javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure?

时间:2017-03-07 12:41:15

标签: java ssl

Java 1.7 + Apache Tomcat

我正在使用Rest-Full Webservice,我已经完成了以下步骤来添加证书。

1)对于Mozilla浏览器,我添加了证书,我可以在REST-CLIENT上获得响应。

2)现在我从浏览器导出了两个证书(.crt文件),并使用keytool -import -alias cmd添加到../lib/security/cacerts。

3)之后,我尝试从java代码中获取URL,但获取" javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure"

4)我添加了UnlimitedJCEPolicyJDK7 JAR,但没有得到任何回应。

客户代码:

URL url = new URL("https://myUrl/getAttributes");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/xml");
            Request reqBody = new Request();
            String input = reqBody.getXMLRequest();
            System.out.println(input);
            OutputStream os = conn.getOutputStream(); // Here it is getting failed

Stack-Trace:

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl

0 个答案:

没有答案