I have created a web service in Java which posts data to another web service. This requires SSL certificates for authentication. This web service is running fine on Tomcat, but when I deploy the same code on GlassFish 3.0.1 server, I am getting javax.net.ssl.SSLHandshakeException
: Received fatal alert: unknown ca exception.
I have imported the certificate to glassfish trustStore using keytool. The required certificates are provided by client.
My code:
System.setProperty("javax.net.ssl.keyStoreType" , "pkcs12");
System.setProperty("javax.net.ssl.keyStore", applicationRootDirPath + "clientCert.p12");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
System.setProperty("javax.net.ssl.trustStoreType", "jks");
System.setProperty("javax.net.ssl.trustStore", "path of glass fish truststore");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
try {
url = new URL(serverUrl);
urlConn = url.openConnection();
urlConn.setDoOutput(true);
urlConn.setRequestMethod("POST");
urlConn.setAllowUserInteraction(false);
urlConn.setUseCaches(false);
urlConn.setRequestProperty("Content-type", "text/xml; charset=utf-8");
urlConn.setRequestProperty("Content-Length", new Integer(xml.length()).toString());
try {
writer = new OutputStreamWriter(urlConn.getOutputStream(), "UTF-8");
writer.write(xmlData);
} finally {
if (writer != null) {
writer.close();
}
}
trace += "\n urlConn.getInputStream()";
in = urlConn.getInputStream();
}