Hi, I'm trying to make an HTTPS connection using
Test and Prod environment configuration.
jdk1.6.0_32
Linux
Jboss 5.1
In the Test environment I am able to get a connection properly. But in the Prod env I am getting the Exception
Caused by: java.lang.ClassCastException: com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnectionOldImpl cannot be cast to javax.net.ssl.HttpsURLConnection
the url.openConnection() returns the following objects in two envs.
Prod:
com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection
SIT:
sun.net.www.protocol.https.DelegateHttpsURLConnection
code :
import java.net.URL;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class WebAppAdaptor {
public static void main(String args[]) {
HttpsURLConnection con = null;
try {
URL url = new URL(PropertyManager.getProperty("https://www.google.com");
SSLContext ssl_ctx = SSLContext.getInstance("TLS");
TrustManager[] trust_mgr = get_trust_mgr();
ssl_ctx.init(null, // key manager
trust_mgr, // trust manager
new SecureRandom()); // random number generator
HttpsURLConnection.setDefaultSSLSocketFactory(ssl_ctx.getSocketFactory());
con = (HttpsURLConnection) url.openConnection();
}catch(Exception e){
e.printstacktrace();
}
}
}
how to avoid this exception. Is this some configuration i am missing.