'Extract body from SOAP Request
I am parsing a SOAP request.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gas="http://solveralynx.com/abc/webservice/pressuredataaccess">
<soapenv:Header/>
<soapenv:Body>
<pressure:getBalance>
<!--Optional:-->
<dateFrom>: 2021-02-04</dateFrom>
<!--Optional:-->
<dateTo>: 2021-02-06</dateTo>
<!--Optional:-->
<Ident>26986</Ident>
</pressure:getBalance>
</soapenv:Body>
</soapenv:Envelope>
I want to take the body of SOAP envelop but code which i have to write should be compatible to public void process(org.apache.camel.Exchange exchange) because I am writing it inside a component cProcessr.
I am struggling with it I am trying this
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
}
}
it is throwing following error
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
