javax.net.ssl.SSLHandshakeException:在HTTP Web连接后的Rest Webservice中,添加证书后也是如此

时间:2017-10-29 11:29:52

标签: java rest ssl exception

我部署了一个REST应用程序Web服务,在客户端,在构建URL之后,我正在建立HTTP URL连接&打开Buffered Reader将数据流发送到服务器端。

以下是代码片段。

SSLContext sc = SSLContext.getInstance("SSL");
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
         new javax.net.ssl.HostnameVerifier(){

              public boolean verify(String hostname,
                      javax.net.ssl.SSLSession sslSession) {
                  return true;
              }
        });

HttpURLConnection conn = (HttpURLConnection) tnprestapplicationURL.openConnection();
String USER_AGENT = "Mozilla/5.0";

conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

BufferedReader br = new BufferedReader(new 
InputStreamReader((conn.getInputStream())));

我在SSL连接时添加了证书。我不知道这个概念。下面是我添加的一段代码,以摆脱异常,但我仍面临异常。任何人都可以帮忙吗?

Final Url is  https://10.53.108.123:8443/tnpWS/webapi/tnp/getAlerts?exportCustomFields=Severity,KPI,Dimension,Referencevalue,KPIvalue,Starttime,Endtime,Notificationstatus|PERCEIVED_SEVERITY,PI_NAME,PI_DIM_VALUE,THRESHOLD_VALUE,OBSERVED_VALUE,from_unixtime(CAST(PI_START_TIME/1000asBIGINT))PI_START_TIME,from_unixtime(CAST(PI_END_TIME/1000asBIGINT))PI_END_TIME,PI_NOTIFY_STATUS&startDate=29-10-2017%2014:00:00&queryType=getAlerts&severity=&endDate=29-10-2017%2016:41:06&exportDB=false&exportFields=&exportFileName=&
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1914)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:279)
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:273)
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1477)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:213)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:961)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:897)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1033)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1342)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1369)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1353)
        at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1348)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
        at com.nokia.tnp.alertmonitor.actions.AlertMonitorActionController.getData(AlertMonitorActionController.java:165)

0 个答案:

没有答案