[undertow-dev] Sharing session attributes in NonBlocking Handlers and Traditional Servlets
Stuart Douglas
sdouglas at redhat.com
Mon Mar 10 16:37:15 EDT 2014
Yes, if you are running handlers outside the servlet chain the servlet
request context does not get setup.
Because you are actually after the ServletContextImpl (which allows you
to get the session) you need to get a reference to this at deployment time.
How are you setting up your non-blocking handler? Via ServletExtension?
If so then the ServletContext is just passed into the extension, so you
can just pass it directly to the handler (You will need to cast it to
ServletContextImpl though in order to use it to get the session).
Stuart
Lightspoke Discussion wrote:
> Hi Stuart,
>
> I have a regular servlet (the sample... public class HelloWorldServlet
> extends HttpServlet) running inside the same web context (in the same
> war). In the HelloWorldServlet I can access the session object. I ran
> that first, but when I run the non-blocking servlet, my reqctx still
> returns null.
>
> I'm running Wildfly 8.0.0 final, in case that matters.
>
> So is everything hinging on:
>
>
> public class ServletInitialHandler implements HttpHandler,
> ServletDispatcher {
>
> ...
> publicvoidhandleRequest(finalHttpServerExchangeexchange)throwsIOException,ServletException
> ...
>
> exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY,
> servletRequestContext);
>
> ...
>
>
>
>
>
> On Sun, Mar 9, 2014 at 12:55 PM, Stuart Douglas <sdouglas at redhat.com
> <mailto:sdouglas at redhat.com>> wrote:
>
> This will only be not null after the first servlet handler has run.
> If your handler is executing outside the scope of the servlet
> deployment then you need to store a reference to the ServletContext
> somewhere (worst case = stick it in a static somewhere).
> Stuart
>
>
> Lightspoke Discussion wrote:
>
> If you are running before the initial handler you need to store
> a reference to the servlet context or the Deployment somewhere.
>
>
>
>
> --
> --
> Matthew Ma
> http://www.lightspoke.com
> Lightspoke Web Based Database
More information about the undertow-dev
mailing list