I am having problems with the default Xerces DocumentBuilderFactory
implementation of Java 11 (the one included in Java 11) which tries to perform an HTTPURLConnection
I assume to check some DTD or something like that. This request does not finish and thus is blocking my whole app.
To avoid this problem I would like to prevent DocumentBuilderFactory
to perform any online requests. Is there a way to set it into some sort of offline state?
String xml = ...
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(false);
return docBuilder.parse(new InputSource(new StringReader(xml)));
The XML input comes from external sources, therefore I don't have any influence on it's content. DocumentBuilderFactory has to process all XML data I get no matter what it contains, modifying it is no option.
Stack trace where it stops:
at java.net.SocketInputStream.socketRead0([email protected]/Native Method)
at java.net.SocketInputStream.socketRead([email protected]/SocketInputStream.java:115)
at java.net.SocketInputStream.read([email protected]/SocketInputStream.java:168)
at java.net.SocketInputStream.read([email protected]/SocketInputStream.java:140)
at java.io.BufferedInputStream.fill([email protected]/BufferedInputStream.java:252)
at java.io.BufferedInputStream.read1([email protected]/BufferedInputStream.java:292)
at java.io.BufferedInputStream.read([email protected]/BufferedInputStream.java:351)
- locked <0x0000000581b21270> (a java.io.BufferedInputStream)
at sun.net.www.http.HttpClient.parseHTTPHeader([email protected]/HttpClient.java:754)
at sun.net.www.http.HttpClient.parseHTTP([email protected]/HttpClient.java:689)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0([email protected]/HttpURLConnection.java:1615)
- locked <0x0000000581b21320> (a sun.net.www.protocol.http.HttpURLConnection)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream([email protected]/HttpURLConnection.java:1520)
- locked <0x0000000581b21320> (a sun.net.www.protocol.http.HttpURLConnection)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity([email protected]/XMLEntityManager.java:676)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity([email protected]/XMLEntityManager.java:1398)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity([email protected]/XMLEntityManager.java:1364)
at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource([email protected]/XMLDTDScannerImpl.java:257)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch([email protected]/XMLDocumentScannerImpl.java:1152)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next([email protected]/XMLDocumentScannerImpl.java:1040)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next([email protected]/XMLDocumentScannerImpl.java:943)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next([email protected]/XMLDocumentScannerImpl.java:605)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument([email protected]/XMLDocumentFragmentScannerImpl.java:534)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:888)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse([email protected]/XML11Configuration.java:824)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse([email protected]/XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse([email protected]/DOMParser.java:246)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse([email protected]/DocumentBuilderImpl.java:339)