tomcat 服务器上的 javax.net.ssl.SSLHandshakeException

标签 java jakarta-ee tomcat ssl https

我想通过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/

相关文章:

使用 Memcached 的 Tomcat session 复制,ClassNotFoundException : com. esotericsoftware.kryo.pool.KryoFactory

java - Web 应用程序无法建立与数据库的连接

java - 使用键 move BufferedImage

java - 从字符串构造 JSONArray 时出错

java - MyBatis : is it possible to set typeAlias in xml mapper?

java - Arquillian 与野蝇 10

java - Java EE 项目中的 Log4j2 配置文件

java - 在接口(interface)中存储查询以从数据库获取数据(Selenium webdriver + java)

java - 如何在 Java 中使用 JScrollPane

rest - 使用Java EE 6进行RESTful Web开发-有哪些选择?