簡體   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