Re: Objects in Vector are loosing type

2001-05-04 Thread Milt Epstein

On Fri, 4 May 2001, Endre Stølsvik wrote:

> On Thu, 3 May 2001, Milt Epstein wrote:
>
> | Maybe your app could use some reorganizing.
>
> Yeah, maybe, Milt.
>
> Why don't you ask the developers, then? I actually believe that all
> things I said in those mails about reloading in TC3.x and TC4 are
> correct.

Because I have no reason to.  I have had success with reloading with
3.2.1 (and so have others, as reported on the list) -- so I don't
think all your comments were accurate.  I believe that includes
changes to auxiliary, non-servlet classes, but I don't recall exactly.
Next time I have occasion to try, I'll report the results (if I
remember :-).  I have heard that reloading with 4.X is more
problematic (and may not work at all), but I haven't tried it yet
myself.

I did at one time have problems with ClassCastExceptions (and similar,
having to do with native code), but with a little bit of reorganizing,
I was able to get around it.  (Admittedly my apps are not the most
complex, nor do I currently make extensive use of objects in sessions.)


> And the reason for me having to restart every time is that I
> basically have made a "server" running "on top of tomcat", and
> there's basically only 3 servlets running, but with lots of helper
> classes and stuff around.
>
> The reason for _always_ getting a ClassCastException is that I have
> all my user information stored in a User object. This won't ever
> reload (that is, serialize/deserialize, or in some other way being
> "cast" over to the new classloader), and when i retrieve it from the
> HttpSession, it's _always_ ClassCastException'ing.
>
> I'm not the only one making such "complicated" apps. The exact same
> story about the "User object" have been mentioned a couple of times
> on this list.

Likely true.  And I'm sure if it was happening to me (and it may in
the future :-), I'd be annoyed as well.  And, FWIW, servlet reloading
seems a more straightforward thing that should be working -- handling
all the ClassCastExceptions seems a more complex issue (although if
what you say is true, and is the norm, having plain servlet reloading
without handling the ClassCastException issues won't do some people
any good).

The thing that bothered me is that you were ranting and raving about
the problems without a deep technical understanding of the issues,
without appreciation for what the tomcat developers have done, and
without offering to contribute.  Tomcat is not a commercial product
where you should be expecting (and/or demanding) more.  The developers
may be sticking to more "core" features that they need to get working
to implement the spec (I believe reloading is not part of the spec).

Have you tried checking out the tomcat-dev list to see what they have
to say about it there?  Seems that would be more constructive.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]




Re: Objects in Vector are loosing type

2001-05-04 Thread Bob Davison



On 04/05/2001 07:38:57 ?iso-8859-1?Q?Endre_St=F8lsvik?= wrote:
> On Thu, 3 May 2001, Milt Epstein wrote:
>
> | Maybe your app could use some reorganizing.
>
> Yeah, maybe, Milt.
>
> Why don't you ask the developers, then? I actually believe that all things
> I said in those mails about reloading in TC3.x and TC4 are correct.
>
> And the reason for me having to restart every time is that I basically
> have made a "server" running "on top of tomcat", and there's basically
> only 3 servlets running, but with lots of helper classes and stuff around.
>
> The reason for _always_ getting a ClassCastException is that I have all my
> user information stored in a User object. This won't ever reload (that is,
> serialize/deserialize, or in some other way being "cast" over to the new
> classloader), and when i retrieve it from the HttpSession, it's _always_
> ClassCastException'ing.
>
> I'm not the only one making such "complicated" apps. The exact same story
> about the "User object" have been mentioned a couple of times on this
> list.
>
> And that's how it is.
>
> ;)
>
>
> --
> Mvh,
> Endre
>

I just started using Tomcat (3.2.1) the other day for development and found the
"nearly but not quite" state of the servlet reloading to be frustrating so I had
a look at the code and have come up with a few hacks that seem to get it working
for me, session objects as well.  The main problem seems to be that class
reloading is being handled on the servlet level rather than the context level.

I am sure that it is not robust and certainly doesn't take into account
destroying a servlet on one thread while it is use on another, but it is fine
for development.  Try it out and let me know if it helps with those
ClassCastException blues :-)

Sorry about the code folks, I know that this isn't tomcat-dev but I am not a
tomcat developer and there seem to be a few people on this list suffering with
the same problem.


File: org/apache/tomcat/core/ContextManager.java
method internalService(), just before the line that reads

if( req.getWrapper() == null ) {

add

req.getContext().handleReload(req);

--

File: org/apache/tomcat/core/Context.java
new method

void handleReload(Request req) {
if( reloadable
&& servletL != null
&& servletL.shouldReload() ) {
Enumeration e = servlets.elements();
while( e.hasMoreElements() ) {
try {
ServletWrapper wrapper = (ServletWrapper)e.nextElement();
if( !wrapper.isInternal() ) {
wrapper.destroy();
}
} catch(Exception ex) {
log("Error in destroy: ", ex);
}
}
servletL.reload();
try {
contextM.doReload(req, this);
} catch(TomcatException te) {
log("Error in reload", te);
}
}
}



File: org/apache/tomcat/core/ServletWrapper.java

method doDestroy(), at the end add:

servlet = null;
servletClass = null;


method handleReload(), comment out everything (beware there are already /* */
comments in there...)


.../Bob


-
Visit our Internet site at http://www.reuters.com

Any views expressed in this message are those of  the  individual
sender,  except  where  the sender specifically states them to be
the views of Reuters Ltd.



Re: Objects in Vector are loosing type

2001-05-03 Thread Endre Stølsvik

On Thu, 3 May 2001, Milt Epstein wrote:

| Maybe your app could use some reorganizing.

Yeah, maybe, Milt.

Why don't you ask the developers, then? I actually believe that all things
I said in those mails about reloading in TC3.x and TC4 are correct.

And the reason for me having to restart every time is that I basically
have made a "server" running "on top of tomcat", and there's basically
only 3 servlets running, but with lots of helper classes and stuff around.

The reason for _always_ getting a ClassCastException is that I have all my
user information stored in a User object. This won't ever reload (that is,
serialize/deserialize, or in some other way being "cast" over to the new
classloader), and when i retrieve it from the HttpSession, it's _always_
ClassCastException'ing.

I'm not the only one making such "complicated" apps. The exact same story
about the "User object" have been mentioned a couple of times on this
list.

And that's how it is.

;)


-- 
Mvh,
Endre




Re: Objects in Vector are loosing type - classload problems

2001-05-03 Thread David Wall

> I have to restart tomcat each and every time I make one single change to
> _anyting_ of my code. This is the most time consuming part of developing
> on Tomcat, I feel. (How's Jetty doing, btw??)

Of course, you are free to use any implementation, or you could even submit
an example of how to fix it.

Personally, I think the classloader scheme itself is rather broken, which
apparently is why there are so many problems.  It seems absurd to me that
the classloader "hierarchy" only allows you to go UP, but now down.  We've
seen this problem so many times, such as when using JMS and wanting to put
the JMS files in a base classloader (like on the CLASSPATH) or JCE/JNDI code
that may be loaded in the initial classloaders because they are defined in
lib/ext or in java.security properties file.  If you call those libraries
and they need to serialize your object or anything, they can't do it because
your object was probably created using the classloader created by the Tomcat
context.  I can see that the first check for a class should be in the
current classloader, then it can move its way up the hierarchy to the top
level classloader, but if it's not found, it would be great if it could then
start to look DOWN the hierarchy to see if it can find it.  I suspect
there's some odd security reason not to do this, but it seems unlikely since
you first give the system the ability to look up the chain and only go down
if it's not found.

But Tomcat 4.0 was supposed to fix things, but my quick test shows there are
still problems keeping the classloaders all separated.  When I run two
virtual host contexts in the same Tomcat instance, and both contexts make
use of JMS, JNDI, JDBC and JCE, there's always a conflict that makes it not
work (like static/singleton instances being created under one context being
"reused" in the other context).  By putting them in separate Tomcats,
everything works.  So, there's either a longstanding bug in the Tomcat 3.2
and 4.0 classloader scheme, or there's a basic conflict in the behavior of
classloaders that is really not workable.  This probably gets even worse in
EJB worlds, but I'm not sure.

David




Re: Objects in Vector are loosing type

2001-05-03 Thread Milt Epstein

On Thu, 3 May 2001, Endre Stølsvik wrote:

> On Wed, 2 May 2001, Joel Parramore wrote:
>
> | Well, Endre, comments such as "classloading is totally fucked",
> | while having a nice kewl sound-bite quality, really don't explain
> | what is going on too well to someone who hasn't encountered the
> | problem before.
>
> It's just that it kind of annoys me. It's definately an huge itch,
> but I don't have the time to scratch it. Stupid thing to say, but
> what's annoying is that it's not quite recongized by the developers
> as a problem, which truly puzzles me..

How do you know they don't consider it a problem?  Maybe it's not as
easy to solve as you think it is.  Or maybe there are other things
they consider higher priority.  Maybe you can contribute some time and
code the solution yourself.


> I have to restart tomcat each and every time I make one single
> change to _anyting_ of my code. This is the most time consuming part
> of developing on Tomcat, I feel. (How's Jetty doing, btw??)

*Every* time, for any change?  That doesn't sound right.  Servlet
reloading works for me (I'm using Tomcat 3.2.1).  The
classloader/class cast issue is different than simple reloading of
servlets.


> Also, forgot to mention, the reloader doesn't notice if any _other_
> classes have changed, e.g. your User object or whatever. Only the
> directly affected Servlet, and only the first one hit, will get
> reloaded.
[ ... ]

I don't believe this is correct either -- for classes that are in the
servlet directories (as opposed to the classpath), I believe reloading
works.

Maybe your app could use some reorganizing.

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]




Re: Objects in Vector are loosing type

2001-05-03 Thread Endre Stølsvik

On Wed, 2 May 2001, Joel Parramore wrote:

|
| Well, Endre, comments such as "classloading is totally fucked", while having
| a nice kewl sound-bite quality, really don't explain what is going on too
| well to someone who hasn't encountered the problem before.

It's just that it kind of annoys me. It's definately an huge itch, but I
don't have the time to scratch it. Stupid thing to say, but what's
annoying is that it's not quite recongized by the developers as a problem,
which truly puzzles me..

I have to restart tomcat each and every time I make one single change to
_anyting_ of my code. This is the most time consuming part of developing
on Tomcat, I feel. (How's Jetty doing, btw??)

Also, forgot to mention, the reloader doesn't notice if any _other_
classes have changed, e.g. your User object or whatever. Only the directly
affected Servlet, and only the first one hit, will get reloaded.

If not totally fucked, it's definately pretty messed up..!

;)

Endre




RE: Objects in Vector are loosing type

2001-05-02 Thread Joel Parramore


Well, Endre, comments such as "classloading is totally fucked", while having
a nice kewl sound-bite quality, really don't explain what is going on too
well to someone who hasn't encountered the problem before.

Speaking for myself, I had not seen any sort of explanation on the mailing
list before (haven't done an extensive archive check, admittedly, esp. on
the developer list), nor in the Jakarta FAQs.  Another poster commented that
this item keeps popping up; perhaps making this into a FAQ item would insure
that questions and comments on the topic would assist in preventing this
question from (re)occuring.  (Perhaps a weekly posting of FAQ items would
help as well, but that's another issue.)

Thanks for the explanation, though.  And your English is just fine. :-)

Regards,
Joel Parramore



> -Original Message-
> From: Endre Stolsvik [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 02, 2001 2:53 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Objects in Vector are loosing type
>
>
> On Mon, 30 Apr 2001, Joel Parramore wrote:
>
> |
> | Can or has or will someone work up a slightly more technical explanation
> | than
> |
> | > It's because tomcat's reloading are totally fucked.
>
> Well, Joel, it's because tomcat3x doesn't do this:
>
> a) stop the webapp
> b) destroys all servlets
> c) serializes all the Sessions
> d) throws away the ClassLoader for this webapp
> e) cleans away the webapp from all "caches" in the system
> f) restarts the whole webapp, as if for the first time, making a new
> ClassLoader for it.
> g) deserializes all the Sessions (now with the new ClassLoader)
> h) lets the users use the system again
>
> (Which is apparently how tomcat 4 should do it, but it never did for me.
> But I am doing a very weird ting according to the developers, I am running
> tomcat away from it's installation directory, and this is _not_
> supported.)
>
> What tomcat3x does, is to just ditches the ClassLoader and reloads the
> _first_ servlet you hit after a refresh of the .class-files timestamps.
> Even if you recompile your whole webapp, tomcat just reloads the first
> servlet a user hits. This means that all the other Servlets are still
> "cached" using the old ClassLoader, and you actually get two instanses of
> your webapp, all the old Session objects and all the other Servlets loaded
> with the old ClassLoader, while all the new Session objects and the one,
> first hit Servlet with the new ClassLoader.
>   It doesn't, as mentioned, do anything about the Session variables, and
> therefore you often get ClassCastExceptions when you try to handle and
> cast objects gotten from the Session within the one, new reloaded servlet.
> This because _it's_ version of the Class you try to cast the object gotten
> from the Session to, is loaded with the new ClassLoader, while the object
> you try to cast is loaded with the old. This is not considered the same
> Classes, and you get ClassCastException.
>
> This is so very, very wrong, and therefore I'd say it's "totally fucked"..
> This has been pointed out a whole bunch of times.
>
> Better? I'm not that fantastic with English, hope you excuse that, Joel.
>
> Endre.




Re: Objects in Vector are loosing type

2001-05-01 Thread Endre Stølsvik

On Mon, 30 Apr 2001, Joel Parramore wrote:

|
| Can or has or will someone work up a slightly more technical explanation
| than
|
| > It's because tomcat's reloading are totally fucked.

Well, Joel, it's because tomcat3x doesn't do this:

a) stop the webapp
b) destroys all servlets
c) serializes all the Sessions
d) throws away the ClassLoader for this webapp
e) cleans away the webapp from all "caches" in the system
f) restarts the whole webapp, as if for the first time, making a new
ClassLoader for it.
g) deserializes all the Sessions (now with the new ClassLoader)
h) lets the users use the system again

(Which is apparently how tomcat 4 should do it, but it never did for me.
But I am doing a very weird ting according to the developers, I am running
tomcat away from it's installation directory, and this is _not_
supported.)

What tomcat3x does, is to just ditches the ClassLoader and reloads the
_first_ servlet you hit after a refresh of the .class-files timestamps.
Even if you recompile your whole webapp, tomcat just reloads the first
servlet a user hits. This means that all the other Servlets are still
"cached" using the old ClassLoader, and you actually get two instanses of
your webapp, all the old Session objects and all the other Servlets loaded
with the old ClassLoader, while all the new Session objects and the one,
first hit Servlet with the new ClassLoader.
  It doesn't, as mentioned, do anything about the Session variables, and
therefore you often get ClassCastExceptions when you try to handle and
cast objects gotten from the Session within the one, new reloaded servlet.
This because _it's_ version of the Class you try to cast the object gotten
from the Session to, is loaded with the new ClassLoader, while the object
you try to cast is loaded with the old. This is not considered the same
Classes, and you get ClassCastException.

This is so very, very wrong, and therefore I'd say it's "totally fucked"..
This has been pointed out a whole bunch of times.

Better? I'm not that fantastic with English, hope you excuse that, Joel.

Endre.




RE: Objects in Vector are loosing type

2001-04-30 Thread Cory Hubert

Look at the thread "Weird Casting Problem. Tomcat Bug?" for a more
technical explanation.   No disrespect but I think we've been repeating
ourselves.Someone needs to fix it or put it in the FAQ.

-Original Message-
From: Joel Parramore [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 30, 2001 11:42 AM
To: [EMAIL PROTECTED]
Subject: RE: Objects in Vector are loosing type



Can or has or will someone work up a slightly more technical explanation
than

> It's because tomcat's reloading are totally fucked.

???

Regards,
Joel Parramore


> -Original Message-
> From: Cory Hubert [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 30, 2001 11:36 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Objects in Vector are loosing type
>
>
>   We should put this in the FAQ.   This issue pops up Often.
>
> -Original Message-
> From: Endre Stolsvik [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 30, 2001 4:59 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Objects in Vector are loosing type
>
>
> On Fri, 27 Apr 2001, Ivan wrote:
>
> | thank you very much for your reply
> |
> | I turned off my computer and tried it again a few hours later and it
> seemed
> | to work, then i made changes and then the second servlet wasnt able to
> cast
> | back to CHyperlink again.  after putting the code back the way I had it,
> it
> | still wouldnt work.
>
> You're having the "reload problem", and each time you restart tomcat,
> everything will work for you.
>
> It's because tomcat's reloading are totally fucked. This goes for all
> versions, but 4 should apparently have som new stuff, which basically
> reboots the whole webapp and serializes/deserializes everything in users'
> sessions if anything changes..
>
>
>
> --
> Mvh,
> Endre




RE: Objects in Vector are loosing type

2001-04-30 Thread Joel Parramore


Can or has or will someone work up a slightly more technical explanation
than

> It's because tomcat's reloading are totally fucked.

???

Regards,
Joel Parramore


> -Original Message-
> From: Cory Hubert [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 30, 2001 11:36 AM
> To: [EMAIL PROTECTED]
> Subject: RE: Objects in Vector are loosing type
>
>
>   We should put this in the FAQ.   This issue pops up Often.
>
> -Original Message-
> From: Endre Stolsvik [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 30, 2001 4:59 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Objects in Vector are loosing type
>
>
> On Fri, 27 Apr 2001, Ivan wrote:
>
> | thank you very much for your reply
> |
> | I turned off my computer and tried it again a few hours later and it
> seemed
> | to work, then i made changes and then the second servlet wasnt able to
> cast
> | back to CHyperlink again.  after putting the code back the way I had it,
> it
> | still wouldnt work.
>
> You're having the "reload problem", and each time you restart tomcat,
> everything will work for you.
>
> It's because tomcat's reloading are totally fucked. This goes for all
> versions, but 4 should apparently have som new stuff, which basically
> reboots the whole webapp and serializes/deserializes everything in users'
> sessions if anything changes..
>
>
>
> --
> Mvh,
> Endre




RE: Objects in Vector are loosing type

2001-04-30 Thread Cory Hubert

We should put this in the FAQ.   This issue pops up Often.

-Original Message-
From: Endre Stolsvik [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 30, 2001 4:59 AM
To: [EMAIL PROTECTED]
Subject: Re: Objects in Vector are loosing type


On Fri, 27 Apr 2001, Ivan wrote:

| thank you very much for your reply
|
| I turned off my computer and tried it again a few hours later and it
seemed
| to work, then i made changes and then the second servlet wasnt able to
cast
| back to CHyperlink again.  after putting the code back the way I had it,
it
| still wouldnt work.

You're having the "reload problem", and each time you restart tomcat,
everything will work for you.

It's because tomcat's reloading are totally fucked. This goes for all
versions, but 4 should apparently have som new stuff, which basically
reboots the whole webapp and serializes/deserializes everything in users'
sessions if anything changes..



--
Mvh,
Endre




Re: Objects in Vector are loosing type

2001-04-30 Thread Endre Stølsvik

On Fri, 27 Apr 2001, Ivan wrote:

| thank you very much for your reply
|
| I turned off my computer and tried it again a few hours later and it seemed
| to work, then i made changes and then the second servlet wasnt able to cast
| back to CHyperlink again.  after putting the code back the way I had it, it
| still wouldnt work.

You're having the "reload problem", and each time you restart tomcat,
everything will work for you.

It's because tomcat's reloading are totally fucked. This goes for all
versions, but 4 should apparently have som new stuff, which basically
reboots the whole webapp and serializes/deserializes everything in users'
sessions if anything changes..



-- 
Mvh,
Endre




Re: Objects in Vector are loosing type

2001-04-28 Thread Ivan

OK after several days of head banging on this problem, I found the problem
thanks to the tips from you guys.

I was putting CHyperlink objects into a vector which was in a session and
than using another servlet to get the CHyperlink objects out of the vector.
However i was getting run time errors when i tried to cast the Objects back
to CHyperlinks.

What I discovered was that when I restarted tomcat everything was working,
and then i made changes in my servlets and hit Rebuild all in JBuilder.
Then i got the error again when trying to cast.

What i think happened was because I hit rebuild all a new version of
CHyperlink was being generated and then when attempting to cast the object
that was still sitting in the Vector it failed because the JVM must have
checked the signature on the object in the Vector vs the CHyperlink class i
just rebuilt.

As long as i restart the server after making changes to the classes
everything is working fine.

Does this result make sense to you all?

Thanks again,
Ivan

- Original Message -
From: "Filip Hanik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Saturday, April 28, 2001 2:28 PM
Subject: RE: Objects in Vector are loosing type


> > So are you saying it is by chance if a different class loader loads each
> > servlet and this can effect the casting?
>
> yes, the same class loaded by different class loaders, is not considered
the
> same class.
>
> ie, you can't cast them
>
> ~
> Namaste - I bow to the divine in you
> ~
> Filip Hanik
> Software Architect
> [EMAIL PROTECTED]
> www.filip.net
>




RE: Objects in Vector are loosing type

2001-04-28 Thread Filip Hanik

> So are you saying it is by chance if a different class loader loads each
> servlet and this can effect the casting?

yes, the same class loaded by different class loaders, is not considered the
same class.

ie, you can't cast them

~
Namaste - I bow to the divine in you
~
Filip Hanik
Software Architect
[EMAIL PROTECTED]
www.filip.net




Re: Objects in Vector are loosing type

2001-04-27 Thread Ivan



Thank you for your reply
 
It returns novick.urlprog.CHyperlink  which is 
the name of the class, however when i do 
if (instanceof novick.urlprog.CHyperlink) 

the condition fails
 
this code
 
if (obj instanceof 
novick.urlprog.CHyperlink){link 
= (CHyperlink) 
obj;out.print(" 
" + 
link.GetHTML());}else{  
out.print(" " + obj.getClass().getName() 
);}
 
returns
 
novick.urlprog.CHyperlink
 
for each object in the vector
which seems impossible because the the name 
of the class is the same as what i tested for in the if 
statement!
 
any ideas?

  - Original Message - 
  From: 
  Hawkins, Keith 
  (Keith) 
  To: [EMAIL PROTECTED] 
  Sent: Friday, April 27, 2001 3:46 
PM
  Subject: RE: Objects in Vector are 
  loosing type
  
  What 
  do you get if you call getClass().getName()  on the obj at the point 
  you are getting the items back
  out 
  of the vector?
  
-Original Message-From: Ivan [mailto:[EMAIL PROTECTED]]Sent: 
Friday, April 27, 2001 5:14 PMTo: [EMAIL PROTECTED]Subject: 
Objects in Vector are loosing type
Does anyone know what is going on with the this 
weird problem?
 
I have a class named CHyperklink
 
I putting a vector into a session object and 
then adding CHyperlink objects to the vector.
 
When I retrieve the vector (with no problem) 
from the session object, I can cast the objects back to CHyperlinks if do it 
in the same servlet that put the objects in the vector.
 
If i retrieve the objects from the vector 
from a diffrent servlet than the one the put the objects into the 
vector, they all come out of the vector but they are not instanceof 
CHyperlink anymore and I cannot cast them back to CHyperlink.
 
When i call tostring() on the objects in the 
vector i get output indicating that they are still CHyperlinks.
 
I am stuck because i cant cast back to the 
CHyperlink and call the appropriate methods.  Does anyone know what is 
happending?
 
 
Here is output for tostring calls on objects 
in vector
 
novick.urlprog.CHyperlink@f11e4598novick.urlprog.CHyperlink@97064598novick.urlprog.CHyperlink@942a4598novick.urlprog.CHyperlink@909e4598novick.urlprog.CHyperlink@9c5a4598 

 
Here is code for inserting 
vector
 
   CHyperlink 
hlink;    
hlink = new CHyperlink(address, description, 
name);    
// create hyperlink object
 
    
HttpSession session = 
request.getSession();    
// get session
 
    
Vector urls = (Vector) 
session.getAttribute("vector");    
// get vector from session
 
    if 
(urls == 
null)    
// vector does not exist 
yet    
{  
urls = new 
Vector();  
// create new vector
 
  
session.setAttribute("vector",urls);  
// adds urls vector to session if not already 
there    
}
 
    
urls.add(hlink);    
// add the hyperlink to the vector
 
here is code for retrieving 
vector
 
    
HttpSession session = request.getSession();
 
    
Vector v2 = (Vector) 
session.getAttribute("vector");    
// get vector from session
 
    
Object 
obj;    
CHyperlink 
link;    
// temp variables
 
 
if ( v2 != 
null) {   
            out.print("Got the 
vector");
 
       
        for (int i = 0 ; i < v2.size() ; 
++i)          
     {    
                
obj = v2.get(i);
 
        
            if (obj instanceof 
novick.urlprog.CHyperlink)    
                
{  
link = (CHyperlink) 
obj;    
  out.print(" " + 
link.GetHTML());    
}        
            
            
            
else    
{  
        
            
out.print(" " + obj.toString() 
);    
}       
    }  }
 


Re: Objects in Vector are loosing type

2001-04-27 Thread Ivan

thank you very much for your reply

I turned off my computer and tried it again a few hours later and it seemed
to work, then i made changes and then the second servlet wasnt able to cast
back to CHyperlink again.  after putting the code back the way I had it, it
still wouldnt work.

So are you saying it is by chance if a different class loader loads each
servlet and this can effect the casting?

Also both servlets import the CHyperlink class.

One more note is the change I made that screwed it up after it was working
was attempting to forward the request to another servlet after adding the
CHyperlink objects to the vector.  Does this ring any bells?

THanks again for your replies.

Ivan

- Original Message -
From: "Filip Hanik" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 27, 2001 3:27 PM
Subject: RE: Objects in Vector are loosing type


> if servlet1 is the servlet that puts the object into the vector and
servlet2
> is the servlet that tries to read them.
> then these servlet may be loaded with different class loaders, which might
> indicate that each one of these servlets have loaded the class CHyperLink
> with different class loaders, hence you get a ClassCastException.
>
> the only way to solve this is if the class CHyperLink loaded with the same
> class loader.
>
> one option is to:
> remove the class from any WEB-INF/lib or WEB-INF/classes location (hide
them
> from the adaptive class loader)
> add the class into a separate directory and set your system classpath to
> include that location.
> the CHyperLink class will now be loaded using the System class loader when
> both servlets try to access it
>
> hope this helps
> Filip
>
> ~
> Namaste - I bow to the divine in you
> ~
> Filip Hanik
> Software Architect
> [EMAIL PROTECTED]
> www.filip.net
> -Original Message-
> From: Ivan [mailto:[EMAIL PROTECTED]]
> Sent: Friday, April 27, 2001 2:14 PM
> To: [EMAIL PROTECTED]
> Subject: Objects in Vector are loosing type
>
>
> Does anyone know what is going on with the this weird problem?
>
> I have a class named CHyperklink
>
> I putting a vector into a session object and then adding CHyperlink
objects
> to the vector.
>
> When I retrieve the vector (with no problem) from the session object, I
can
> cast the objects back to CHyperlinks if do it in the same servlet that put
> the objects in the vector.
>
> If i retrieve the objects from the vector from a diffrent servlet than the
> one the put the objects into the vector, they all come out of the vector
but
> they are not instanceof CHyperlink anymore and I cannot cast them back to
> CHyperlink.
>
> When i call tostring() on the objects in the vector i get output
indicating
> that they are still CHyperlinks.
>
> I am stuck because i cant cast back to the CHyperlink and call the
> appropriate methods.  Does anyone know what is happending?
>
>
> Here is output for tostring calls on objects in vector
>
> novick.urlprog.CHyperlink@f11e4598
> novick.urlprog.CHyperlink@97064598
> novick.urlprog.CHyperlink@942a4598
> novick.urlprog.CHyperlink@909e4598
> novick.urlprog.CHyperlink@9c5a4598
>
> Here is code for inserting vector
>
>CHyperlink hlink;
> hlink = new CHyperlink(address, description, name);
> // create hyperlink object
>
> HttpSession session = request.getSession();
> // get session
>
> Vector urls = (Vector) session.getAttribute("vector");
> // get vector from session
>
> if (urls == null)
> // vector does not exist yet
> {
>   urls = new Vector();
>   // create new vector
>
>   session.setAttribute("vector",urls);
>   // adds urls vector to session if not already there
> }
>
> urls.add(hlink);
> // add the hyperlink to the vector
>
> here is code for retrieving vector
>
> HttpSession session = request.getSession();
>
> Vector v2 = (Vector) session.getAttribute("vector");
> // get vector from session
>
> Object obj;
> CHyperlink link;
> // temp variables
>
>  if ( v2 != null)
>  {
>out.print("Got the vector");
>
>for (int i = 0 ; i < v2.size() ; ++i)
>{
> obj = v2.get(i);
>
> if (obj instanceof novick.urlprog.CHyperlink)
> {
>   link = (CHyperlink) obj;
>   out.print(" " + link.GetHTML());
> }
>
> else
> {
>   out.print(" " + obj.toString() );
> }
>}
>   }
>
>




RE: Objects in Vector are loosing type

2001-04-27 Thread Hawkins, Keith (Keith)



What 
do you get if you call getClass().getName()  on the obj at the point 
you are getting the items back
out of 
the vector?

  -Original Message-From: Ivan 
  [mailto:[EMAIL PROTECTED]]Sent: Friday, April 27, 2001 5:14 
  PMTo: [EMAIL PROTECTED]Subject: Objects in 
  Vector are loosing type
  Does anyone know what is going on with the this 
  weird problem?
   
  I have a class named CHyperklink
   
  I putting a vector into a session object and then 
  adding CHyperlink objects to the vector.
   
  When I retrieve the vector (with no problem) from 
  the session object, I can cast the objects back to CHyperlinks if do it in the 
  same servlet that put the objects in the vector.
   
  If i retrieve the objects from the vector 
  from a diffrent servlet than the one the put the objects into the vector, 
  they all come out of the vector but they are not instanceof CHyperlink anymore 
  and I cannot cast them back to CHyperlink.
   
  When i call tostring() on the objects in the 
  vector i get output indicating that they are still CHyperlinks.
   
  I am stuck because i cant cast back to the 
  CHyperlink and call the appropriate methods.  Does anyone know what is 
  happending?
   
   
  Here is output for tostring calls on objects in 
  vector
   
  novick.urlprog.CHyperlink@f11e4598novick.urlprog.CHyperlink@97064598novick.urlprog.CHyperlink@942a4598novick.urlprog.CHyperlink@909e4598novick.urlprog.CHyperlink@9c5a4598 
  
   
  Here is code for inserting 
  vector
   
     CHyperlink 
  hlink;    
  hlink = new CHyperlink(address, description, 
  name);    
  // create hyperlink object
   
      
  HttpSession session = 
  request.getSession();    
  // get session
   
      Vector 
  urls = (Vector) 
  session.getAttribute("vector");    
  // get vector from session
   
      if 
  (urls == 
  null)    // 
  vector does not exist 
  yet    
  {  
  urls = new 
  Vector();  
  // create new vector
   
    
  session.setAttribute("vector",urls);  
  // adds urls vector to session if not already 
  there    
  }
   
      
  urls.add(hlink);    
  // add the hyperlink to the vector
   
  here is code for retrieving 
  vector
   
      
  HttpSession session = request.getSession();
   
      Vector 
  v2 = (Vector) 
  session.getAttribute("vector");    
  // get vector from session
   
      Object 
  obj;    
  CHyperlink 
  link;    // 
  temp variables
   
   
  if ( v2 != 
  null) {   
              out.print("Got the 
  vector");
   
         
          for (int i = 0 ; i < v2.size() ; 
  ++i)          
       {    
                  
  obj = v2.get(i);
   
          
              if (obj instanceof 
  novick.urlprog.CHyperlink)    
                  
  {  
  link = (CHyperlink) 
  obj;    
    out.print(" " + 
  link.GetHTML());    
  }        
              
              
              
  else    
  {      
                  
  out.print(" " + obj.toString() 
  );    
  }       
      }  }
   


RE: Objects in Vector are loosing type

2001-04-27 Thread Filip Hanik

if servlet1 is the servlet that puts the object into the vector and servlet2
is the servlet that tries to read them.
then these servlet may be loaded with different class loaders, which might
indicate that each one of these servlets have loaded the class CHyperLink
with different class loaders, hence you get a ClassCastException.

the only way to solve this is if the class CHyperLink loaded with the same
class loader.

one option is to:
remove the class from any WEB-INF/lib or WEB-INF/classes location (hide them
from the adaptive class loader)
add the class into a separate directory and set your system classpath to
include that location.
the CHyperLink class will now be loaded using the System class loader when
both servlets try to access it

hope this helps
Filip

~
Namaste - I bow to the divine in you
~
Filip Hanik
Software Architect
[EMAIL PROTECTED]
www.filip.net
-Original Message-
From: Ivan [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 2:14 PM
To: [EMAIL PROTECTED]
Subject: Objects in Vector are loosing type


Does anyone know what is going on with the this weird problem?

I have a class named CHyperklink

I putting a vector into a session object and then adding CHyperlink objects
to the vector.

When I retrieve the vector (with no problem) from the session object, I can
cast the objects back to CHyperlinks if do it in the same servlet that put
the objects in the vector.

If i retrieve the objects from the vector from a diffrent servlet than the
one the put the objects into the vector, they all come out of the vector but
they are not instanceof CHyperlink anymore and I cannot cast them back to
CHyperlink.

When i call tostring() on the objects in the vector i get output indicating
that they are still CHyperlinks.

I am stuck because i cant cast back to the CHyperlink and call the
appropriate methods.  Does anyone know what is happending?


Here is output for tostring calls on objects in vector

novick.urlprog.CHyperlink@f11e4598
novick.urlprog.CHyperlink@97064598
novick.urlprog.CHyperlink@942a4598
novick.urlprog.CHyperlink@909e4598
novick.urlprog.CHyperlink@9c5a4598

Here is code for inserting vector

   CHyperlink hlink;
hlink = new CHyperlink(address, description, name);
// create hyperlink object

HttpSession session = request.getSession();
// get session

Vector urls = (Vector) session.getAttribute("vector");
// get vector from session

if (urls == null)
// vector does not exist yet
{
  urls = new Vector();
  // create new vector

  session.setAttribute("vector",urls);
  // adds urls vector to session if not already there
}

urls.add(hlink);
// add the hyperlink to the vector

here is code for retrieving vector

HttpSession session = request.getSession();

Vector v2 = (Vector) session.getAttribute("vector");
// get vector from session

Object obj;
CHyperlink link;
// temp variables

 if ( v2 != null)
 {
   out.print("Got the vector");

   for (int i = 0 ; i < v2.size() ; ++i)
   {
obj = v2.get(i);

if (obj instanceof novick.urlprog.CHyperlink)
{
  link = (CHyperlink) obj;
  out.print(" " + link.GetHTML());
}

else
{
  out.print(" " + obj.toString() );
}
   }
  }