'Accept signed SSL Certificate on non default port

I am trying to connect to a web server using a java client and get the following exception:

javax.ejb.EJBTransactionRolledbackException: RESTEASY004655: Unable to invoke request: javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

The server uses a signed Certificate from a CA that my machine trusts. I am assuming that the problem lies in the servers address, which uses a port that differs from https default. E.g.: "https://someserver.net:11011"

How can i get my java client to accept certificates on any port?

Here's how i currently create a client and attempt to create a connection:

javax.ws.rs.client.Client client = ClientBuilder.newClient();
URI uri = new URL("https://someserver.net:11011").toURI();
Response response = client.target(uri).request().get();

I tried to connect on the default port, which worked:

Response testResponse = client.target("https://someserver.net").request().get(); // works
Response testResponse2 = client.target("https://someserver.net:443").request().get(); // works
Response testResponse3 = client.target("https://someserver.net:11011").request().get(); // throws


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source