| Author |
HttpsURLConnection ClassCastException - Solution Does Not Work
|
Greg Lafrance
Greenhorn
Joined: Mar 09, 2004
Posts: 1
|
|
I've seen several posts about using the HttpsURLConnection class and getting a ClassCastException. I've seen many suggested solutions related to backward compatibility. Here is my situation that is not working, and I ask for advice on how to proceed. Here is my code: import java.io.*; import java.net.*; import javax.net.ssl.*; import java.util.Properties; import java.security.*; public class SSL { public static void main( String args[ ] ) throws IOException { String url_string = args[0]; System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol"); Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); try{ URL url = new URL(url_string); System.out.println(url.openConnection().toString()); HttpsURLConnection httpsURLConnection = (HttpsURLConnection)(url.openConnection()); } catch(Exception e){ System.out.println("Exception occurred."); System.out.println(e); } System.exit( 0 ); } } -------------------------- Here is the output: com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection: Exception occurred. java.lang.ClassCastException When I execute java -version I get this: java version "1.4.2_06" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03) Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode) -------------------------------------------- Here is the explanation I've seen quite often: HttpsURLConnection migrated to javax.net.ssl from com.sun.net.ssl for 1.4. You're probably getting an instance of this class (javax.net.ssl) instead of what you originally compiled under (com.sun.net.ssl. But I am compiling using java 1.4.2, so why am I getting a com.sun.net.ssl.internal.www.protocol.https.DelegateHttpsURLConnection It seems like I am locked out of using HTTPS in Java. Do I need to reinstall my JDK? Any help would be greatly appreciated ! Thanks, Greg
|
 |
 |
|
|
subject: HttpsURLConnection ClassCastException - Solution Does Not Work
|
|
|