• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpsURLConnection ClassCastException - Solution Does Not Work

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic