using different keystore at runtime
Hi everybody,
I have the following problem:
I've written an application which is able to send different kind of requests to an https server by using the jakarta HTTPClient.
For the connection you can specify the url, the keystore and the corresponding password.
If you send a request for the first time it works fine but if you change the parameters(application is still running) an exception occures: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found (the keystore should be correct)
what could be the problem and how can I solve it
here is my code:
public void sendRequest() {
HttpClient client = null;
Header header = null;
int statusCode = -1;
try {
System.setProperty("javax.net.ssl.trustStore", this.szKeyStore);
System.setProperty("javax.net.ssl.trustStorePassword", this.szPassword);
System.out.println(System.getProperty("javax.net.ssl.trustStore"));
client = new HttpClient();
// Create a method instance.
post = new PostMethod(szUrl);
header = new Header("Content-Type", "text/xml");
post.addRequestHeader(header);
header = new Header("Charset", "ISO-8859-1");
post.addRequestHeader(header);
post.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
RequestEntity re = new StringRequestEntity(szRequest);
post.setRequestEntity(re);
try {
statusCode = client.executeMethod(post);
} catch (Exception exc) {
JOptionPane.showMessageDialog(listener, "not able to connect via HTTPS\n check settings");
System.err.print("Exception while sending request: " + exc.toString());
//post = null;
//header = null;
//client = null;
// return;
}
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: " + post.getStatusLine());
}
// Read the response body.
byte[] responseBody = post.getResponseBody();
// Deal with the response.
// Use caution: ensure correct character encoding and is not binary data
szResponse = new String(responseBody);
listener.requestReceived(szResponse);
post = null;
header = null;
client = null;
} catch (Exception e) {
System.err.println("Execption in sendRequest: " + e.getMessage());
e.printStackTrace();
} finally {
// Release the connection.
if (post != null) post.releaseConnection();
}
}
Thanks a lot

