users@jersey.java.net

Re: [Jersey] Statically obtain the HttpSession (i.e. from HttpServletRequest.getSession())

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 21 Apr 2010 21:07:26 +0200

On Apr 21, 2010, at 8:27 PM, Alex Sherwin wrote:

> Is it possible to statically obtain the HttpSession (i.e. from
> HttpServletRequest.getSession()) ?
>

No, i think you will need to write pre/post servlet request listeners
to set the thread local context. Or adapt the ServletContainer/
SpringServlet and override:

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/spi/container/servlet/ServletContainer.html
#service%28java.net.URI,%20java.net.URI,
%20javax.servlet.http.HttpServletRequest,
%20javax.servlet.http.HttpServletResponse%29

Actually it should also be possible to do this in a Jersey container
request filter, which adds a Closeable to the CloseableService to set
the current context to null. Make that filter is the first in the
chain then other request filters can have access to the HttpSession.

Paul.

> For example, the Cinnamon (Flex AMF provider) Servlet puts the
> current relevant servlet context objects into a statically available
> ThreadLocal during the execution of your implementation classes.
>
> I know its possible to use @Resource to inject what I want into a
> jersey resource, however, what I'm trying to accomplish by unifying
> a few different technologies would be well suited if I could
> statically access the current http session information (if we happen
> to be executing within some context started by jersey).
>
> I'm looking through the jersey SpringServlet and ServletContainer
> now and I'm not seeing anything like that, but I just wanted to make
> sure.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>