Resolving PKIX path building failed Error?

Edit :- Tried to format the question and accepted answer in more presentable way at mine Blog

Here is the original issue.

I am getting this error:

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

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

I am using Tomcat 6 as webserver. I have two HTTPS web applications installed on different Tomcats on different ports but on the same machine. Say App1(port 8443) and App2(port 443). App1 connects to App2. When App1 connects to App2 I get the above error. I know this is a very common error so came across many solutions on different forums and sites. I have the below entry in server.xml of both Tomcats:


Every site says the same reason that certificate given by app2 is not in the trusted store of app1 jvm. This seems to be true also when I tried to hit the same URL in IE browser, it works (with warming, There is a problem with this web site's security certificate. Here I say continue to this website). But when same URL is hit by Java client (in my case) I get the above error. So to put it in the truststore I tried these three options:


System.setProperty("", "C:/.keystore");
System.setProperty("", "changeit");

Option2 Setting below in environment variable

CATALINA_OPTS -- param name\.keystore ---param value

Option3 Setting below in environment variable

JAVA_OPTS -- param name\.keystore ---param value

But nothing worked .

What at last worked is executing the Java approach suggested in How to handle invalid SSL certificates with Apache HttpClient? by Pascal Thivent i.e. executing the program InstallCert.

But this approach is fine for devbox setup but I can not use it at production environment.

I am wondering why three approaches mentioned above did not work when I have mentioned the same values in server.xml of app2 server and same values in truststore by setting

System.setProperty("", "C:/.keystore") and System.setProperty("", "changeit");

in app1 program.

For more information this is how I am making the connection:

URL url = new URL(urlStr);

URLConnection conn = url.openConnection();

if (conn instanceof HttpsURLConnection) {

  HttpsURLConnection conn1 = (HttpsURLConnection) url.openConnection();

  conn1.setHostnameVerifier(new HostnameVerifier() {
    public boolean verify(String hostname, SSLSession session) {
      return true;


Read more here:

Content Attribution

This content was originally published by M Sach at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: