Obtaining HTTP session from a webservice
We have a web application built on a Tomcat 6/WebWork/Hibernate/SQL Server stack.
One part of the web application is a network map built using the Flare toolkit (the predecessor to Flare was Prefuse). The network map data is retrieved via a webservice call, say getData(). This call is made 开发者_运维问答by the Flare application to retrieve XML data it needs to display. The webservice itself has been developed using Apache CXF.
I am trying to figure out how I can obtain the HTTP session within the method designated as a webservice. I need this because I need to maintain server side data across client (Flare application) webservice requests.
Do I need to get the HTTP session using the basic servlet APIs (knowing that the CXF servlet is being used)? Or is there API support at the CXF level?
The webservice itself runs within Tomcat 6.
This is actually part of the JAX-WS spec. You can do
@Resource
WebServiceContext ctx;
....
ctx.getMessageContext().get(MessageContext.SERVLET_REQUEST)
to get the ServletRequest object from which you can do anything with the session or whatever.
Note: by default, JAX-WS clients don't maintain the session cookie. You have to set them to maintain the session:
((BindingProvider)proxy).getRequestContext()
.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, "true");
精彩评论