javax.net.ssl.SSLHandshakeException:在 jdk 6 中握手期间远程主机关闭连接

Posted

技术标签:

【中文标题】javax.net.ssl.SSLHandshakeException:在 jdk 6 中握手期间远程主机关闭连接【英文标题】:javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake in jdk 6 【发布时间】:2016-05-27 19:28:03 【问题描述】:

我有这段代码用于使用 cxf 和 jdk 7 调用 Web 服务:

try 
        IEService port = null;
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, new TrustManager[]new TrustAllX509TrustManager(), new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() 
            public boolean verify(String string, SSLSession ssls) 
                return true;
            
        );

        EService service = new EService();
        port = service.getEServiceEndPoint();

        Map ctx = ((BindingProvider) port).getRequestContext();
        ctx.put("ws-security.username", "username");
        ctx.put("ws-security.password", "password");
        HTTPConduit httpConduit = (HTTPConduit) ClientProxy.getClient(port).getConduit();
        TLSClientParameters tlsCP = new TLSClientParameters();
        tlsCP.setDisableCNCheck(true);
        httpConduit.setTlsClientParameters(tlsCP);

        voucherResponse = port.registerVoucher(voucherRequest);
     catch (Exception e) 
        System.out.println(e.getMessage());
        e.printStackTrace();

    

当我使用 jdk 7 时,此代码可以正常工作,但我应该在我的项目中使用 jdk 6。使用 jdk 6 会抛出以下错误:

javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:98)
at javax.xml.ws.Service.<init>(Service.java:56)
at RayanmehrServiceClient.EchargeService.<init>(EService.java:42)
at com.bps.sw.channels.topup.rayanmehr.RayanMehrServices.main(MehrServices.java:162)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:100)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:203)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:147)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'https://api.domain.com/Services/Strict/Version1/EService.svc?singleWsdl'.: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:249)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:192)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:98)
... 6 more
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1139)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1049)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:771)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:225)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:283)
... 12 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
... 26 more

如何解决这个问题?

【问题讨论】:

【参考方案1】:

尝试在您的 java6>jre>security>lib> 文件夹中添加 Java Criptography Extension 的 jar,替换其中已经存在的。

你可以在这里下载http://www.oracle.com/technetwork/es/java/javase/downloads/jce-6-download-429243.html

【讨论】:

废话!所以...如果它与 java 7 一起使用...尝试复制您的信任库,从 jvm7 到 jvm6

以上是关于javax.net.ssl.SSLHandshakeException:在 jdk 6 中握手期间远程主机关闭连接的主要内容,如果未能解决你的问题,请参考以下文章