+

Search Tips   |   Advanced Search

Example: Using JAX-WS properties to send and receive SOAP headers


WAS provides extensions to the JAX-WS and Web Services for Java EE client models, including the com.ibm.wsspi.websvcs.Constants.JAXWS_OUTBOUND_SOAP_HEADERS and com.ibm.wsspi.websvcs.Constants.JAXWS_INBOUND_SOAP_HEADERS properties. This example demonstrates how these two properties are used.

The following programming example illustrates how to send two request SOAP headers and receive one response SOAP header within a JAX-WS Web services request and response:

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(Constants.JAXWS_OUTBOUND_HEADERS, outboundHeaders);
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(Constants.JAXWS_OUTBOUND_HEADERS);
17 List<String> serverUuidList = inboundMap.get(new QName("com.rotbank.security","ServerUuid"));
18 String text = serverUiidList.get(0);
19 
//

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.



Related concepts


SOAP with Attachments API for Java interface

 

Related tasks


Sending implicit SOAP headers with JAX-WS
Receiving implicit SOAP headers with JAX-WS
Implementing extensions to JAX-WS Web services clients

 

Related


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