java - SAX 解析异常 : XML document structures must start and end within the same entity

标签 java web-services axis

我正在从 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:

异常并不总是相同的。有时它会指定响应中的特定元素:

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:

我正在进行的网络服务调用返回了大量数据。如果我将服务器配置为返回较少的数据,则调用成功完成。

注意:虽然我没有收到任何客户端超时异常,但我尝试将超时值增加到五分钟,但这没有任何效果。

最佳答案

Apache Axis 1.4 默认支持 HTTP 1.0。被调用的服务器正在使用 HTTP 1.1,它显然支持分块传输编码。

来自 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 响应中的 block 一无所知,并且可能在接收到所有 block 之前关闭连接。当它尝试反序列化 SOAP 消息时,它提示 XML 格式不正确并且缺少一些结束标记,这是预期的,因为它没有完整的 SOAP 响应。

解决方案是将 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>

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

关于java - SAX 解析异常 : XML document structures must start and end within the same entity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7306626/

相关文章:

java - Intellij自动目录添加war文件

java - Spring - 使用 Web 服务时未加载属性文件中的值

java - Axis 1.4 服务上的授权 header

java - 用于 Web 服务客户端的 AXIS 与 JAX-WS

java - 从 postman (休息服务)如何将 json 日期(字符串格式)发送到接受日期对象的 java

java - 继续对象序列化还是使用数据库?

linux - 如何计算观看视频时的CPU负载(Linux上的Web服务器)

java - "Failed to deserialize object"在点燃缓存中插入对象时出错

java - 如何并行运行 Spock 测试?

java - 3D 坐标旋转缺乏透视 2D 精度