Sending implicit SOAP headers with JAX-WS
You can enable an existing Java™ API for XML-Based Web Services (JAX-WS) web services client to send values in implicit SOAP headers. By modifying your client code to send implicit SOAP headers, you can send specific information within an outgoing web service request.
Before you begin
To complete this task, you need a web services client that you can enable to send implicit SOAP headers.
- A message part that is declared as a SOAP header in the binding in the Web Services Description Language (WSDL) file, but the message definition is not referenced by a portType element within a WSDL file.
- An element that is not contained in the WSDL file.
Handlers and service endpoints can manipulate implicit or explicit SOAP headers using the SOAP with Attachments API for Java (SAAJ) data model.
Using JAX-WS, there is no restriction on types of headers that you can manipulate.
About this task
The client application sets properties on the Dispatch or Proxy object to send and receive implicit SOAP headers.
Procedure
Results
You have a JAX-WS web services client that is configured to send implicit SOAP headers.
Example
1 //Create the hashmaps for the outbound soap headers
2 Map<QName, List<String>> outboundHeaders=new HashMap<QName, List<String>>();
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 request context
12 dispatch.getRequestContext().put("jaxws.binding.soap.headers.outbound");
13 // Invoke the remote operation
14 dispatch.invoke(parm1);
15 // Get the inbound header map from the response context
16 Map<QName,List<String>> inboundMap = dispatch.getResponseContext().get("jaxws.binding.soap.headers.outbound");
17 List<String> serverUuidList = inboundMap.get(new QName("com.rotbank.security","ServerUuid"));
18 String text = serverUiidList.get(0);
19 //Note: text now equals a XML object that contains a SOAP header:
21//"<y:ServerUuid xmlns:y=\"com.rotbank.security\"><:uuid>ROTB-0A03519322FSA01
22 </y:uuid></y:ServerUuid.");
On line 2, create the outbound SOAP header map.
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 request context, which causes the AtmUuid1 and AtmUuid2 headers to be added to the request message when the operation is invoked.
On line 14, invoke the remote operation.
On line 15, obtain the outbound header map.
On lines 17-18, the ServerUuid header is retrieved from the response Map. The Map accesses the SOAP header from the response message.