users@jersey.java.net

Re: [Jersey] In JAX-RS: Jersey: API model, how do you access HTTP session variables

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 21 May 2009 21:23:09 +0200

Hi Mahesh,

There is a reason why you cannot find anything :-) it is because using
HTTP sessions breaks the REST stateless constraint:

   http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3

and we do not encourage this to be broken.

If you want to break this constraint you can do one of the following:

   1) Inject the HttpServletRequest [1] and enable the session from
that; or

   2) Annotate a resource class with PerSession [2] if you want the
state of the resource to be associated with a
       session. Or use a DI framework like Spring or Guice and use the
equivalent mechanism to declare the life-
       cycle

Paul.

[1] https://jersey.dev.java.net/documentation/1.1.0-ea/user-
guide.html#d4e412
[2] https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/spi/container/servlet/PerSession.html

On May 21, 2009, at 8:42 PM, maahi wrote:

> Hi,
>
> I just started developing REST APIs using Jersey JAX-RS APIs using
> Jersey 1.0.3. I have basic question: How do you access Http
> session variables?
>
> Is there a annotation injection for accessing Http session
> variables? I searched through the docs I couldn't find any
> documentation on this topic?
>
> Appreciate your help.
> --
> Regards
> --Mahesh