[jboss-user] [JBoss Web Services CXF] - How to share session between web service calls?

Anand Jayaraman do-not-reply at jboss.com
Thu Aug 12 23:32:07 EDT 2010


Anand Jayaraman [http://community.jboss.org/people/anand201301] replied to the discussion

"How to share session between web service calls?"

To view the discussion, visit: http://community.jboss.org/message/557200#557200

--------------------------------------------------------------
Hi,

I needed one clarification, will this work if there are two separate instances of BindingProvider being used from client code. For e.g.

Greeter greeter = service.getGreeterPort();

BindingProvider bp = (BindingProvider)greeter;
                   bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);


Map<String, List<String>> headers= CastUtils.cast((Map)bp.getRequestContext().get("javax.xml.ws.http.request.headers"));

if (headers == null) {
    headers = new HashMap<String, List<String>>();
    bp.getRequestContext().put("javax.xml.ws.http.request.headers", headers);
}

List<String> cookies = Arrays.asList(new String[] {"a=a", "b=b"});
headers.put("Cookie", cookies);

String greeting = greeter.greetMe("Bonjour");

*//After this invocation i am creating a brand new instance of binding provider .*

Greeter *greeter1* = *service1*.getGreeterPort();

BindingProvider *bp1* = (BindingProvider)*greeter1*;
                   bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);


Map<String, List<String>> headers= CastUtils.cast((Map)*bp1*.getRequestContext().get("javax.xml.ws.http.request.headers"));

if (headers == null) {
    headers = new HashMap<String, List<String>>();
    bp.getRequestContext().put("javax.xml.ws.http.request.headers", headers);
}

List<String> cookies = Arrays.asList(new String[] {"a=a", "b=b"});
headers.put("Cookie", cookies);

String greeting = *greeter1*.greetMe("Bonjour");

-------------------------------------------------------------------------------------------------
The headers set in the first BindingProvider may not be same as the headers in the second binding provider because CXF would create a different cookie for the second BindingProvider instance.

So is the solution to keep the header, cookie information in a local data structure in the client side and keep copying it back to all new BindingProvider instances created from client side so that the same cookie information is relayed back to the server?

But this way it would not be too different from the HttpConduit approach i had mentioned earlier.

Are there any changes on the server that also needs to be done?

Regards,
Anand

--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/557200#557200]

Start a new discussion in JBoss Web Services CXF at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2046]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20100812/79911796/attachment.html 


More information about the jboss-user mailing list