Java Reference
In-Depth Information
Getting
and
Sharing
Data
About
Users
and
the
Request
Problem
You want to get data regarding your service invocations, such as the user invoking the service,
information about HTTP statuses, and web service-specific information such as attachments
and the WSDL. You want something similar to ServletContext , but for a web service. Or,
you want a way to share processing-related state between handlers within a handler chain.
Solution
Refer to the javax.xml.ws.WebServiceContext inside your web service implementation.
Use it to get the MessageContext , the user principal, or to find out if the user is in a given
role.
Discussion
The WebServiceContext interface is implemented behind the scenes by the SOAP container.
It has three methods:
MessageContext getMessageContext
Principal getUserPrincipal
boolean isUserInRole(String role)
An endpoint implementation class will get a WebServiceContext instance injected when a
field of that type is declared as a Resource , as shown here:
@WebService
public class Hello {
@Resource
private WebServiceContext wsContext;
public void doWork(){
MessageContext mContext = wsContext.getMessageContext();
...}
}
As with any injected resource in Java EE 5, the context will be populated by the container at
runtime. Once you have a message context object from the web service context, you can share
Search WWH ::




Custom Search