I am getting an SSL Handshake exception when trying to run a code in JDeveloper. However, the exact same code is working fine in Netbeans IDE.
The error is;
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
I know the error comes most likely when the proper certificate is not present in the truststore. This is not the case here, as I can see the certificate being added as a trusted certificate after enabling the javax.net.debug=ssl
logs.
Also, this cannot be a simple case of certificate not being available as the exact same code is working fine on Netbeans with the same truststore and java version.
The code is as follows;
package client;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import javax.ws.rs.client.Entity;
public class Class1 {
public Class1() {
super();
}
private static final String resourceUrl = "My/url";
public static void main(String[] args) {
Response headers = null;
System.out.println(System.getProperty("java.version"));
System.setProperty("javax.net.ssl.trustStore","C:\\path\\to\\jks");
System.setProperty("javax.net.ssl.trustStorePassword","passphrase");
System.setProperty("javax.net.debug","ssl");
try {
Client client = ClientBuilder.newClient();
String auth = "username:password";
byte[] authBytes = auth.getBytes(StandardCharsets.UTF_8);
String encodedAuth = Base64.getEncoder().encodeToString(authBytes);
String input = "JSON_input_payload";
headers = client
.target(resourceUrl)
.request()
.header("Authorization", "Basic " + encodedAuth)
.post(Entity.json(input));
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("Response = " + headers);
}
}
Any ideas? Perhaps I need to check some IDE specific configuration files? Couldn't figure out what to look for in Jdev config files though, hence posting the question here.
Netbeans version is 8.2
JDev versions I checked this on are 12.2.1.3.0
and 12.2.1.4.0
OS is Windows 10.
The java.version
is the same in bothe IDE's, i.e, 1.8.0_151
. I also tried running them in the version 1.8.0_221
, but got the same results.