I’m trying to print a URL (without having a browser involved at all) but the URL is currently throwing the following:
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
I’m calling the URL using a JEditorPane’s setPage method, which just takes a URL as a parameter. Assuming I can’t change anything server side and I still need to get to this resource, how would I go about ignoring the certificate error (or something else that gets me to my goal)?
Accessing this URL via a browser tells me the site is untrusted and asks me if I want to proceed.
Extend
JEditorPaneto override thegetStream()method.Inside that method, you can open a
URLConnection. Test whether it is anHttpsURLConnection. If it is, initialize your ownSSLContextwith a customX509TrustManagerthat doesn’t perform any checks. Get the context’sSSLSocketFactoryand set it as the socket factory for the connection. Then return theInputStreamfrom the connection.This will defeat any attempts by the runtime to protect the user from a spoof site serving up malware. If that’s really what you want…