You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Benson Margulies <bi...@gmail.com> on 2012/07/19 16:14:33 UTC
Sessions and JAX-RS
At the risk of incurring the wrath of Roy T. Fielding, I want to do
something with sessions and JAX-RS. I see the @Context annotation, but
I don't understand what I need to do to cause a session to come into
existence in the first place.
Re: Sessions and JAX-RS
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Benson
On 19/07/12 15:14, Benson Margulies wrote:
> At the risk of incurring the wrath of Roy T. Fielding, I want to do
> something with sessions and JAX-RS. I see the @Context annotation, but
> I don't understand what I need to do to cause a session to come into
> existence in the first place.
We have a couple of examples in the code base.
One is to let the servlet container manage it on your behalf, simply do
@Context
HttpServletRequest request;
(or get it from MessageContext)
HttpSession session = request.getSession();
and work with HttpSession. This can be the simplest option, however
there's little control over the way cookie can be actually represented -
this apparently can further customized say at the Tomcat/Jetty config
level but it can become quite involved - especially if you'd like start
sharing the state between the multiple containers...
So the simpler option may be to set cookies explicitly, example,
return Response.ok().header("Set-Entity", theCookie).build();
(or use NewCookie utility - it does not support Expires property though)
and then get the returning cookie in a request filter, using
HttpHeaders, etc - this is what we do in the saml2 sso sp code
Cheers, Sergey