SOAP Headers in Lotus Domino web service consumers and providers

In a current project we’re using the web service consumer and web server provider capability of Lotus Domino quite heavily. During the development the need to process the SOAP request headers which are provided in a section above the SOAP body. Problem is that these are not exposed through the proxy classes generated for you when you import the WSDL. Searching Google I came across the blog of Elena Neroslavskaya and more importantly the post that helped me out. Using the MessageContext class described in that blog post helped me crack the nut and now I can both iterate through the SOAP headers sent to me in the request and send SOAP headers back in the response. Sweet!

Below are two code snippets – one for iterating through request headers and one for sending headers back. Home it may help someone out there.

Iterate received headers

private void recurseHeaders(Iterator ite) {
  while (ite.hasNext()) {
    MessageElement elem = (MessageElement)ite.next();
    String nsUri = elem.getNamespaceURI();
    String name = elem.getName();
    String value = elem.getValue();
    System.out.println("SOAP Header - ns , name , value ");
    this.recurseHeaders(elem.getChildElements());
  }
}

public com.example.FooResponseType foo(
  com.example.FooRequestType req) throws Exception {

  MessageContext mc = MessageContext.getCurrentContext();
  SOAPEnvelope envelope = mc.getRequestMessage()
    .getSOAPEnvelope();
  this.recurseHeaders(
    envelope.getHeader().getChildElements());
}

Send back headers

import lotus.domino.axis.message.SOAPHeaderElement;
import lotus.domino.axis.message.MessageElement;

MessageElement elemGuid =
  new MessageElement("http://lekkimworld.com", "Guid");
elemGuid.addTextNode("GuidXYZ");

MessageElement elemUser =
  new MessageElement("http://lekkimworld.com", "User");
elemUser.addTextNode("UserXYZ");

SOAPHeaderElement elemHeader =
  new SOAPHeaderElement("http://lekkimworld.com", "TopElem");
elemHeader.addChild(elemGuid);
elemHeader.addChild(elemUser);

mc.getResponseMessage()
  .getSOAPEnvelope().addHeader(elemHeader);

http://./files/prettyprint/prettify.js

prettyPrint();

Discovering Notes 8: WSDL editing


If you’re running Notes 8 and starting to look into composite applications (CA) you’ll need a tool to edit WSDL files unless you’re the notepad-type. Even I is getting past that point and starting to resort to GUI editors so maybe you should to. Fortunately for us all there is no need to look further than your favorite IDE (which is even more true after Notes 8 has been released).

In Eclipse the WSDL editor is provided by the Web Tools Platform (WTP) Project which can easily be installed on top of the standard free Eclipse IDE. I used Eclipse 3.3 but you might as well use Eclipse 3.2 or even 3.1 I think.

Installation is as easy as 1, 2, 3:

  1. Add a remote update site to http://download.eclipse.org/webtools/updates/
  2. Once prompted for the components to install select “Web Standard Tools (WST)” feature in the “Web Tools Project (WTP)” category (see screenshot)
  3. Install and sit back and wait while the installation runs to completion

To show of the WSDL editing capabilities of the Eclipse editor I created a simple WSDL file with two math functions (add and subtract) as shown below.

Afterwards I imported the WSDL file into a Java web service in Domino Designer but it could as well have been LotusScript. Nice ha?