[undertow-dev] Sharing session attributes in NonBlocking Handlers and Traditional Servlets
Lightspoke Discussion
lsgroup at gmail.com
Sat Mar 8 16:52:40 EST 2014
Hi Start,
Thanks for the response. That makes a lot of sense. I'm having trouble
obtaining a non-null ServletRequestContext. I couldn't find another way to
obtain a ServletRequestContext. I've included the code I'm using below...
public class HelloWorldHandler implements HttpHandler {
@Override
public void handleRequest(final HttpServerExchange exchange) throws
Exception {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE,
"text/plain");
exchange.getResponseSender().send("Hello!");
ServletRequestContext reqctx =
exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
System.out.println("reqctx="+reqctx);
// ... reqctx is null ...
Thanks again!
On Mon, Feb 17, 2014 at 7:27 PM, Stuart Douglas <sdouglas at redhat.com> wrote:
> Basically you need to use
> io.undertow.servlet.spec.ServletContextImpl#getSession().
>
> If your handler is running after the initial servlet handler you can get
> this from the io.undertow.servlet.handlers.ServletRequestContext, which is
> attached to the exchange.
>
> If you are running before the initial handler you need to store a
> reference to the servlet context or the Deployment somewhere.
>
> Servlet does not use SessionAttachmentHandler, because each servlet
> context can have its own session with its own settings, and multiple
> contexts can be involved in the same request if forward/include is used. As
> a result each servlet context has its own session manager, and manages it
> internally.
>
> Stuart
>
> ----- Original Message -----
> > From: "Lightspoke Discussion" <lsgroup at gmail.com>
> > To: undertow-dev at lists.jboss.org
> > Sent: Tuesday, 18 February, 2014 1:08:58 AM
> > Subject: [undertow-dev] Sharing session attributes in NonBlocking
> Handlers and Traditional Servlets
> >
> > Hello,
> >
> > Does anyone know how you might go about sharing session attributes
> between a
> > servlet and a non-blocking handler in the same project?
> >
> > InMemorySessionManager sessman = new InMemorySessionManager(foundsessid);
> > SessionAttachmentHandler sessattach = new
> SessionAttachmentHandler(sessman,
> > sessconf);
> > SessionManager regsessman = sessattach.getSessionManager();
> > Session session;
> > session = sessman.getSession(exchange, sessconf);
> > //returns null
> >
> >
> >
> > SessionCookieConfig sessconf = new SessionCookieConfig();
> > String foundsessid = sessconf.findSessionId(exchange);
> > session = regsessman.getSession(foundsessid);
> > System.out.println("getsession by id ="+session );
> > //returns null
> >
> >
> > session = regsessman.createSession(exchange, sessconf);
> > System.out.println("create session ="+session );
> >
> > //returns a session - but ...
> >
> > 1. session attributes from servlet do not return its value and
> > 2. session attributes across http requests do not persist in memory
> >
> > Thanks in advance!
> >
> >
> >
> > --
> > --
> > Mike
> >
> > _______________________________________________
> > undertow-dev mailing list
> > undertow-dev at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/undertow-dev
>
--
--
Matthew Ma
http://www.lightspoke.com
Lightspoke Web Based Database
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20140308/7913db66/attachment.html
More information about the undertow-dev
mailing list