tags:

views:

460

answers:

1

Hi,

We are working on one project where in we are using JaxWSProxyFactoryBean provided by CXF framework to invoke webservices. I am using SPRING configuration to create clients rather than using API directly in code. I am also setting maintain_session property to make sure session is maintained by WS clients.

<jaxws:client id="userAuthenticationServiceClient1" address="${application.deployment.url}/UserAuthentication" serviceClass="com.authentication.webservice.IUserAuthenticationService" abstract="true" > <jaxws:properties > <entry key="javax.xml.ws.session.maintain"> <value type="java.lang.Boolean">true</value> </entry> </jaxws:properties> </jaxws:client>

But I found that the session is not maintained across various webservices instances. To make it more clear If there are proxy clients like wc1, wc2, wc3. All the operations invoked on wc1 will have its session, while wc2 will create new session. Can someone let me know what settings I need to do so that all the ws clients will share session?

+1  A: 

There really isn't an "automatic" way to do it. Each service proxy is designed to be completely separate from the others. However, you can "manually" copy the session cookies from one proxy to the other via:

HTTPConduit conduit1 = (HTTPConduit)ClientProxy.getClient(p1).getConduit(); HTTPConduit conduit2 = (HTTPConduit)ClientProxy.getClient(p2).getConduit(); conduit2.getCookies().putAll(conduit1.getCookies());

That should copy all the cookies from one to the other.

Daniel Kulp
hey daniel, thanks for replying to my post. But its not possible to use above APIs, as I already mentioned that I am using SPRING managed beans. None of the classes created by me are aware of whether they are invoking any webservice, since the instances created by jaxws:client are injected. I wanted to have a generic way to do it without making my classes aware of where they live :)
CuriousMind
Ah. In that case, the only thing I can think of is to write a couple interceptors to do this. An "In" interceptor that would record all the session cookies and an "Out" to add/update the session cookies. Configure those on all the <jaxws:client> things.
Daniel Kulp