You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Mignon, Laurent" <La...@softwareag.com> on 2011/04/08 11:33:55 UTC

JAXRS and HTTPSession

Hi,

I've some troubles to deal with the HttpSession in my REST services.
My services are deployed into tomcat and I use the WebClient to call
these.

The problem is that each time the client call the server, I recieve a
new HttpSession (the id is different between each call) ant thus, data
put into the session by the previous request are not found by the new
request...
How can I use with HttpSession to manage datas related to the session
between calls.

Thanks

lmg

Re: JAXRS and HTTPSession

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

On Fri, Apr 8, 2011 at 10:33 AM, Mignon, Laurent <
Laurent.Mignon@softwareag.com> wrote:

> Hi,
>
> I've some troubles to deal with the HttpSession in my REST services.
> My services are deployed into tomcat and I use the WebClient to call
> these.
>
> The problem is that each time the client call the server, I recieve a
> new HttpSession (the id is different between each call) ant thus, data
> put into the session by the previous request are not found by the new
> request...
>

You need to set an org.apache.cxf.message.Message.MAINTAIN_SESSION.
You can do it by using JAXRSClientFactoryBean:

JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean()l
bean.setAddress(address);
bean.setProperties(Collections.singletonMap(Message.MAINTAIN_SESSION,
Boolean.TRUE));
vean.createWebClient();

or

WebClient wc = webClient.create(address);
WebClient.getConfig(wc).getRequestContext().put(Message.MAINTAIN_SESSION,
Boolean.TRUE));

This property can also be injected from Spring.

Alternatively, copy Cookies explicitly, by getting Cookies from the current
Response and setting them as headers on the current client

Hope that helps, Sergey

How can I use with HttpSession to manage datas related to the session
> between calls.
>
> Thanks
>
> lmg
>