0

Here's the SOAP request that I am submitting using SOAPUI

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:My namespace="My Package">
   <soapenv:Header>
    <Username>q</Username>
    <Password>q</Password>
   </soapenv:Header>
   <soapenv:Body>
      <Op:Op>
         <Op:int>2134</Op:int>
      </Op:Op>
   </soapenv:Body>
</soapenv:Envelope>

Now I have created a maven project in eclipse and have generated a wsdl file, aar file (for deploying using Tomcat 7) and a jar file from the Java code (java2wsdl). When the request is submitted, the code must authorize the user with credentials provided under the header element. However, I am not able to parse the SOAP request. When I tried parsing with,

SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = fac.getDefaultEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
Iterator it = header.getChildElements();
Iterator bodyIt = body.getChildElements();
while (it.hasNext()) {
    OMElement e = (OMElement) it.next();
    System.out.println(e.getText().toString());
}
while (bodyIt.hasNext()) {
    OMElement e = (OMElement) bodyIt.next();
    System.out.println(e.getText().toString());
}

whereby SOAPFactory and other objects are imported from axiom, none of the print statements where executed. So the question is how do I parse this request so that I have the ability to read the header and body?

I apologize if anything is vague; I am still new to Java web services.

1 Answer 1

0

From the Javadoc of the SOAPFactory#getDefaultEnvelope() method:

Create a default SOAP envelope with an empty header and an empty body.

So your Java code behaves as expected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.