-
1. Re: Sharing session attributes in NonBlocking Handlers and Traditional Servlets
lsgroup Mar 8, 2014 3:14 PM (in response to lsgroup)Do sessions not work for non-blocking servlets? I've tried several ways to obtain an existing session, but they all return a null object. When I call
createSession() is creates a non-null session object that holds the same sessionid as when findSessionId(exchange) is called. However, I can't seem to retrieving a session using that id.
SessionCookieConfig sessconf = new SessionCookieConfig();
String foundsessid = sessconf.findSessionId(exchange);
//foundsessid has value...
SessionCookieSource sesscookiesource = sessconf.sessionCookieSource(exchange);
InMemorySessionManager sessman = new InMemorySessionManager(foundsessid);
session = sessman.getSession(exchange, sessconf);
//session returns null...
SessionAttachmentHandler sessattach = new SessionAttachmentHandler(sessman, sessconf);
SessionManager regsessman = sessattach.getSessionManager();
session = regsessman.getSession(exchange, sessconf);
//session returns null...
session = regsessman.getSession(foundsessid);
//session returns null...
Has anyone out there gotten session to work for non-blocking handlers in Wildfly 8?
-
2. Re: Re: Sharing session attributes in NonBlocking Handlers and Traditional Servlets
pferraro Mar 10, 2014 10:57 AM (in response to lsgroup)I'm not sure I understand what you're trying to do...
Why are you creating your own SessionManager instance?
Instead your servlet should use the standard HttpServletRequest.getSession(...) method to obtain a reference to the session.
In your non-blocking handler, you can access the servlet request from the exchange.
e.g.
public void handleRequest(HttpServerExchange exchange) { ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY); HttpServletRequest request (HttpServletRequest) context.getServletRequest(); HttpSession session = request.getSession(); }