Search in sources :

Example 1 with SessionManager

use of com.networknt.session.SessionManager in project light-session-4j by networknt.

the class JdbcSessionMultipleTest method getTestHandler.

static RoutingHandler getTestHandler() {
    return Handlers.routing().add(Methods.GET, "/get", exchange -> {
        SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
        Session session = sessionManager.getSession(exchange);
        if (session == null) {
            session = sessionManager.createSession(exchange);
            session.setAttribute(COUNT, 0);
            logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
        }
        Integer count = (Integer) session.getAttribute(COUNT);
        logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
        exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
        session.setAttribute(COUNT, ++count);
    });
}
Also used : SessionManager(com.networknt.session.SessionManager) Session(com.networknt.session.Session) HttpString(io.undertow.util.HttpString)

Example 2 with SessionManager

use of com.networknt.session.SessionManager in project light-session-4j by networknt.

the class RedisSessionSingleIT method getTestHandler.

static RoutingHandler getTestHandler() {
    return Handlers.routing().add(Methods.GET, "/get", exchange -> {
        SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
        Session session = sessionManager.getSession(exchange);
        if (session == null) {
            session = sessionManager.createSession(exchange);
            session.setAttribute(COUNT, 0);
            logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
        }
        Integer count = (Integer) session.getAttribute(COUNT);
        logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
        exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
        session.setAttribute(COUNT, ++count);
    });
}
Also used : SessionManager(com.networknt.session.SessionManager) Session(com.networknt.session.Session) HttpString(io.undertow.util.HttpString)

Example 3 with SessionManager

use of com.networknt.session.SessionManager in project light-session-4j by networknt.

the class HazelCastSessionSingleTest method getTestHandler.

static RoutingHandler getTestHandler() {
    return Handlers.routing().add(Methods.GET, "/get", exchange -> {
        SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
        Session session = sessionManager.getSession(exchange);
        if (session == null) {
            session = sessionManager.createSession(exchange);
            session.setAttribute(COUNT, 0);
            logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
        }
        Integer count = (Integer) session.getAttribute(COUNT);
        logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
        exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
        session.setAttribute(COUNT, ++count);
    });
}
Also used : SessionManager(com.networknt.session.SessionManager) Session(com.networknt.session.Session) HttpString(io.undertow.util.HttpString)

Example 4 with SessionManager

use of com.networknt.session.SessionManager in project light-session-4j by networknt.

the class HazelcastSessionMultipleTest method getTestHandler.

static RoutingHandler getTestHandler() {
    return Handlers.routing().add(Methods.GET, "/get", exchange -> {
        SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
        Session session = sessionManager.getSession(exchange);
        if (session == null) {
            session = sessionManager.createSession(exchange);
            session.setAttribute(COUNT, 0);
            logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
        }
        Integer count = (Integer) session.getAttribute(COUNT);
        logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
        exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
        session.setAttribute(COUNT, ++count);
    });
}
Also used : SessionManager(com.networknt.session.SessionManager) Session(com.networknt.session.Session) HttpString(io.undertow.util.HttpString)

Example 5 with SessionManager

use of com.networknt.session.SessionManager in project light-session-4j by networknt.

the class JdbcSessionSingleTest method getTestHandler.

static RoutingHandler getTestHandler() {
    return Handlers.routing().add(Methods.GET, "/get", exchange -> {
        SessionManager sessionManager = SingletonServiceFactory.getBean(SessionManager.class);
        Session session = sessionManager.getSession(exchange);
        if (session == null) {
            session = sessionManager.createSession(exchange);
            session.setAttribute(COUNT, 0);
            logger.debug("first time access create a session and count is 0 sessionId = " + session.getId());
        }
        Integer count = (Integer) session.getAttribute(COUNT);
        logger.debug("not the first time, get count from session = " + count + " sessionId = " + session.getId());
        exchange.getResponseHeaders().add(new HttpString(COUNT), count.toString());
        session.setAttribute(COUNT, ++count);
    });
}
Also used : SessionManager(com.networknt.session.SessionManager) Session(com.networknt.session.Session) HttpString(io.undertow.util.HttpString)

Aggregations

Session (com.networknt.session.Session)6 SessionManager (com.networknt.session.SessionManager)6 HttpString (io.undertow.util.HttpString)6