954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Connecting to HTTPS - unable to find valid certification path to requested target

Hello everyone,

I am using the code below. It is working when I used this in Eclipse. What I did is to place the generated keystore from the InstallCert.class ( http://blogs.sun.com/andreas/resource/InstallCert.java ) to the latest JRE in the Program Files>Java

But when I deployed this class in the Tomcat/Bea its searching I am receiving this errors:

BEA Weblogic - HttpsConnection Exception: [Security:090477]Certificate chain received from - was not trusted causing SSL handshake failure.

TOMCAT: HttpsConnection Exception: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

Can you give me an idea on how to resolve this issue? Your replies are greatly appreciated.

Looking forward to your replies.

Thanks in Advance

import java.io.*;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;


public class HttpsConnection {
	
	public static void ConnectToHttps(String HttpsAddress,String FileDestination,int upload){
		try {
			HttpsConnection.ConnectToSSL(HttpsAddress,FileDestination,0);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("HttpsConnection Exception: " + e.getMessage());
			e.printStackTrace();
		}
	}
	
    public static void ConnectToSSL(String HttpsAddress,String FileDestination,int upload) throws Exception {
    	
		// Dynamic registration of JSSE provider
		java.security.Security.addProvider(
	          new com.sun.net.ssl.internal.ssl.Provider());
	
	    // Need to be set
	    	  System.setProperty(
	            "java.protocol.handler.pkgs",
	            "com.sun.net.ssl.internal.www.protocol");
	
	    // Install Authenticator
	    Authenticator.setDefault (new PasswordAuthenticator());
	
		URL url = new URL(HttpsAddress);
		
		BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
	
		String InputLine;
		
		if (upload==1){
			UploadDataFile.FileUpload(HttpsAddress,FileDestination);
		}else{
			int i = 0;
			while ((InputLine = in.readLine()) != null){
			    if (i==7){
			    	HttpsScanFlatFile.ScanHttpsFile(InputLine,HttpsAddress,FileDestination);
			    }
			    i++;
			}
			in.close();
		}
    	}
	}

	class PasswordAuthenticator extends Authenticator {
		public void ExperianCreditAuthenticator() {
		}

		protected PasswordAuthentication getPasswordAuthentication() {
    	System.out.println("Connecting to HTTPS Site...");
    	return new PasswordAuthentication("Username","Password".toCharArray());
    }
}
jamojo
Light Poster
32 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Any suggestions or ideas please?

jamojo
Light Poster
32 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

i get the same problem! you need install the certificate in your jdk./
such as , i use the keytool utility to generate the *.cer file and import it
to my jdk.but i still get the mistake ,still work hard!

xiaocong
Newbie Poster
1 post since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You