Retrieving transport headers with JAX-WS
You can enable a Java™ API for XML-Based Web Services (JAX-WS) web services client to retrieve values from transport headers. For a request that uses HTTP, the transport headers are retrieved from HTTP headers found in the HTTP response message. For a request that uses Java Message Service (JMS), the transport headers are retrieved from the JMS message properties found on the JMS response message.
Before you begin
Retrieving transport headers is supported only by Web services clients, and is supported for the HTTP and JMS transports. The web services client must call the JAX-WS APIs directly and not through any intermediary layers, such as a gateway function.
About this task
When using the JAX-WS programming model, the client must set a property on the BindingProvider's RequestContext object to retrieve values from the transport headers. After you set the property, values are read from responses for the subsequent method invocations against that BindingProvider object until the associated property is set to null or the BindingProvider object is discarded.
To retrieve values from the transport headers on inbound responses, modify the client code as follows:
Procedure
Results
You have a JAX-WS web service that can receive transport headers from incoming response messages.
Example
public class MyApplicationClass {
// Inject an instance of the service's port-type.
@WebServiceRef(EchoService.class)
private EchoPortType port;
// This method will invoke the web service operation and retrieve transport headers on the request.
public void invokeService() {
// Set up the Map to retrieive our response headers.
Map<String, Object> responseHeaders = new HashMap<String, Object>;
responseHeaders.put(“MyHeader1”, null);
responseHeaders.put(“MyHeader2”, null);
responseHeaders.put(“MyHeader3”, null);
// Set the Map as a property on the RequestContext.
BindingProvider bp = (BindingProvider) port;
bp.getRequestContext().put(com.ibm.websphere.webservices.Constants.RESPONSE_TRANSPORT_PROPERTIES, responseHeaders);
// Invoke the web services operation.
String result = port.echoString(“Hello, world!”);
// Now retrieve our response headers.
Object header1 = responseHeaders.get(“MyHeader1”);
Object header2 = responseHeaders.get(“MyHeader2”);
Object header3 = responseHeaders.get(“MyHeader3”);
}
}