English 中文(简体)
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");
问题回答

暂无回答




相关问题
IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

ASP.net web services

I am using a web service which sets the Thread.CurrentPrincipal object while logging in and soon later when another webmethod of the same web service accesses Thread.CurrentPrincipal, its different/...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

热门标签