users@jersey.java.net

[Jersey] Re: HttpContext persistence - any ideas?

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Mon, 13 Dec 2010 16:34:50 +0100

Hi Alex,

HttpContext is never persisted. A new instance is created for each and
every request.

If you want to do this the RESTful way:

1) Use application state: the first response will return enough state
such that the client can make a second request with enough state such
the server knows what to do; and/or

2) Use resource state: persist the information as a resource, whether
that be in-memory or to a DB. You can use a @Singleton for basic in-
memory persistence. The see other would return the URI to that
resource in the location header.

Otherwise, you can use servlet session state.

Paul.


On Dec 13, 2010, at 4:15 PM, Alex Treppass wrote:

> All,
>
> What are the rules which govern when the HttpContext will be
> persisted or recreated between requests from the same client?
>
> I am attempting to put an object in the httpContext.getProperties()
> map and return a See Other Response, and then (when the browser then
> requests the 'see other' page) for my Message Body Writer to get
> this object back out and do something with it.
>
> Putting the object in is successful, but when the 2nd call comes in
> the httpContext object appears to have changed and the properties
> map is empty.
>
> Regards,