gpt4 book ai didi

java - 带有 Axis 2 的 SOAP 1.2 未解析

转载 作者:行者123 更新时间:2023-12-01 19:22:30 25 4
gpt4 key购买 nike

我正在编写一个接收 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/”

因此,将协议(protocol)规范从 1.2 更改为 1.1 解决了问题:

MessageFactory.newInstance();

而不是:

MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

在这两种情况下,您仍然可以自定义前缀和命名空间。而且,如果您尝试使用 Spring WS,请不要忘记在信封中包含 "soapenv" 前缀。

关于java - 带有 Axis 2 的 SOAP 1.2 未解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3365022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com