简体   繁体   中英

SOAP 1.2 with Axis 2 is not parsed

I am writing a server that receives SOAP 1.2 messages. 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. I use axis2.

Here is my POM dependency:

  <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

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

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

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.

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/" .

So, chanching the protocol specification from 1.2 to 1.1 solved the problem:

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.

I was getting 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. It was observed that the IBM specific jar was not in the class path. The jar file is com.ibm.jaxws.thinclient_8.0.0.jar .

The variable name is WAS_V8JAXWS_WEBSERVICES_THINCLIENT . After adding this variable to Java Build Path I no longer see this error.

Also a link to the other version: http://www-01.ibm.com/support/docview.wss?uid=swg21316678

You should try with the official implementation of 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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