SAXParseException:XML文档结构必须在同一实体中开始和结束 [英] SAXParseException: XML document structures must start and end within the same entity

查看:899
本文介绍了SAXParseException:XML文档结构必须在同一实体中开始和结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Apache Axis 1.4 Java客户端调用Web服务。呼叫正确到达服务器,但客户端在大约几分钟后抛出此异常:

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 "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默认支持HTTP 1.0。被调用的服务器正在使用HTTP 1.1,它显然支持Chunked Transfer Encoding。

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.

来自 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.

其中意味着Axis 1.4对HTTP响应中的块没有任何了解,并且可能在接收所有块之前关闭连接。当它试图反序列化SOAP消息时,它抱怨XML没有很好地形成并且缺少一些结束标记,这是预期的,因为它没有完整的SOAP响应。

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配置为使用默认支持HTTP 1.1的CommonsHTTPSender。您可以通过在org / apache / axis / client / client-config.wsdd下的类路径上添加client-config.wsdd来实现此目的:

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>

相关设置是名为http的传输。
大多数应用程序服务器已经在类路径中加载了这个类,如果不是你需要添加 Apache Commons HTTP jar 到你的类路径。

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.

这篇关于SAXParseException:XML文档结构必须在同一实体中开始和结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆