SANJAY HALDAR
asked on
ClassCastException while trying to create HttpsURLConnection
Hi,
when I am trying to create httpsURLConnection like this:
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
I am getting ClassCastException but its working fine in standalone application
JDK:1.4
Weblogic: 8
CODE SAMPLE:
import java.net.URL;
import javax.net.ssl.HttpsURLConn ection;
-----
----
URL url;
try {
SSLContext ssl_ctx = SSLContext.getInstance("TL S");
TrustManager[] trust_mgr = get_trust_mgr();
ssl_ctx.init(null, trust_mgr,new SecureRandom()); // random number generator
HttpsURLConnection.setDefa ultSSLSock etFactory( ssl_ctx
.getSocketFactory());
url = new URL("https://.......");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
}catch(.....){
----
}
Please Help me to resolve this problem
Thanks you
when I am trying to create httpsURLConnection like this:
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
I am getting ClassCastException but its working fine in standalone application
JDK:1.4
Weblogic: 8
CODE SAMPLE:
import java.net.URL;
import javax.net.ssl.HttpsURLConn
-----
----
URL url;
try {
SSLContext ssl_ctx = SSLContext.getInstance("TL
TrustManager[] trust_mgr = get_trust_mgr();
ssl_ctx.init(null, trust_mgr,new SecureRandom()); // random number generator
HttpsURLConnection.setDefa
.getSocketFactory());
url = new URL("https://.......");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
}catch(.....){
----
}
Please Help me to resolve this problem
Thanks you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What are you doing with 'con' such that you need to know its type?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Two people showed you the reason for the problem and yet you couldn't even be bothered to respond ...
ASKER
I've requested that this question be closed as follows:
Accepted answer: 0 points for SANJAY HALDAR's comment #a40646513
for the following reason:
Provided solution worked out and solved the issue.
Thanks.
Accepted answer: 0 points for SANJAY HALDAR's comment #a40646513
for the following reason:
Provided solution worked out and solved the issue.
Thanks.
Two people showed you the reason for the problem and yet you couldn't even be bothered to respond ...
ASKER
The question was well responded that we got the solution our self, what does the last comment of CEHJ means?
ASKER
ok
ASKER
I am able to resolve this. Please find updated code:
import java.net.URL;
import javax.net.ssl.HttpsURLConn
-----
----
URL url;
try {
SSLContext ssl_ctx = SSLContext.getInstance("TL
TrustManager[] trust_mgr = get_trust_mgr();
ssl_ctx.init(null, trust_mgr,new SecureRandom()); // random number generator
HttpsURLConnection.setDefa
.getSocketFactory());
.getSocketFactory());
//url = new java.net.URL("https://......");
url = new URL(null,"https://....",new sun.net.www.protocol.https.Handler());
URI uri=null;
try {
uri = new URI(url.getProtocol(),url.
} catch (URISyntaxException e) {
e.printStackTrace();
}
url = uri.toURL();
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
}catch(.....){
----
}
Regards,
Ajaya Samanta