我正在编写一个接收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)
答案 0 :(得分:2)
尝试访问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);
在这两种情况下,您仍然可以自定义前缀和名称空间。而且,如果您尝试使用弹簧WS,请不要忘记在信封中包含"soapenv"
前缀。
答案 1 :(得分:1)
您应该尝试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>
答案 2 :(得分:1)
尝试使用WSDL端点连接到现有Web服务时出现WSWS4104E: A SOAP 1.2 Protocol is not supported by SAAJ 1.2.
错误。据观察,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