<div dir="ltr">Hi Start, <div>Thanks for the response.  That makes a lot of sense.  I&#39;m having trouble obtaining a non-null ServletRequestContext.  I couldn&#39;t find another way to obtain a ServletRequestContext.  I&#39;ve included the code I&#39;m using below...</div>
<div><br></div><div><div>public class HelloWorldHandler implements HttpHandler {</div><div>    @Override</div><div>    public void handleRequest(final HttpServerExchange exchange) throws Exception {</div><div>        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, &quot;text/plain&quot;);</div>
<div>        exchange.getResponseSender().send(&quot;Hello!&quot;);</div><div><br></div><div>        ServletRequestContext reqctx = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);</div><div>        System.out.println(&quot;reqctx=&quot;+reqctx);</div>
</div><div>        // ... reqctx is null ...</div><div><br></div><div>Thanks again!</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 17, 2014 at 7:27 PM, Stuart Douglas <span dir="ltr">&lt;<a href="mailto:sdouglas@redhat.com" target="_blank">sdouglas@redhat.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Basically you need to use io.undertow.servlet.spec.ServletContextImpl#getSession().<br>
<br>
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.<br>
<br>
If you are running before the initial handler you need to store a reference to the servlet context or the Deployment somewhere.<br>
<br>
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.<br>

<br>
Stuart<br>
<div><div class="h5"><br>
----- Original Message -----<br>
&gt; From: &quot;Lightspoke Discussion&quot; &lt;<a href="mailto:lsgroup@gmail.com">lsgroup@gmail.com</a>&gt;<br>
&gt; To: <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
&gt; Sent: Tuesday, 18 February, 2014 1:08:58 AM<br>
&gt; Subject: [undertow-dev] Sharing session attributes in NonBlocking Handlers    and Traditional Servlets<br>
&gt;<br>
&gt; Hello,<br>
&gt;<br>
&gt; Does anyone know how you might go about sharing session attributes between a<br>
&gt; servlet and a non-blocking handler in the same project?<br>
&gt;<br>
&gt; InMemorySessionManager sessman = new InMemorySessionManager(foundsessid);<br>
&gt; SessionAttachmentHandler sessattach = new SessionAttachmentHandler(sessman,<br>
&gt; sessconf);<br>
&gt; SessionManager regsessman = sessattach.getSessionManager();<br>
&gt; Session session;<br>
&gt; session = sessman.getSession(exchange, sessconf);<br>
&gt; //returns null<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; SessionCookieConfig sessconf = new SessionCookieConfig();<br>
&gt; String foundsessid = sessconf.findSessionId(exchange);<br>
&gt; session = regsessman.getSession(foundsessid);<br>
&gt; System.out.println(&quot;getsession by id =&quot;+session );<br>
&gt; //returns null<br>
&gt;<br>
&gt;<br>
&gt; session = regsessman.createSession(exchange, sessconf);<br>
&gt; System.out.println(&quot;create session =&quot;+session );<br>
&gt;<br>
&gt; //returns a session - but ...<br>
&gt;<br>
&gt; 1. session attributes from servlet do not return its value and<br>
&gt; 2. session attributes across http requests do not persist in memory<br>
&gt;<br>
&gt; Thanks in advance!<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; --<br>
&gt; Mike<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; undertow-dev mailing list<br>
&gt; <a href="mailto:undertow-dev@lists.jboss.org">undertow-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/undertow-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/undertow-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>--<br>Matthew Ma<br><a href="http://www.lightspoke.com">http://www.lightspoke.com</a><br>Lightspoke Web Based Database
</div>