原本實作的RESTful Client(Java HttpsURLConnection)模擬request時,伺服器回應了以下錯誤:
javax.servlet.ServletException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:418)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Google了一下找到了這篇文章:
http://smilelifes.blogspot.com/2007/04/unable-to-find-valid-certification-path.html
由於系統加上了SSL加密機制且Certificate是自已作的,導致Java無法得知去哪裡找到Certificate?
所以需要將當初建立的ca certificate 匯入到JDK內部的cacerts中即可解決!!
keytool -import -file myca.cert -keystore %JAVA_HOME%\jre\lib\security\cacerts -file myca.cert -alias tomcat
http://blog.csdn.net/sfdev/article/details/2957240
回覆刪除可以參考看看喔!
謝喇。
回覆刪除