微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

禁止 Xerxes DocumentBuilderFactory 执行 HTTP 请求

如何解决禁止 Xerxes DocumentBuilderFactory 执行 HTTP 请求

我在使用 Java 11(Java 11 中包含的那个)的认 Xerces DocumentBuilderFactory 实现时遇到问题,它试图执行 HTTPURLConnection 我假设检查一些 DTD 或类似的东西。此请求未完成,因此阻止了我的整个应用程序。

为了避免这个问题,我想阻止 DocumentBuilderFactory 执行任何在线请求。有没有办法将其设置为某种离线状态?

String xml = ...
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(false);
return docBuilder.parse(new InputSource(new StringReader(xml)));

XML 输入来自外部来源,因此我对其内容没有任何影响。 DocumentBuilderFactory 必须处理我得到的所有 XML 数据,无论它包含什么,修改它是没有选择的。

停止的堆栈跟踪:

at java.net.socketInputStream.socketRead0(java.base@11.0.10/Native Method)
at java.net.socketInputStream.socketRead(java.base@11.0.10/SocketInputStream.java:115)
at java.net.socketInputStream.read(java.base@11.0.10/SocketInputStream.java:168)
at java.net.socketInputStream.read(java.base@11.0.10/SocketInputStream.java:140)
at java.io.BufferedInputStream.fill(java.base@11.0.10/BufferedInputStream.java:252)
at java.io.BufferedInputStream.read1(java.base@11.0.10/BufferedInputStream.java:292)
at java.io.BufferedInputStream.read(java.base@11.0.10/BufferedInputStream.java:351)
- locked <0x0000000581b21270> (a java.io.BufferedInputStream)
at sun.net.www.http.HttpClient.parseHTTPHeader(java.base@11.0.10/HttpClient.java:754)
at sun.net.www.http.HttpClient.parseHTTP(java.base@11.0.10/HttpClient.java:689)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(java.base@11.0.10/HttpURLConnection.java:1615)
- locked <0x0000000581b21320> (a sun.net.www.protocol.http.HttpURLConnection)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(java.base@11.0.10/HttpURLConnection.java:1520)
- locked <0x0000000581b21320> (a sun.net.www.protocol.http.HttpURLConnection)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(java.xml@11.0.10/XMLEntityManager.java:676)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(java.xml@11.0.10/XMLEntityManager.java:1398)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(java.xml@11.0.10/XMLEntityManager.java:1364)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(java.xml@11.0.10/XMLDTDScannerImpl.java:257)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(java.xml@11.0.10/XMLDocumentScannerImpl.java:1152)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(java.xml@11.0.10/XMLDocumentScannerImpl.java:1040)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(java.xml@11.0.10/XMLDocumentScannerImpl.java:943)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(java.xml@11.0.10/XMLDocumentScannerImpl.java:605)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(java.xml@11.0.10/XMLDocumentFragmentScannerImpl.java:534)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.10/XML11Configuration.java:888)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(java.xml@11.0.10/XML11Configuration.java:824)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(java.xml@11.0.10/XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(java.xml@11.0.10/DOMParser.java:246)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(java.xml@11.0.10/DocumentBuilderImpl.java:339)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。