java SAXParseException: XML 文档结构必须在同一实体内开始和结束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7306626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SAXParseException: XML document structures must start and end within the same entity
提问by Zak
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:
我正在从 Apache Axis 1.4 Java 客户端调用 Web 服务。调用正确到达服务器,但客户端在大约几分钟后抛出此异常:
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 "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.
我进行的 Web 服务调用会返回大量数据。如果我将服务器配置为返回较少的数据,则调用成功完成。
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.
注意:虽然我没有收到任何客户端超时异常,但我尝试将超时值增加到五分钟,但这没有效果。
回答by Zak
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.
Apache Axis 1.4 默认支持 HTTP 1.0。被调用的服务器使用 HTTP 1.1,它显然支持分块传输编码。
From w3.org:
来自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.
这意味着 Axis 1.4 对 HTTP 响应中的块一无所知,并且可能在接收所有块之前关闭连接。当它尝试反序列化 SOAP 消息时,它抱怨 XML 格式不正确并且缺少一些结束标记,这是意料之中的,因为它没有完整的 SOAP 响应。
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:
解决方案是将 Axis 配置为使用默认支持 HTTP 1.1 的 CommonsHTTPSender。您可以通过在 org/apache/axis/client/client-config.wsdd 下的类路径上添加一个 client-config.wsdd 来完成此操作,其中包含以下内容:
<?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 jarto your classpath.
相关设置是名称为“http”的传输。大多数应用程序服务器已经在它们的类路径中加载了这个类,以防万一您不需要将Apache Commons HTTP jar添加到您的类路径中。