users@jersey.java.net

Re: [Jersey] Is it possible to maintain sessions the RESTful way?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 11 Aug 2008 10:09:54 +0200

On Aug 11, 2008, at 9:39 AM, Srinivas Naresh Bhimisetty wrote:

> Thank you. That clears my doubt.
> So you mean we can make use of the headers to get the session
> tracking functionality.
>

Lars is referring to making state explicit as resource state
accessible as resources identified by URIs.

The other kind of state is application state, and that is sent by the
client. These could be headers, they can even be cookies as long as
they are not opaque identifiers that reference hidden state on the
server the client cannot access and results in the changing of
resource state based on previous requests and responses.

For GET requests i would recommend not using HTTP headers for
application-state unless you really need to.

Paul.


> Thanks,
> Naresh
>
> Lars Tackmann wrote:
>> On Mon, Aug 11, 2008 at 8:26 AM, Srinivas Naresh Bhimisetty
>> <Srinivas.Bhimisetty_at_sun.com> wrote:
>>
>>> Hi,
>>>
>>> this is a Jersey newbie. I was going through some docs which
>>> said, RESTful
>>> web services are stateless.
>>> If these are stateless, would it be possible for someone to
>>> create a RESTful
>>> web service which has to maintain the session information for the
>>> different
>>> actions, i.e., if I want to write a web service, something like a
>>> Credit
>>> Card Transaction, how would I maintain the state if I want to
>>> write it the
>>> RESTful way. Is it possible? Is the RESTful approach suitable
>>> only for few
>>> kind of services?
>>> I think I'm confused. Could somebody please elaborate this
>>> particular
>>>
>>
>> RESTful services does not maintain state the usual way (i.e. a cookie
>> id used to retrieve a server side session). This does however not
>> prevent you from creating a credit card transactional resource -
>> consider this flow:
>>
>> ----
>> post /creditcard/transaction => get a transaction id in location
>> header (say: 42)
>> put /creditcard/42 => put work (in entity body) on to the transaction
>> :
>> put /creditcard/42/commit => commit transaction
>> ----
>>
>> this way you create a transactional id, add work to it and on commit
>> you simply execute all this work in a server side transaction.
>> Further
>> functionality, like a rollback resource or transaction timeout are
>> equally easy to add.
>>
>> Hope this helps
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>