2

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.

Shivam Puri
  • 1,578
  • 12
  • 25
  • [1] Does this help: [How to configure JDeveloper to trust an SSL certificate and fix PKIX path building failed when connecting to an Https URL?](https://cedricleruth.com/how-to-configure-jdeveloper-to-trust-an-ssl-certificate-and-fix-pkix-path-building-failed-when-connecting-to-an-https-url/) [2] I don't see why you have included a `netbeans` tag for this question if everything is fine in NetBeans. – skomisa Jan 29 '20 at 06:04
  • [1] Did not help, but thanks! [2] Just added the tag since I did get the code working in netbeans. Thought it might help if there are any experienced people who know either of the two IDE's. But I get what you mean, let me remove the tag – Shivam Puri Jan 30 '20 at 08:27

0 Answers0