JAXB + SAX + Open JDK 8 通过客户端异常重置连接

问题描述 投票:0回答:1

我的代码从网络下载 XML 报告并将原始 XML 分配给字符串变量。然后它创建一个 SAXPaser,如下所示:

try {
             SAXParserFactory spf = SAXParserFactory.newInstance();
    
             spf.setXIncludeAware(true);
             spf.setNamespaceAware(true);
             spf.setValidating(true); // Not required for JAXB/XInclude
    
             XMLReader xr = (XMLReader) spf.newSAXParser().getXMLReader();
             xr.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false); //with true report could not be parsed
             xr.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); // This may not be strictly required as DTDs shouldn't be allowed at all, per previous line.
             xr.setFeature("http://xml.org/sax/features/external-general-entities", false);
             xr.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
             return new SAXSource(xr,  new InputSource(new StringReader(output)));
        } catch (Exception e) {
            e.printStackTrace();
        }

然后调用 jaxb 方法来解组 XML,如下所示

jaxbUnmarshaller.unmarshal(saxSource);

这会触发以下异常。在文档中查找类并“ClassLoader:null”

factoryClassName - 提供 javax.xml.parsers.SAXParserFactory 实现的完全限定工厂类名称。

classLoader - 用于加载工厂类的ClassLoader。如果为null,则使用当前线程的上下文classLoader来加载工厂类。

我看到其他人在 SOF 上给出的建议说不要使用“com.sun”包。不幸的是我必须使用 Java 8,具体来说:

openjdk版本“1.8.0_392”

据我所知,异常背后的代码适用于 Oracle Java 8。我将不胜感激任何帮助。

谢谢你

JAXP: find factoryId =javax.xml.parsers.SAXParserFactory JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl JAXP: created new instance of class com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl using ClassLoader: null javax.xml.bind.UnmarshalException - with linked exception: [javax.net.ssl.SSLException: Connection reset] at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:246) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:214) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:140) at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:123) at com.matrix.clientmanager.ws.nipr.ScbDownloadReport.downloadReport(ScbDownloadReport.java:74) at com.matrix.clientmanager.autobatch.RunLicenseConfig.checkReportResults(RunLicenseConfig.java:325) at com.matrix.clientmanager.autobatch.RunLicenseConfig.<init>(RunLicenseConfig.java:87) at com.matrix.clientmanager.autobatch.AutoBatch.runLicenseConfig(AutoBatch.java:3352) at com.matrix.clientmanager.autobatch.RunAutoBatch.main(RunAutoBatch.java:1111) Caused by: javax.net.ssl.SSLException: Connection reset at sun.security.ssl.Alert.createSSLException(Alert.java:127) at sun.security.ssl.TransportContext.fatal(TransportContext.java:331) at sun.security.ssl.TransportContext.fatal(TransportContext.java:274) at sun.security.ssl.TransportContext.fatal(TransportContext.java:269) at sun.security.ssl.SSLTransport.decode(SSLTransport.java:138) at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1401) at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1309) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:440) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:197) at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1572) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1500) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:268) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:648) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1305) at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XMLEntityManager.java:1271) at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XMLDTDScannerImpl.java:264) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(XMLDocumentScannerImpl.java:1160) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(XMLDocumentScannerImpl.java:1044) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:958) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:601) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:642) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:243) ... 8 more Suppressed: java.net.SocketException: Broken pipe (Write failed) at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) at java.net.SocketOutputStream.write(SocketOutputStream.java:155) at sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81) at sun.security.ssl.TransportContext.fatal(TransportContext.java:362) ... 35 more Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:210) at java.net.SocketInputStream.read(SocketInputStream.java:141) at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:464) at sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:165) at sun.security.ssl.SSLTransport.decode(SSLTransport.java:109) ... 32 more
    
java java-8 xml-parsing jaxb saxparser
1个回答
0
投票
有人可能会从这个答案中受益。

XML 的序言中有这个 DTD

<!DOCTYPE SCB_Report SYSTEM 'https://example.com/html/SCB_XML_Report.dtd'>
防火墙阻止了该 URL。

© www.soinside.com 2019 - 2024. All rights reserved.