WAS v8.5 > Reference > Developer examples

Example: Using JAX-WS properties to manipulate SOAP headers in a JAX-WS handler

WebSphere Application Server provides extensions to the JAX-WS and Web Services for Java EE client programming models, including the jaxws.binding.soap.headers.outbound and jaxws.binding.soap.headers.inbound properties. This example shows how to use these two properties to manipulate SOAP headers in a JAX-WS handler.

These API extensions, and the standard APIs cannot be used to manipulate SOAP headers in the same JAX-WS handler. You must decide whether to use these extensions or the standard APIs when setting up the SOAP header manipulation processing for a JAX-WS handler.

The following programming example illustrates how to set two request SOAP headers and retrieve one response SOAP header within a JAX-WS handler context:

1  //Create the hashmaps for the outbound soap headers
2  Map<QName, List<String>> outboundHeaders=messageContext.get("jaxws.binding.soap.headers.outbound"); 
3
4  //Add "AtmUuid1" and "AtmUuid2" to the outbound map 5  List<String> list1 = new ArrayList<String>();
6  list1.add("<AtmUuid1 xmlns=\"com.rotbank.security\"><uuid>ROTB-0A01254385FCA09</uuid></AtmUuid1>");
7  List<String> list2 = new ArrayList<String>();
8  list2.add("<AtmUuid2 xmlns=\"com.rotbank.security\"><uuid>ROTB-0A01254385FCA09</uuid></AtmUuid2>"
9  outboundHeaders.put(new QName("com.rotbank.security", "AtmUuid1"), list1);
10 outboundHeaders.put(new QName("com.rotbank.security", "AtmUuid2"), list2);
11 // Set the outbound map on the MessageContext object, which is passed into the JAX-WS handler method 12 messageContext.put("jaxws.binding.soap.headers.outbound", outboundHeaders);

On line 2, retrieve the outbound SOAP header map from the MessageContext parameter, which is passed into the JAX-WS handler method.

On lines 5-10, the AtmUuid1 and AtmUuid2 headers elements are added to the outbound map.

On line 12, the outbound map is set on the JAX-WS handler context, which causes the AtmUuid1 and AtmUuid2 headers to be added to the request message. This code is not necessary because the outboundHeaders map is a live map.

JAX-WS handler methods might also retrieve specific headers from the map and remove headers or entire lists of headers, if desired.

Use only these APIs or only the standard APIs to process a message. Do not mix the two.


Related concepts:

SOAP with Attachments API for Java interface


Related


Sending implicit SOAP headers with JAX-WS
Receive implicit SOAP headers with JAX-WS
Implement extensions to JAX-WS web services clients


Reference:

Additional Application Programming Interfaces (APIs)
Web services specifications and APIs


+

Search Tips   |   Advanced Search