【发布时间】:2016-02-25 09:21:00
【问题描述】:
我正在使用 java 应用程序检查 url 连接性,对于某些 url(内部)应用程序 url,我得到 200(成功),对于其他我得到以下异常。
但是如果我手动连接到下面的 url,没有问题,我需要 pki 证书吗? 需要你的帮助。
URL 链接响应代码 (200),好
http://pns15a-0215.corpny.com:21212/Mngr200 OK OK
网址链接响应异常
https://tantex.intra.net/Mngr/
异常消息: sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径
日志
javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法在 sun.security.ssl 中找到请求目标的有效证书路径。在 sun.security.ssl.Handshaker.fatalSE(Handshaker.java:276) 在 sun.security.ssl 在 sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1884) 在 sun.security.ssl 的 Alerts.getSSLException(Alerts.java:192) .Handshaker.fatalSE(Handshaker.java:270) 在 sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1341) 在 sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:153)
程序源代码
log.info("testing the httpurlconnection for url:" + strUrl );
url = new URL(strUrl);
urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK )
{
log.info("url http connection is sucessfull");
//append the response status
urlResponseStatus = "OK";
}
else
{
log.info("url http connection failure, response code:" + urlConn.getResponseCode());
//append the response status
urlResponseStatus = "NOT OK";
}
urlResponseCode = urlConn.getResponseCode();
urlResponseMessage = urlConn.getResponseMessage();
【问题讨论】:
标签: java