PDA

View Full Version : Reading SOAP header element values using SoapHeaderElement



devijvers
Oct 31st, 2006, 08:08 AM
Hey,

I'm confused as how to read the element values in the SOAP header using the SoapHeaderElement interface. What I have so far is this:



public void invoke(MessageContext messageContext) throws Exception {
SoapMessage soapMessage = (SoapMessage) messageContext.getRequest();
SoapHeader header = soapMessage.getSoapHeader();

String messageID;
String correlationID;
for (Iterator iter = header.examineAllHeaderElements(); iter.hasNext();) {
SoapHeaderElement headerElement = (SoapHeaderElement) iter.next();

}

}


I can use the getName() method to get the element name but I can't find any methods to get the element content or value. Also, I couldn't find any information or resources on how to do this.

I understand I can use OXM to convert the SOAP header elements to objects but for me this is overkill since I only have a few elements I want to read.

Thanks for your feedback.

Arjen Poutsma
Nov 1st, 2006, 02:08 AM
You can get the contents by calling getSource(). This returns a Source XML input abstraction, i.e. it can be a DOMSource in case of an underlying DOM document, or a Stax XMLReader, etc.

You can either cast this element directly, or use a javax.xml.transform.Transfformer to transform it to the type you want.

Cheers,