I'm trying to post data to a payment gateway website with the following jsp code:
System.setProperty("javax.net.ssl.trustStore ","C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\security\\cacerts");\
System.setProperty("javax.net.ssl.trustStorePassword","changeit");
URL server = new URL("https://...");
HttpURLConnection connection = (HttpURLConnection) server.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("content-type","application/x-www-form-urlencoded");
connection.connect();
OutputStream os = connection.getOutputStream();
os.write(checkRequestByte);
os.close();
I've added the .cer file to java keystore with this command:
keytool -importcert -file "path/certFile.cer" -keystore "Java/jre7/lib/security/cacerts" -alias "Alias"
I also tried this one:
keytool -importcert -file "path/certFile.cer" -keystore "Java/jdk1.7.0_17/jre/lib/security/cacerts" -alias "Alias"
and in both cases I've got this message:
Certificate was added to keystore
But when I run it and the page opens, I get the following error:
org.apache.jasper.JasperException: An exception occurred processing JSP page /process.jsp at line 36
33: connection.setDoOutput(true);
34: connection.setRequestProperty("content-type","application/x-www-form-urlencoded");
35:
36: connection.connect();
37:
38: OutputStream os = connection.getOutputStream();
39: os.write(checkRequestByte);
javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty ...
I'm confused, I've never faced it before .... I appreciate your comments
The solution was so easy :D, I've restarted the tomcat and now it works like a charm ;)