We run crawlers on websites to keep our info up to date. Some websites like this one allow standard navigation with the browser, but they don't send responses when using standard Java libraries. Here's the code I'm using to access the home (index) page,
try
{
URL my_url = new URL("https://www.capitallightingfixture.com");
URLConnection u = my_url.openConnection();
if ( u instanceof HttpURLConnection )
{
HttpURLConnection http_u = (HttpURLConnection)u;
System.out.println(http_u.getResponseCode());
}
}
catch (Exception e)
{
e.printStackTrace();
}
When run, this program will throw the following error
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
From what I understand about the errors, they're thrown when Java can't validate the certificate provided by the server. However, as I mentioned above, Google Chrome has no problems navigating to the page, and it even verifies the certificate (no security errors are thrown).
Is there a way I can override Java and allow it to receive the response anyway?