SAXParseException: XML document structures must start and end within the same entity

20,161

Apache Axis 1.4 supports HTTP 1.0 by default. The server being called is using HTTP 1.1, which apparently supports Chunked Transfer Encoding.

From w3.org:

The chunked encoding modifies the body of a message in order to transfer it as a series of chunks, each with its own size indicator, followed by an OPTIONAL trailer containing entity-header fields. This allows dynamically produced content to be transferred along with the information necessary for the recipient to verify that it has received the full message.

Which means that Axis 1.4 knows nothing about chunks in the HTTP response and probably closes the connection before receiving all the chunks. When it attempts to deserialize the SOAP message, it complains that the XML is not well formed and is missing some closing tag, which is expected because it doesn't have the complete SOAP response.

The solution is to configure Axis to use CommonsHTTPSender which supports HTTP 1.1 by default. You do this by adding a client-config.wsdd on your classpath under org/apache/axis/client/client-config.wsdd with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<deployment name="ApacheCommonsHTTPConfig" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

 <globalConfiguration>

  <parameter name="disablePrettyXML" value="true"/>

  <parameter name="enableNamespacePrefixOptimization" value="false"/>

 </globalConfiguration>

 <transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender" />

 <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender" />

 <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender" />

</deployment>

The relevant setting is the transport with name "http". Most application servers already have this class loaded in their classpath, in case it isn't you need to add the Apache Commons HTTP jar to your classpath.

Share:
20,161
Zak
Author by

Zak

Updated on October 03, 2020

Comments

  • Zak
    Zak over 3 years

    I'm calling a web service from an Apache Axis 1.4 Java client. The call reaches the server correctly but the client is throwing this exception after approximately a couple of minutes:

    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: org.xml.sax.SAXParseException: XML document structures must start and end within the  same entity.
    faultActor:
    faultNode:
    faultDetail:
    

    The exception is not always the same. Sometimes it specifies a specific element in the response:

    AxisFault
    faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
    faultSubcode:
    faultString: org.xml.sax.SAXParseException: The element type &quot;name&quot; must be terminated by the matching end-tag &quot;&lt;/name&gt;&quot;.
    faultActor:
    faultNode:
    faultDetail:
    

    The web service call I am making returns a large amount of data. If I configure the server to return less data, the call is completed successfully.

    Note: Although I'm not getting any client-side time out exceptions, I tried increasing the value for the timeout to five minutes, but this had no effect.

  • Cacho Santa
    Cacho Santa over 12 years
    Works like a charm! Thanks @Zak!