You can enable an existing Java API for XML-based RPC (JAX-RPC) 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.
Handlers and service endpoints can manipulate implicit or explicit SOAP headers using the SOAP with Attachments API for Java (SAAJ) data model.
You cannot manipulate protected SOAP headers. A SOAP header that is declared protected by its owning component, for example, Web Services Security, is not accessible to client applications. An exception occurs if you try to manipulate protected SOAP headers.
The client application sets properties on the Stub or Call object to send and receive implicit SOAP headers.
You have a JAX-RPC web services client that is configured to send implicit SOAP headers.
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 //Note: "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.
In this information ...Related concepts
| IBM Redbooks, demos, education, and more(Index) |