Tuesday, April 6, 2010

Adding SOAP header in axiom SOAPEnvelope

SAAJ api provides addheader method to add soap header but we don't have similer method in axiom SOAPEnvelope. I took me a while to figure out how to do that. Below is the peace of code to achieve this in axiom SOAPEnvelope.

Actually I was trying to implement handler where I got hold of SOAPEnvelope form messagecontext and wanted to add SOAPHeader.

SOAPEnvelope env = ctx.getEnvelope();

SOAPHeader hdr = env.getHeader();

SOAPFactory factory = (SOAPFactory) env.getOMFactory();

OMNamespace ns = factory.createOMNamespace("http://ws.apache.org/axis2", "hns");

SOAPHeader head = factory.createSOAPHeader(env);

SOAPHeaderBlock header = head.addHeaderBlock("userID", ns);


If you happen to get hold of SOAPEnvelope you will see the following is appended in SOAPHeader section.

<hns:userID xmlns:hns="http://ws.apache.org/axis2">shiv</hns:userID>

No comments:

Post a Comment