title: Extract body from SOAP Request
body: <p>I am parsing a SOAP request.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gas="http://solveralynx.com/abc/webservice/pressuredataaccess"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;pressure:getBalance&gt;
           &lt;!--Optional:--&gt;
           &lt;dateFrom&gt;: 2021-02-04&lt;/dateFrom&gt;
           &lt;!--Optional:--&gt;
           &lt;dateTo&gt;: 2021-02-06&lt;/dateTo&gt;
           &lt;!--Optional:--&gt;
           &lt;Ident&gt;26986&lt;/Ident&gt;
        &lt;/pressure:getBalance&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I want to take the body of SOAP envelop but code which i have to write should be compatible to
  <strong>public void process(org.apache.camel.Exchange exchange)</strong> because I am writing it inside a component cProcessr.</p>
  <p>I am struggling with it
  I am trying this</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import javax.xml.soap.*;
  import javax.xml.soap.SOAPBody;
  import javax.xml.soap.SOAPElement;
  
  MessageFactory messageFactory = MessageFactory.newInstance();
  SOAPMessage soapMessage = messageFactory.createMessage();
  SOAPPart soapPart = soapMessage.getSOAPPart();
  SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
  SOAPBody soapBody = soapEnvelope.getBody();
  Iterator itr=soapResponse.getSOAPBody().getChildElements();
  while (itr.hasNext()) {
      Node node=(Node)itr.next();
      if (node.getNodeType()==Node.ELEMENT_NODE) {
          Element ele=(Element)node;
          out.println(ele.getNodeName() + " = " + ele.getTextContent());
      } else if (node.getNodeType()==Node.TEXT_NODE) {
          //do nothing here most likely, as the response nearly never has mixed content type
          //this is just for your reference
      }
  }</code></pre>
  </div>
  </div>
  </p>
  <p>it is throwing following error
  <a href="https://i.stack.imgur.com/xXikZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xXikZ.png" alt="enter image description here" /></a>
  Am not sure even if it is taking the body or not because in Log file it is printing nothing. Does the code is ok and compatible for org.apache.camel.Exchange or there is some other way.</p>