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 <site> - <ip> 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());
}
}