jQuery in Action, 3rd edition
The moose likes Sockets and Internet Protocols and the fly likes HttpsURLConnection ClassCastException - Solution Does Not Work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "HttpsURLConnection ClassCastException - Solution Does Not Work" Watch "HttpsURLConnection ClassCastException - Solution Does Not Work" New topic

HttpsURLConnection ClassCastException - Solution Does Not Work

Greg Lafrance

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];

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

URL url = new URL(url_string);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection)(url.openConnection());
catch(Exception e){
System.out.println("Exception occurred.");
System.exit( 0 );
Here is the output:

Exception occurred.

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 !

I agree. Here's the link: http://aspose.com/file-tools
subject: HttpsURLConnection ClassCastException - Solution Does Not Work
It's not a secret anymore!