Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

authentication with http problem  RSS feed

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble figuring out how to interact with an HTTPS site from a Java application (not applet or server-side) and submit some forms until I get to the page I need to parse for some data. In order to make sure I could figure out how to do *something*, I followed some O'Reilly Network Programming code for posting to a website (pg. 500-501) and created a Java application that can interact with http://www.weather.com and submit my local zip code and get the HTML from the result page. From there I tried to modify it to interact with the HTTPS site. I wasn't sure what I needed to change, especially with the following line:
URLConnection uc = url.openConnection();
However, I found this code online and decided to put it in after the above line:
if(uc instanceof javax.net.ssl.HttpsURLConnection ) {
System.out.println("very good");
}
else {
System.out.println("ooops, failed");
}
Because the URL I hardcoded is an https one, it prints out "very good", so I know it's automatically giving me an HttpsURLConnection.
I also used Authenticator.setDefault(mySpecificAuthenticatorSubclass());
However, when I run the code to try to interact with the site, I get this:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
So, I'm clearly not authenticating properly or something like that. Any ideas? This is actually about the 3rd approach I've taken in the past week, and I'm getting pretty frustrated!
 
norman richards
Author
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stephen Huey:

However, when I run the code to try to interact with the site, I get this:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
So, I'm clearly not authenticating properly or something like that. Any ideas? This is actually about the 3rd approach I've taken in the past week, and I'm getting pretty frustrated!

I think this is telling you that you can't verify the identity of if the web server. Do you actually care about verifying the web servers certificate? If so, you need to set up your keystore. And configure your JVM appropriately. There are some javax.net.ssl.* properties (trustStore and keyStore maybe, I'd have to look) you have to set to let the system find the certificates it needs.
If all you want is to be safe from casual snooping of your connection, you don't need anything more than what you have now...
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't care about verifying the server or anything like that. Right now, I'm just trying to connect and grab some data from a webpage. The problem is that I've gotten that exception, and I can't seem to shake it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!