![](/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.