tags:

views:

46

answers:

1

Hello,

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"&gt;
    <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"&gt;
    <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)
+1  A: 

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