This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Https problem when accessing through java programs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Https problem when accessing through java programs" Watch "Https problem when accessing through java programs" New topic
Author

Https problem when accessing through java programs

Anand Natraj
Ranch Hand

Joined: May 17, 2004
Posts: 53
Hi

I am facing a problem with Https.

I have successfully configured verisign certificate and I am able to access through browser like
https://localhost:8443/hello/mypattern


But when we try to access through java program it�s throwing following exception.



javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certifica
te found
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.j(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(DashoA6275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA6275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA6275)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:617)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(DashoA6275)
at java.net.URL.openStream(URL.java:913)
at TestHttps.main(TestHttps.java:18)
Caused by: sun.security.validator.ValidatorException: No trusted certificate found
at sun.security.validator.SimpleValidator.buildTrustedChain(SimpleValidator.java:304)
at sun.security.validator.SimpleValidator.engineValidate(SimpleValidator.java:107)
at sun.security.validator.Validator.validate(Validator.java:202)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(DashoA6275)
at com.sun.net.ssl.internal.ssl.JsseX509TrustManager.checkServerTrusted(DashoA6275)
... 12 more



The following is my java program.


import java.net.*;

import javax.net.*;

import java.io.*;

class TestHttps{

public static void main(String[] args){

String dataLine;

try{


System.setProperty("javax.net.ssl.keyStore","D:\\lbs2kv.keystore");
System.setProperty("javax.net.ssl.keyStorePassword","password");
URL url = new URL("https://localhost:8443/hello/mypattern");
BufferedReader htmlPage = new BufferedReader(new InputStreamReader(url.openStream()));
while ((dataLine = htmlPage.readLine()) != null){
System.out.println(dataLine);
}
htmlPage.close();

}

catch(Exception e){

// System.out.println(e.getMessage());

e.printStackTrace();

}

}

}

Pls let me know how I can solve this problem



Thanks in advance



Regards

Anand
 
 
subject: Https problem when accessing through java programs