• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 390
  • Last Modified:

URLConnection to HttpURLConnection causes classcastException

I'm having a problem that happens when I run my applet from a cabfile with a test cert, but not when I reference class files residing in a directory. (IE 6)

I am using an HttpURLConnection to read and write to a web server.  I create a URL object url to reference my page and then I execute HttpCnn = (HttpURLConnection)url.openConnection() to create the connection.

Works fine when the class files reside in a folder, but I get a java.lang.classCastException when I package the files in a cab file and sign with a test cert.

Any ideas about why this is happening?

thanks
0
garyz31
Asked:
garyz31
1 Solution
 
objectsCommented:
Because it's not using a HttpURLConnection.
You cannot assume that a HttpURLConnection is being used, it could be any class that extends URLConnection.
0
 
garyz31Author Commented:
So, how do I find out what is being used?  Can i control what is being used?
0
 
garyz31Author Commented:
And, why does packaging the class files in a cab file make a difference?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
garyz31Author Commented:
So, how do I find out what is being used?  Can i control what is being used?
0
 
garyz31Author Commented:
And, why does packaging the class files in a cab file make a difference?
0
 
Jan LouwerensCommented:
You can find out which class is being used by calling:

conn = url.openConnection();
String className = conn.getClass().getName();

I can't help you with the cab file difference, though...
0
 
objectsCommented:
No you can't control what is being used.

What exactly do you mean when you say:
"Works fine when the class files reside in a folder"
Are you still running it as applet?
0
 
objectsCommented:
I'd say your tryinmg to make an SSL connection which will use:
sun.plugin.protocol.jdk12.https.BrowserHttpsURLConnection

The actual classname will be mentioned in the exception.
0
 
garyz31Author Commented:
If I have put http explicitly in the url, is it possible that the connection is not a HttpURLConnection?

Let me check again to make sure it isn't some problem with referencing the cab file.  I'm running now as <object>.  What appeared to be happening was that the applet ran correctly when the class files were not contained in a cab file, but simply placed in a directory, but not when placed in a cab file.  I'll check again to be sure that I'm not making some other error.

If I have put http explicitly in the url, is it possible that the connection is not a HttpURLConnection?
0
 
objectsCommented:
> is it possible that the connection is not a HttpURLConnection?

Definitely, there is no guarantee what the class of the returned object will be except that it will be a subclass of URLConnection. And different objects will be returned by different JVM's.

So what class is actually being returned?
0
 
garyz31Author Commented:
So is it better to use only the methods of the URLConnection object along with a URLencoder, etc.

If I always have to write URLConnection code, of what value is HttpConnection?
0
 
objectsCommented:
> So is it better to use only the methods of the URLConnection object

Definitely.

> of what value is HttpConnection?

HttpURLConnection is simply a particular implementation of URLCOnnection.
0
 
heyhey_Commented:
in fact HttpURLConnection is abstract class ...
0
 
Venci75Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: objects
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now