You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by to...@aladin.ca on 2006/04/06 16:10:07 UTC

crossContext breaking class hierarchy?

Hello,

I am experiencing a problem with Tomcat and class hierarchies.  In
particular when an object (which implements interface X) is shared among
serveral contexts I am unable to cast the object back into interface X.

Here is the setup (for simplicity I'll illustrate this with 2 contexts):

* Interface "ClassInterface" is distributed across all applications in a
.jar.

Application A in context a
--------------------------
- Implements ClassInterface and adds an instance of the class in it's
context:

  ClassInterface i = new ClassInterfaceImplementation();
  getServletContext().setAttribute("some.key", i);

Application B in context b
--------------------------
- Tries to cast the object in the context back into a ClassInterface but
fails with a classCastException: ClassInterfaceImplementation

  ServletContext context = (ServletContext)
getServletContext.getContext("/a");
  ClassInterface i = (ClassInterface) context.getAttribute("some.key");
  -- EXCEPTION IS THROWN --
  java.lang.ClassCastException: ClassInterfaceImplementation


Has anybody experienced this before?  Does setting an attribute in the
context mess things up with the class hierarchy?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by David Gagnon <dg...@siunik.com>.
Leon Rosenberg wrote:

>Well, if you don't need the session just forget about it :-)
>If you don't put anything into session and aren't using it in any
>other way, why should there be a memory leak?
>  
>
Maybe a misunderstanding from me but I tought Tomcat will keep session 
info on each connection for a given time (let say 15 minutes).  So if 
1000 uses ask for a report in 15 minute it's 1000 session object.  But 
my numbers are too high anyway so probably this leak is not a problem .. 
if leak exists :-)

Regards
/David


>regards
>Leon
>
>
>On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
>  
>
>>Hi,
>>
>>    
>>
>>>Check the javadocs:
>>>
>>>http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getSession()
>>>
>>>Returns the current session associated with this request, or if the
>>>request does not have a session, creates one.
>>>
>>>If you don't want a session call getSession(false) or don't call the
>>>method at all. As far as I know the webapp will be sessionless as long
>>>as you don't call getSession() on request object and put
>>>session="false" in all your jsps (otherwise in the generated java
>>>servlet HttpSession session = request.getSession(); will be called).
>>>
>>>
>>>      
>>>
>>Thanks I was looking for doing the JSP <%@ page session="true"  %>
>>equivalent .. but in servlet
>>
>>
>>    
>>
>>>Another question, what's your goal? Why do you need explicitely
>>>sessionless servlets so badly? Isn't it sufficent just not to use the
>>>session if you don't need it?
>>>
>>>
>>>      
>>>
>>I want to use Tomcat to hold a reportServer.  It will receive request
>>from different users from different webApp to craft reports.  It needs
>>to be sessionless,  in fact since I don't need session I just wanted to
>>avoid a memory leak...
>>
>>Thanks for your help
>>/David
>>
>>
>>
>>    
>>
>>>regards
>>>Leon
>>>
>>>On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
>>>
>>>
>>>      
>>>
>>>>In fact I need to know How to have a sessionless Servlet?  I search the
>>>>tomcat source and it seems I have nothing to do.  But when I do a
>>>>request.getSession()  I do receive a session object?  Is that normal
>>>>behavior?
>>>>
>>>>Thanks for your help
>>>>/David
>>>>
>>>>
>>>>
>>>>Franck Borel wrote:
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Use <%@ page session="false"> in your jsp sites.
>>>>>
>>>>>-- Franck
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>I need to have a sessionless tomcat.  I surely easy to do but I'm
>>>>>>searching without success for a while now.
>>>>>>
>>>>>>I need a servlet without session.
>>>>>>
>>>>>>
>>>>>>Thanks for your help
>>>>>>Best regards
>>>>>>/David
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>------------------------------------------------------------------------
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>
>>>
>>>
>>>
>>>
>>>      
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by Leon Rosenberg <ro...@googlemail.com>.
Well, if you don't need the session just forget about it :-)
If you don't put anything into session and aren't using it in any
other way, why should there be a memory leak?

regards
Leon


On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
> Hi,
>
> >Check the javadocs:
> >
> >http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getSession()
> >
> >Returns the current session associated with this request, or if the
> >request does not have a session, creates one.
> >
> >If you don't want a session call getSession(false) or don't call the
> >method at all. As far as I know the webapp will be sessionless as long
> >as you don't call getSession() on request object and put
> >session="false" in all your jsps (otherwise in the generated java
> >servlet HttpSession session = request.getSession(); will be called).
> >
> >
> Thanks I was looking for doing the JSP <%@ page session="true"  %>
> equivalent .. but in servlet
>
>
> >Another question, what's your goal? Why do you need explicitely
> >sessionless servlets so badly? Isn't it sufficent just not to use the
> >session if you don't need it?
> >
> >
> I want to use Tomcat to hold a reportServer.  It will receive request
> from different users from different webApp to craft reports.  It needs
> to be sessionless,  in fact since I don't need session I just wanted to
> avoid a memory leak...
>
> Thanks for your help
> /David
>
>
>
> >regards
> >Leon
> >
> >On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
> >
> >
> >>In fact I need to know How to have a sessionless Servlet?  I search the
> >>tomcat source and it seems I have nothing to do.  But when I do a
> >>request.getSession()  I do receive a session object?  Is that normal
> >>behavior?
> >>
> >>Thanks for your help
> >>/David
> >>
> >>
> >>
> >>Franck Borel wrote:
> >>
> >>
> >>
> >>>Use <%@ page session="false"> in your jsp sites.
> >>>
> >>>-- Franck
> >>>
> >>>
> >>>
> >>>>Hi,
> >>>>
> >>>> I need to have a sessionless tomcat.  I surely easy to do but I'm
> >>>>searching without success for a while now.
> >>>>
> >>>>I need a servlet without session.
> >>>>
> >>>>
> >>>>Thanks for your help
> >>>>Best regards
> >>>>/David
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>>For additional commands, e-mail: users-help@tomcat.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>------------------------------------------------------------------------
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>For additional commands, e-mail: users-help@tomcat.apache.org
> >>>
> >>>
> >>>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
> >
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by David Gagnon <dg...@siunik.com>.
Hi,

>Check the javadocs:
>
>http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getSession()
>
>Returns the current session associated with this request, or if the
>request does not have a session, creates one.
>
>If you don't want a session call getSession(false) or don't call the
>method at all. As far as I know the webapp will be sessionless as long
>as you don't call getSession() on request object and put
>session="false" in all your jsps (otherwise in the generated java
>servlet HttpSession session = request.getSession(); will be called).
>  
>
Thanks I was looking for doing the JSP <%@ page session="true"  %> 
equivalent .. but in servlet


>Another question, what's your goal? Why do you need explicitely
>sessionless servlets so badly? Isn't it sufficent just not to use the
>session if you don't need it?
>  
>
I want to use Tomcat to hold a reportServer.  It will receive request 
from different users from different webApp to craft reports.  It needs 
to be sessionless,  in fact since I don't need session I just wanted to 
avoid a memory leak...

Thanks for your help
/David



>regards
>Leon
>
>On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
>  
>
>>In fact I need to know How to have a sessionless Servlet?  I search the
>>tomcat source and it seems I have nothing to do.  But when I do a
>>request.getSession()  I do receive a session object?  Is that normal
>>behavior?
>>
>>Thanks for your help
>>/David
>>
>>
>>
>>Franck Borel wrote:
>>
>>    
>>
>>>Use <%@ page session="false"> in your jsp sites.
>>>
>>>-- Franck
>>>
>>>      
>>>
>>>>Hi,
>>>>
>>>> I need to have a sessionless tomcat.  I surely easy to do but I'm
>>>>searching without success for a while now.
>>>>
>>>>I need a servlet without session.
>>>>
>>>>
>>>>Thanks for your help
>>>>Best regards
>>>>/David
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>>
>>>>        
>>>>
>>>------------------------------------------------------------------------
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>>      
>>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by Leon Rosenberg <ro...@googlemail.com>.
Check the javadocs:

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getSession()

Returns the current session associated with this request, or if the
request does not have a session, creates one.

If you don't want a session call getSession(false) or don't call the
method at all. As far as I know the webapp will be sessionless as long
as you don't call getSession() on request object and put
session="false" in all your jsps (otherwise in the generated java
servlet HttpSession session = request.getSession(); will be called).

Another question, what's your goal? Why do you need explicitely
sessionless servlets so badly? Isn't it sufficent just not to use the
session if you don't need it?

regards
Leon

On 4/7/06, David Gagnon <dg...@siunik.com> wrote:
> In fact I need to know How to have a sessionless Servlet?  I search the
> tomcat source and it seems I have nothing to do.  But when I do a
> request.getSession()  I do receive a session object?  Is that normal
> behavior?
>
> Thanks for your help
> /David
>
>
>
> Franck Borel wrote:
>
> > Use <%@ page session="false"> in your jsp sites.
> >
> > -- Franck
> >
> >> Hi,
> >>
> >>  I need to have a sessionless tomcat.  I surely easy to do but I'm
> >> searching without success for a while now.
> >>
> >> I need a servlet without session.
> >>
> >>
> >> Thanks for your help
> >> Best regards
> >> /David
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >>
> >
> >
> >------------------------------------------------------------------------
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by David Gagnon <dg...@siunik.com>.
In fact I need to know How to have a sessionless Servlet?  I search the 
tomcat source and it seems I have nothing to do.  But when I do a 
request.getSession()  I do receive a session object?  Is that normal 
behavior?

Thanks for your help
/David



Franck Borel wrote:

> Use <%@ page session="false"> in your jsp sites.
>
> -- Franck
>
>> Hi,
>>
>>  I need to have a sessionless tomcat.  I surely easy to do but I'm 
>> searching without success for a while now.
>>
>> I need a servlet without session.
>>
>>
>> Thanks for your help
>> Best regards
>> /David
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How do disable session in tomcat 5.5?

Posted by Franck Borel <bo...@ub.uni-freiburg.de>.
Use <%@ page session="false"> in your jsp sites.

-- Franck
> Hi,
>
>  I need to have a sessionless tomcat.  I surely easy to do but I'm 
> searching without success for a while now.
>
> I need a servlet without session.
>
>
> Thanks for your help
> Best regards
> /David
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


-- 
====================================================================
Dipl.-Hyd. Franck Borel               Universitaetsbibliothek Freiburg
EMail: borel@ub.uni-freiburg.de       EDV-Dezernat
Tel. : +49-761 / 203-3908             Werthmannplatz 2 | Postfach 1629
Fax  : +49-761 / 203-3987             79098 Freiburg   | 79016 Freiburg



How do disable session in tomcat 5.5?

Posted by David Gagnon <dg...@siunik.com>.
Hi,

  I need to have a sessionless tomcat.  I surely easy to do but I'm 
searching without success for a while now.

I need a servlet without session.


Thanks for your help
Best regards
/David

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: crossContext breaking class hierarchy?

Posted by to...@aladin.ca.
Problem sovled.  Thanks Tim you got me thinking on the right path.

I put the interface.jar in the tomcat shared/lib rather than in the
individual context's  lib folder.

This worked because the jar in the shared/lib folder is common to each of
the context's classloader.  Putting the interface.jar in each context
reflects having two different interfaces (because of the different
classloaders).


> My interface is only in the 2 context specific locations:
>
> Application A context a: /WEB-INF/lib/interface.jar
> Application B context b: /WEB-INF/lib/interface.jar
>
> It is not in the Tomcat common or shared lib folders; I've verified this
> just in case I had a brain cramp.
>
>
>
>> I've seen this with Oracle jdbc objects.  If you have classes12.jar in
>> your
>> WEB-INF/lib directory, and a copy in common/lib (for the Tomcat
>> Datasource)
>> then you will have TWO oracle.jdbc.XX classes loaded, one in the common
>> classloader and on in your web app's classloader and although they are
>> both
>> oracle.jdbc.XX, they are not the SAME class object (instance).
>>
>> So, be certain your interface X is not in two visible places.  Or if it
>> is,
>> you cannot cast objects from one classloader to the other.
>>
>> Tim
>>
>> -----Original Message-----
>> From: tomcat@aladin.ca [mailto:tomcat@aladin.ca]
>> Sent: Thursday, April 06, 2006 10:10 AM
>> To: users@tomcat.apache.org
>> Subject: crossContext breaking class hierarchy?
>>
>> Hello,
>>
>> I am experiencing a problem with Tomcat and class hierarchies.  In
>> particular when an object (which implements interface X) is shared among
>> serveral contexts I am unable to cast the object back into interface X.
>>
>> Here is the setup (for simplicity I'll illustrate this with 2 contexts):
>>
>> * Interface "ClassInterface" is distributed across all applications in a
>> .jar.
>>
>> Application A in context a
>> --------------------------
>> - Implements ClassInterface and adds an instance of the class in it's
>> context:
>>
>>   ClassInterface i = new ClassInterfaceImplementation();
>>   getServletContext().setAttribute("some.key", i);
>>
>> Application B in context b
>> --------------------------
>> - Tries to cast the object in the context back into a ClassInterface but
>> fails with a classCastException: ClassInterfaceImplementation
>>
>>   ServletContext context = (ServletContext)
>> getServletContext.getContext("/a");
>>   ClassInterface i = (ClassInterface) context.getAttribute("some.key");
>>   -- EXCEPTION IS THROWN --
>>   java.lang.ClassCastException: ClassInterfaceImplementation
>>
>>
>> Has anybody experienced this before?  Does setting an attribute in the
>> context mess things up with the class hierarchy?
>>
>> Thanks.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: crossContext breaking class hierarchy?

Posted by to...@aladin.ca.
My interface is only in the 2 context specific locations:

Application A context a: /WEB-INF/lib/interface.jar
Application B context b: /WEB-INF/lib/interface.jar

It is not in the Tomcat common or shared lib folders; I've verified this
just in case I had a brain cramp.



> I've seen this with Oracle jdbc objects.  If you have classes12.jar in
> your
> WEB-INF/lib directory, and a copy in common/lib (for the Tomcat
> Datasource)
> then you will have TWO oracle.jdbc.XX classes loaded, one in the common
> classloader and on in your web app's classloader and although they are
> both
> oracle.jdbc.XX, they are not the SAME class object (instance).
>
> So, be certain your interface X is not in two visible places.  Or if it
> is,
> you cannot cast objects from one classloader to the other.
>
> Tim
>
> -----Original Message-----
> From: tomcat@aladin.ca [mailto:tomcat@aladin.ca]
> Sent: Thursday, April 06, 2006 10:10 AM
> To: users@tomcat.apache.org
> Subject: crossContext breaking class hierarchy?
>
> Hello,
>
> I am experiencing a problem with Tomcat and class hierarchies.  In
> particular when an object (which implements interface X) is shared among
> serveral contexts I am unable to cast the object back into interface X.
>
> Here is the setup (for simplicity I'll illustrate this with 2 contexts):
>
> * Interface "ClassInterface" is distributed across all applications in a
> .jar.
>
> Application A in context a
> --------------------------
> - Implements ClassInterface and adds an instance of the class in it's
> context:
>
>   ClassInterface i = new ClassInterfaceImplementation();
>   getServletContext().setAttribute("some.key", i);
>
> Application B in context b
> --------------------------
> - Tries to cast the object in the context back into a ClassInterface but
> fails with a classCastException: ClassInterfaceImplementation
>
>   ServletContext context = (ServletContext)
> getServletContext.getContext("/a");
>   ClassInterface i = (ClassInterface) context.getAttribute("some.key");
>   -- EXCEPTION IS THROWN --
>   java.lang.ClassCastException: ClassInterfaceImplementation
>
>
> Has anybody experienced this before?  Does setting an attribute in the
> context mess things up with the class hierarchy?
>
> Thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: crossContext breaking class hierarchy?

Posted by Tim Lucia <ti...@yahoo.com>.
I've seen this with Oracle jdbc objects.  If you have classes12.jar in your
WEB-INF/lib directory, and a copy in common/lib (for the Tomcat Datasource)
then you will have TWO oracle.jdbc.XX classes loaded, one in the common
classloader and on in your web app's classloader and although they are both
oracle.jdbc.XX, they are not the SAME class object (instance).

So, be certain your interface X is not in two visible places.  Or if it is,
you cannot cast objects from one classloader to the other.

Tim 

-----Original Message-----
From: tomcat@aladin.ca [mailto:tomcat@aladin.ca] 
Sent: Thursday, April 06, 2006 10:10 AM
To: users@tomcat.apache.org
Subject: crossContext breaking class hierarchy?

Hello,

I am experiencing a problem with Tomcat and class hierarchies.  In
particular when an object (which implements interface X) is shared among
serveral contexts I am unable to cast the object back into interface X.

Here is the setup (for simplicity I'll illustrate this with 2 contexts):

* Interface "ClassInterface" is distributed across all applications in a
.jar.

Application A in context a
--------------------------
- Implements ClassInterface and adds an instance of the class in it's
context:

  ClassInterface i = new ClassInterfaceImplementation();
  getServletContext().setAttribute("some.key", i);

Application B in context b
--------------------------
- Tries to cast the object in the context back into a ClassInterface but
fails with a classCastException: ClassInterfaceImplementation

  ServletContext context = (ServletContext)
getServletContext.getContext("/a");
  ClassInterface i = (ClassInterface) context.getAttribute("some.key");
  -- EXCEPTION IS THROWN --
  java.lang.ClassCastException: ClassInterfaceImplementation


Has anybody experienced this before?  Does setting an attribute in the
context mess things up with the class hierarchy?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org