Gopal Gopal - 2 months ago 11x
Java Question PKIX path building failed

i am using java application to check the url connrectivity, for the some url (internal) application url, i am getting 200 (success), for the others i am getting the below exception.

but if i manually connect to the below url , no issues on that, do i need pki certificates.
need your help.

URL Link response code (200), good 200 OK OK

URL link response exception

Exception message: PKIX path building failed: unable to find valid certification path to requested target

Logs PKIX path building failed: unable to find valid certification path to requested target at at at at at at

Program Source code"testing the httpurlconnection for url:" + strUrl );

url = new URL(strUrl);
urlConn = (HttpURLConnection) url.openConnection();

if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK )
{"url http connection is sucessfull");

//append the response status
urlResponseStatus = "OK";
{"url http connection failure, response code:" + urlConn.getResponseCode());

//append the response status
urlResponseStatus = "NOT OK";

urlResponseCode = urlConn.getResponseCode();
urlResponseMessage = urlConn.getResponseMessage();


The SSL certificate isn't trusted by Java. The certificate may be self-signed, or it may be signed by a CA (Certificate Authority) whose root certificate is not in the Java certificate store.

Add the code to trust the certificate provided by host. Import the certificate before consuming the URL.

Just add below code to trust the certificate

TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
    public[] getAcceptedIssuers() {
        return null;
    public void checkClientTrusted([] certs, String authType) {
    public void checkServerTrusted([] certs, String authType) {

   try {
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, new;
    } catch (Exception e) {

// Add your code below