繁体   English   中英

解析从SOAPUI发送的SOAP请求-使用Axis2 Servlet

[英]Parsing SOAP request sent from SOAPUI - using Axis2 Servlet

这是我正在使用SOAPUI提交的SOAP请求

<?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>

现在,我在eclipse中创建了一个maven项目,并从Java代码(java2wsdl)中生成了wsdl文件,aar文件(用于使用Tomcat 7进行部署)和jar文件。 提交请求后,代码必须使用标题元素下提供的凭据授权用户。 但是,我无法解析SOAP请求。 当我尝试解析时,

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());
}

从而SOAPFactory和其他对象是从公理导入的,没有执行任何print语句。 因此,问题是如何解析此请求,以便能够读取标头和正文?

如果有任何疑问,我深表歉意。 我还是Java Web服务的新手。

SOAPFactory#getDefaultEnvelope()方法的Javadoc中:

创建具有空头和空主体的默认SOAP信封。

因此,您的Java代码的行为符合预期。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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