![](/img/trans.png)
[英]Use SOAP 1.2 with WebServiceGatewaySupport in Spring
[英]SOAP 1.2 with Axis 2 is not parsed
我正在編寫一個接收SOAP 1.2消息的服務器。 我遇到的問題是,當我通過SOAPui發送SOAP 1.1消息時,該消息得到了正確處理,而當它是SOAP 1.2消息時卻沒有得到正確處理。 我使用axis2。
這是我的POM依賴項:
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-saaj</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
這是我運行服務器的主要例程。 這不是實際的服務器(無線程),目的是為了顯示問題。
public class App {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(3400);
Socket socket = server.accept();
BasicHttpParams params = new BasicHttpParams();
DefaultHttpServerConnection conn = new DefaultHttpServerConnection();
conn.bind(socket, params);
HttpRequest request = conn.receiveRequestHeader();
if (request instanceof HttpEntityEnclosingRequest) {
conn.receiveRequestEntity((HttpEntityEnclosingRequest) request);
HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
if (entity != null) {
MessageFactory soapMessageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = soapMessageFactory.createMessage(
new MimeHeaders(), entity.getContent());
SOAPBody soapBody = soapMessage.getSOAPBody();
entity.consumeContent();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
SOAP 1.1消息
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
SOAP 1.2消息
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
</soapenv:Body>
</soapenv:Envelope>
我在1.2消息中遇到的異常
javax.xml.soap.SOAPException: org.apache.axiom.soap.SOAPProcessingException: Disallowed element found inside Envelope : {http://www.w3.org/2003/05/soap-envelope}Body
at org.apache.axis2.saaj.SOAPPartImpl.<init>(SOAPPartImpl.java:228)
at org.apache.axis2.saaj.SOAPPartImpl.<init>(SOAPPartImpl.java:246)
at org.apache.axis2.saaj.SOAPMessageImpl.<init>(SOAPMessageImpl.java:99)
at org.apache.axis2.saaj.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:131)
at lolissimo.xhiara.App.main(App.java:33)
嘗試訪問spring框架WS時遇到相同的錯誤。
因此,經過一些意圖和修復以自定義輸出XML,最后我得到了這個uri "http://www.w3.org/2003/05/soap-envelope"
而不是"http://schemas.xmlsoap.org/soap/envelope/"
。
因此,將協議規范從1.2更改為1.1解決了該問題:
MessageFactory.newInstance();
代替:
MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
在這兩種情況下,您仍然可以自定義前綴和名稱空間。 而且,如果您嘗試使用spring WS,請不要忘記在信封中包含"soapenv"
前綴。
我得到的是WSWS4104E: A SOAP 1.2 Protocol is not supported by SAAJ 1.2.
嘗試使用WSDL端點連接到現有Web服務時出錯。 據觀察,IBM特定的jar
不在類路徑中。 jar文件是com.ibm.jaxws.thinclient_8.0.0.jar
。
變量名稱為WAS_V8JAXWS_WEBSERVICES_THINCLIENT
。 在將此變量添加到Java Build Path之后,我不再看到此錯誤。
另一個版本的鏈接: http : //www-01.ibm.com/support/docview.wss?uid=swg21316678
您應該嘗試SAAJ的正式實施。
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.