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();

5 thoughts on “SOAP Headers in Lotus Domino web service consumers and providers”

Comments are closed.