简体   繁体   中英

javax.net.ssl.SSLHandshakeException on a tomcat server

I want to get the content of a url with the https protocol. The problem is that when this code is executed from a tomcat server , I get a HandshakeException .

url = new URL("https://donneespubliques.meteofrance.fr/donnees_libres/Txt/Nivo/nivo.20140309.csv");    
Scanner s = new Scanner(url.openStream());

I tried to look into other stackoverflow questions ( How can I use different certificates on specific connections? or SSL Socket connection ) and it seems I need to define a KeyStore .

I have no idea of how to do this.

The full error in the tomcat server is

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

What is the best way to acheve this?

The default java truststore ($JAVA_HOME/lib/security/cacerts) contains the CA cert for donneespubliques.meteofrance.fr. Most likely tomcat is using a different one.

You should be able to force it by updating the tomcat startup script to include the castore location. Something like this:

-Djavax.net.ssl.trustStore="C:\Program Files\Java\jre7\lib\security\cacerts" 
-Djavax.net.ssl.trustStorePassword=changeit 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM