简体   繁体   English

未解析带有Axis 2的SOAP 1.2

[英]SOAP 1.2 with Axis 2 is not parsed

I am writing a server that receives SOAP 1.2 messages. 我正在编写一个接收SOAP 1.2消息的服务器。 The problem I have is that when I am sending via SOAPui a SOAP 1.1 message, the message is correctly handled but not when it's a SOAP 1.2 message. 我遇到的问题是,当我通过SOAPui发送SOAP 1.1消息时,该消息得到了正确处理,而当它是SOAP 1.2消息时却没有得到正确处理。 I use axis2. 我使用axis2。

Here is my POM dependency: 这是我的POM依赖项:

  <dependencies>
    <dependency>
        <groupId>org.apache.axis2</groupId>
        <artifactId>axis2-saaj</artifactId>
        <version>1.4.1</version>
    </dependency>
  </dependencies>

Here is my main routine to run the server. 这是我运行服务器的主要例程。 This is not the actual server (no thread), the purpose is to show the problem. 这不是实际的服务器(无线程),目的是为了显示问题。

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 message 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 message 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>

The exception I got with the 1.2 message 我在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)

I got the same error when tried to access a spring framework WS. 尝试访问spring框架WS时遇到相同的错误。

So, after several intents and fixes to customize the output XML, Finally I was getting this uri "http://www.w3.org/2003/05/soap-envelope" instead of "http://schemas.xmlsoap.org/soap/envelope/" . 因此,经过一些意图和修复以自定义输出XML,最后我得到了这个uri "http://www.w3.org/2003/05/soap-envelope"而不是"http://schemas.xmlsoap.org/soap/envelope/"

So, chanching the protocol specification from 1.2 to 1.1 solved the problem: 因此,将协议规范从1.2更改为1.1解决了该问题:

MessageFactory.newInstance();

instead of: 代替:

MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

In both cases you can still customize your prefixes and namespaces. 在这两种情况下,您仍然可以自定义前缀和名称空间。 And, if you are trying to consuming a spring WS do not forget to include the "soapenv" prefix in your envelope. 而且,如果您尝试使用spring WS,请不要忘记在信封中包含"soapenv"前缀。

I was getting WSWS4104E: A SOAP 1.2 Protocol is not supported by SAAJ 1.2. 我得到的是WSWS4104E: A SOAP 1.2 Protocol is not supported by SAAJ 1.2. error while trying to connect to an existing web service with WSDL end point. 尝试使用WSDL端点连接到现有Web服务时出错。 It was observed that the IBM specific jar was not in the class path. 据观察,IBM特定的jar不在类路径中。 The jar file is com.ibm.jaxws.thinclient_8.0.0.jar . jar文件是com.ibm.jaxws.thinclient_8.0.0.jar

The variable name is WAS_V8JAXWS_WEBSERVICES_THINCLIENT . 变量名称为WAS_V8JAXWS_WEBSERVICES_THINCLIENT After adding this variable to Java Build Path I no longer see this error. 在将此变量添加到Java Build Path之后,我不再看到此错误。

Also a link to the other version: http://www-01.ibm.com/support/docview.wss?uid=swg21316678 另一个版本的链接: http : //www-01.ibm.com/support/docview.wss?uid=swg21316678

You should try with the official implementation of SAAJ . 您应该尝试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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM