java - XML 模式验证时超时和挂起线程

标签 java xml xsd timeout

我在通过 XSD 架构验证 XML 时收到 TimeoutException,并且与检查器关联的线程被挂起。

为什么会这样呢?如何避免这种情况?

堆栈跟踪:

TimeoutManage I   WTRN0124I: When the timeout occurred the thread with which the transaction is, or was most recently, associated was Thread[WebContainer : 3,5,main].  The stack trace of this thread when the timeout occurred was:
        java.net.SocketInputStream.socketRead0(Native Method)
        java.net.SocketInputStream.read(SocketInputStream.java:140)
        java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
        java.io.BufferedInputStream.read1(BufferedInputStream.java:269)
        java.io.BufferedInputStream.read(BufferedInputStream.java:328)
        sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:700)
        sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
        sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
        org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
        org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
        org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
        org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
        org.apache.xerces.impl.xs.opti.SchemaDOMParser.parse(Unknown Source)
        org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
        org.apache.xerces.impl.xs.traversers.XSDHandler.resolveSchema(Unknown Source)
        org.apache.xerces.impl.xs.traversers.XSDHandler.constructTrees(Unknown Source)
        org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
        org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
        org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
        org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
        org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
        javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
        my.utils.XmlUtils.validate(XmlUtils.java:38)

用于验证的代码片段:

SchemaFactory schemaFactory = 
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
    Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));
    Validator validator = schema.newValidator();
...

异常发生在行:

Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));

最佳答案

如果没有看到实际的 XSD,很难确定,但很可能您的架构不是自包含的,而是包含一个或多个引用外部 URL 的 include 语句。 schemaFactory 可能会尝试获取它们来构建完整的 XSD。

指出这一点的原因之一是堆栈跟踪中对 getSchemaDocument() 的调用,该调用试图在执行 parseSchema()< 的过程中通过 HTTP 获取架构文档 您传入的 xsd 上。

关于java - XML 模式验证时超时和挂起线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12447126/

相关文章:

Java反问题

java - 没有运行第一个 Activity

xml - 有没有可以让我查询 XML 文件的 GUI?

xsd - 是否可以在 org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition 中使用 WSDL?

java - 如何让 JFrame 真正全屏?

java - 如何在 Spring 的 web.xml 中获取配置文件特定的 pom 属性?

java - XML 架构模式错误

java - w3schools xsd 示例不适用于 dom4j。如何使用 dom4j 通过 xsds 验证 xml?

java - 在 BigQuery Java UDF 中对数组进行累积和时出现问题

xml - XSD 验证错误 : Cannot Find The Declaration Of Element 'soapenv:Envelope'