org.apache.axis2.AxisFault: First Element must contain the local name, Envelope , but found definitions

VPR picture VPR · May 26, 2012 · Viewed 32k times · Source

Requests works fine in my local environment and it doesn't work on the deployed environment . Requests were tried from various clients including soapui. Code is deployed on WAS

Axis2

org.apache.axis2.AxisFault: First Element must contain the local name, Envelope , but found definitions
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
    at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604)
Caused by: org.apache.axiom.soap.SOAPProcessingException: First Element must contain the local name, Envelope , but found definitions
    at java.lang.Throwable.<init>(Throwable.java:67)

Answer

etech picture etech · Jun 21, 2013

This is an issue with the server not returning the expected xml response format. This can be caused by using an incorrect service endpoint URL.

To fix, ensure that the URL used in your Axis code matches the URL for the endpoint in the WSDL that your code is based on.

Location in WSDL:

    <service name="ServiceName">
      <port name="PortName" binding="typens:PortNameBinding">
        <soap:address location="http://yourdomain.com/api/soap/"/>
      </port>
    </service>

The corresponding location in code, is typically found in the ServiceNameStub class at two locations:

    /**
     * Default Constructor
     */
    public ServiceNameStub(
            org.apache.axis2.context.ConfigurationContext configurationContext)
            throws org.apache.axis2.AxisFault {

        this(configurationContext,
                "http://yourdomain.com/api/soap/");

    }

    /**
     * Default Constructor
     */
    public ServiceNameStub() throws org.apache.axis2.AxisFault {

        this("http://yourdomain.com/api/soap/");

    }

Just ensure that those two URLs match the URL found at soap:address for the service port in your WSDL file.