Example: Using JAX-WS properties to manipulate SOAP headers in a JAX-WS handler
WebSphere® Application Server provides extensions to the Java™ API for XML-Based Web Services (JAX-WS) and Web Services for Java Platform, Enterprise Edition (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.
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.