Announcement Announcement Module
No announcement yet.
Reading SOAP header element values using SoapHeaderElement Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading SOAP header element values using SoapHeaderElement


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

  • #2
    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.