我想通过https协议(protocol)获取一个url的内容。问题是,当从 tomcat 服务器 执行此代码时,我得到一个 HandshakeException。
url = new URL("https://donneespubliques.meteofrance.fr/donnees_libres/Txt/Nivo/nivo.20140309.csv");
Scanner s = new Scanner(url.openStream());
我试图查看其他 stackoverflow 问题(How can I use different certificates on specific connections? 或 SSL Socket connection),看来我需要定义一个 KeyStore
。
我不知道该怎么做。
tomcat服务器的完整错误是
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
实现此目标的最佳方法是什么?
最佳答案
默认的 java truststore ($JAVA_HOME/lib/security/cacerts) 包含 donneespubliques.meteofrance.fr 的 CA 证书。很可能 tomcat 使用的是不同的。
您应该能够通过更新 tomcat 启动脚本以包含 castore 位置来强制执行它。像这样:
-Djavax.net.ssl.trustStore="C:\Program Files\Java\jre7\lib\security\cacerts"
-Djavax.net.ssl.trustStorePassword=changeit
关于tomcat 服务器上的 javax.net.ssl.SSLHandshakeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22422255/