Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpClient and PostMethod - Https site

843811Jun 27 2007 — edited Jun 28 2007
Hi All,
I am using org.apache.commons.httpclient.HttpClient and org.apache.commons.httpclient.methods.PostMethod to post a request to https site.

my requirement is i need to read the url from property file, add some sensitive information in the HttpHeader and post the request to the URL read from the property.

if I try to post to a https site, I keep getting "javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found"

when I tried setting some system propery as given below

System.setProperty("javax.net.ssl.trustStore",cert);
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

i got a different error saying " Keystore tampered or invalid password" and sometimes "java.net.SocketException: Default SSL context init failed: Invalid keystore format"

pls help.

Iam using weblogic server.


here is my code.

System.setProperty("javax.net.ssl.trustStore","C:/progra~1/Java/j2re1.4.2_12/lib/security/cacerts");
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

//setting the security details ends



String nextUrl="";
if(request.getParameter("goto") != null && ((String)request.getParameter("goto").trim()).length() > 0) {
nextUrl = (String)request.getParameter("goto").trim();
} else {
nextUrl = AccessMgrPropertyManager.getProperty("default.waldo.landing.url");
}

System.out.println("url " + nextUrl);
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(nextUrl);

postMethod.addRequestHeader("AM_MOBILE_NUMBER",paramUsrName);
postMethod.addRequestHeader("AM_USER_NAME",getAlias(paramUsrName));
postMethod.addRequestHeader("AM_ACCOUNT_NUMBER",paramAcctNum);

client.executeMethod(postMethod);

int code = postMethod.getStatusCode();
byte bytes[] = postMethod.getResponseBody();
response.getOutputStream().write(bytes);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2007
Added on Jun 27 2007
2 comments
616 views