Java Reference
In-Depth Information
Accessing Incoming Header Parameters in a Service
Problem
You want to access all parameters set in the header of an incoming request.
Solution
You can use JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY in the message context if
you are using the reference implementation. You can also do it with SAAJ.
Discussion
The following code works only with the reference implementation. It pulls WS-Addressing
headers:
@WebService
public class MyService {
private static final QName MY_HEADER =
new QName("http://ns.soacookbook.com","headerName");
@Resource
WebServiceContext context;
@WebMethod
public void sayHello(String name) {
//RI only
HeaderList headers = context.getMessageContext().get(
JAXWSProperties.INBOUND_HEADER_LIST_PROPERTY);
Header header = headers.get(MY_HEADER);
//do something with header
}
}
Here you're in a web service, which is a managed code situation. This means that you can just
declare the WebServiceContext as a Resource , and let the container inject it for you. From
this context, you can get the message context and use the specified property to get the name
of the header you're interested in, using its QName .
Accessing All SOAP Header Elements shows how to use the SAAJ API to read the values of
SOAP headers. But if you're in a JAX-WS provider class, you want to use code for that API.
Search WWH ::




Custom Search