giving the exception:
Exception in thread “main” javax.ws.rs.ProcessingException: 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
indicating that the authentication somehow doesn’t get trough.
So, essentially: how should I pass username and password to the request?
Can it be that the server certificate is a self-signed one? That could explain a lot of things!
Essentially, the cause of the problems is that the server certificate is not trusted.
A work-around (not for production!) is that a Client is generated that trusts all certificates, e.g. using the class “SslTrustAllRestClient” that can be found at: https://gist.github.com/alpegon/6ad3ab45dbcdb2dbb51ac1ac82b8995b
For this class, you will need the following imports:
import javax.net.ssl.;
import javax.ws.rs.client.;
import java.security.;
import java.security.cert.;
It is then used as follows (example using Jersey 2.6/2.7)
// create a REST client that trusts all certificates (NOT for production!)
SslTrustAllRestClient s = new SslTrustAllRestClient();
Client client = s.createClient();
// the base URI
String BASE_URI = “https://fhir.loinc.org”;
// Add authentication (LOINC username and password)
HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(userName, passWord);
client.register(feature);
IMPORTANT: in applications, always add a “MediaType” as the default is … HTML (i.e. the “website”) which of course doesn’t make sense in applications.
If the server’s certificate is self-signed, please consider a real one, that would make everything much easier.
Best regards
Jozef Aerts, XML4Pharma (mail address easy to find if someone wants to get in contact … )
Thanks Tim,
That is good to hear - so it must be something else.
Reason is that I developed a good amount of other RESTful clients that work with https and where there is no problem.
I could of course download the certificate and put it in the Java keystore, but that would make the application non-portable and hard to deploy for non-specialists.
However, it works for me right now and I can start exploring these wonderful services!