Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

URLConnection to HttpURLConnection causes classcastException

Posted on 2002-04-30
15
Medium Priority
?
389 Views
Last Modified: 2008-02-01
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
Comment
Question by:garyz31
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
15 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6982347
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
 
LVL 1

Author Comment

by:garyz31
ID: 6982535
So, how do I find out what is being used?  Can i control what is being used?
0
 
LVL 1

Author Comment

by:garyz31
ID: 6982542
And, why does packaging the class files in a cab file make a difference?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:garyz31
ID: 6982545
So, how do I find out what is being used?  Can i control what is being used?
0
 
LVL 1

Author Comment

by:garyz31
ID: 6982546
And, why does packaging the class files in a cab file make a difference?
0
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 6982600
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
 
LVL 92

Expert Comment

by:objects
ID: 6982601
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
 
LVL 92

Expert Comment

by:objects
ID: 6982603
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
 
LVL 1

Author Comment

by:garyz31
ID: 6982620
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
 
LVL 92

Expert Comment

by:objects
ID: 6982629
> 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
 
LVL 1

Author Comment

by:garyz31
ID: 6983249
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
 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 6984437
> 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
 
LVL 16

Expert Comment

by:heyhey_
ID: 6985888
in fact HttpURLConnection is abstract class ...
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7992781
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
 

Expert Comment

by:SpideyMod
ID: 8048342
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question