开发者

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

开发者 https://www.devze.com 2023-04-02 18:08 出处:网络
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:

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 el开发者_运维技巧ement in the response:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: org.xml.sax.SAXParseException: The element type "name" must be terminated by the matching end-tag "</name>".
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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消