Archive

Archive for July, 2010

Lotus/Domino 8.5 WebService Provider manipulating SOAP Header

July 28, 2010 1 comment

Similar to previous post Domino WebService Consumer manipulating SOAP Header WebService Provider in some cases have to read SOAP Header passed. It may process the header (e.g log it’s data) and send enhanced Header back along with response. To achieve that we have to add some code to inspect and inject SOAP Header to the payload. Steps are shown below.
Locate generated Web Service Stub with the methods prepared for implementation and access MessageContext to read and set Header:

public void echo()
{
MessageContext mc = MessageContext.getCurrentContext();
// get received SOAP Header
SOAPHeaderElement header = mc.getRequestMessage().getSOAPEnvelope().getHeaderByName(wsNamespace, "auth");

// manipulate header

// set new manipulated header to response
mc.getResponseMessage().getSOAPEnvelope().addHeader(header);
}

Advertisements

Lotus/Domino 8.5 WebService Consumer manipulating SOAP Header

July 28, 2010 Leave a comment

There is pretty often a need to incorporate SOAP Header in the message sent by Web Service consumer. While Domino 8.5 is using Axis Java library under the hood of it’s generated Java Web Service Consumers,it blocks standard setHeader API in the client proxy. We had to look through all generated java files to find the solution. Below is example of sending SOAP Header from Lotus Web Consumer agent.

In the generated by Domino class for endpoint – XXXEndpointStub.java locate the code responsible for making the call, similar to the following:

lotus.domino.websvc.client.Call _call = createCall("submitRequest");
java.lang.Object _resp = _call.invoke(new java.lang.Object[] {parameters});

Modify it to create and addHeader before call invocation.For example to create following SoapHeader:

<soap:Envelope …>

<soap:Header>
<au:auth xmlns:au=”http://www.example.com“>
  <au:username>john</au:username>
</au.auth>
</soap:Header>

<soap:Body>
….
</soap:Body>
</soap:Envelope>

Code will be:

lotus.domino.websvc.client.Call _call = createCall("submitRequest");

try {
// Create soap header elements
SOAPHeaderElement header = new SOAPHeaderElement(“http://www.example.com&#8221;, “auth”);
SOAPElement elemSystem = header.addChildElement(“username”, “au”, “http://www.example.com&#8221;);
elemSystem.addTextNode(“john”);

// add header to payload
_call.addHeader(header);
} catch (Exception e) {
throw new ….
}

java.lang.Object _resp = _call.invoke(new java.lang.Object[] {parameters});