简体   繁体   中英

Parsing SOAP request sent from SOAPUI - using Axis2 Servlet

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM