+

Search Tips   |   Advanced Search

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


WAS provides extensions to the JAX-RPC and Web Services for Java EE client models, including the REQUEST_SOAP_HEADERS and RESPONSE_SOAP_HEADERS Stub properties. This is an example of 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 Web services request and response:

1 
//Create the request and response hashmaps.
2 HashMap requestHeaders=new HashMap();
3 HashMap responseHeaders=new HashMap();
4
5 
//Add "AtmUuid1" and "AtmUuid2" to the request hashmap.
6 requestHeaders.put(new QName("com.rotbank.security", "AtmUuid1"), 
7   "<AtmUuid1 xmlns=\"><uuid>ROTB-0A01254385FCA09</uuid></AtmUuid1>");
8 requestHeaders.put(new QName("com.rotbank.security", "AtmUuid2"), 
9  ((IBMSOAPFactory)SOAPFactory.newInstance()).createElementFromXMLString(
10   "x:AtmUuid2 
    xmlns:x=\"com.rotbank.security\"><x:uuid>ROTB-0A01254385FCA09
     </x:uuid><x:AtmUuid2>"));
11
12 
//Add "ServerUuid" to the response hashmap.
13 
//If "responseHeaders" is empty, all the SOAP headers are
14 
//extracted from the response message.
15 responseHeaders.put(new QName("com.rotbank.security","ServerUuid"), null);
16
17 
//Set the properties on the Stub object.
18 stub.setProperty(Constants.REQUEST_SOAP_HEADERS.requestHeaders);
19 stub.setProperty(Constants.RESPONSE_SOAP_HEADERS.responseHeaders);
20 
21 
//Call the operationon the Stub.
22 stub.foo(parm2, parm2);
23
24 
//Retrieve "ServerUuid" from the response hashmap.
25 SOAPElement serverUuid =
26   (SOAPElement) responseHeaders.get(new QName("com.rotbank.security","ServerUuid"));
27
28 
//
 "serverUuid" now equals a SOAPElement object that represents the 
29 
//following code:
30
//"<y:ServerUuid 
    xmlns:y=\"com.rotbank.security\"><:uuid>ROTB-0A03519322FSA01
   </y:uuid></y:ServerUuid.");

On lines 2-3, new HashMaps are created that are used for the request and response SOAP headers.

On lines 6-10, the AtmUuid1 and AtmUuid2 headers elements are added to the request HashMap.

On line 15, the ServerUuid header element name, along with a null value, is added to the response HashMap.

On line 18, the request HashMap is set as a property on the Stub object. This causes the AtmUuid1 and AtmUuid2 headers to be added to each request message that is associated with an operation that is invoked on the Stub object.

On line 19, the response HashMap is set as a property on the Stub object. This causes the ServerUuid header to be extracted from each response message that is associated with an operation that is invoked on the Stub object.

On line 22, the Web service operation is invoked on the Stub object.

On lines 25-26, the ServerUuid header is retrieved from the response HashMap. The header was extracted from the response message and inserted into the HashMap by the Web services engine.



Related concepts


SOAP with Attachments API for Java interface

 

Related tasks


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

 

Related


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