You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Serge Huber <sh...@mycomponents.com> on 2001/04/27 05:39:14 UTC

Cross context class loader bug ?

	
Hi all,

I am using cross context dispatching in one of my web applications. In 
order to do this I have the following setup in my server.xml file :

         <DefaultContext crossContext="true" reloadable="true" debug="999">
         </DefaultContext>

This is of course in a <Host> tag. I know this is a little extreme to put 
the cross context in the default context but well the problem is not here :)

Basically my code does the following :

	ServletContext dispatchContext = request.getContext(contextNameWithSlash);
	RequestDispatcher dispatcher = 
dispatchContext.getNamedDispatcher(servletName);
	dispatcher.include(requestWrapper, responseWrapper);

As far as I can tell from the public draft of the Servlet API 2.3 this 
should be valid and no null value is returned by the functions (if I 
deactivate the crossContext I get the expected behavior in getContext).

I have two webapps in my setup :
	/caller
	/webraptor which is the web app I want to dispatch to

Now the problem. When the above code execute, this is the stack trace I get :

2001-04-27 05:11:08 StandardWrapper[/webraptor:WebRaptor]: Marking servlet 
WebRaptor as unavailable
2001-04-27 05:11:08 ApplicationDispatcher[/webraptor] Allocate exception 
for servlet WebRaptor
javax.servlet.ServletException: Wrapper cannot find servlet class 
com.xo3.webraptor.MainServlet or a class it depends on
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:786)
	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
	at 
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
	at 
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
	at 
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
	...my stuff
----- Root Cause -----
java.lang.ClassNotFoundException: com.xo3.webraptor.MainServlet
	at 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1064)
	at 
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:929)
	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:781)
	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
	at 
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
	at 
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
	at 
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
	... my stuff

Seems to be a problem with the class loader code when doing dispatching, 
because if I call the destination servlet directly I do not get the same 
behaviour and the servlet is loaded and executed correctly. The code for 
the webapps is all in its right place since calling the servlet manually 
works fine.

I have been scratching my head over this one for a while now and I would 
appreciate any pointer. For information, I can reproduce the problem on 
both tomcat4.0b3, tomcat4.0b4-dev-20010426 (the latest nightly snapshot I 
could get my hands on).

Last but not least I must say that this worked fine under tomcat4.0b1 and 
that I am willing to patch tomcat code if needed.

Thanks a lot,

	Serge Huber.


Re: Cross context class loader bug ?

Posted by Remy Maucherat <re...@apache.org>.
> Hi all,
>
> I am using cross context dispatching in one of my web applications. In
> order to do this I have the following setup in my server.xml file :
>
>          <DefaultContext crossContext="true" reloadable="true"
debug="999">
>          </DefaultContext>
>
> This is of course in a <Host> tag. I know this is a little extreme to put
> the cross context in the default context but well the problem is not here
:)
>
> Basically my code does the following :
>
> ServletContext dispatchContext = request.getContext(contextNameWithSlash);
> RequestDispatcher dispatcher =
> dispatchContext.getNamedDispatcher(servletName);
> dispatcher.include(requestWrapper, responseWrapper);
>
> As far as I can tell from the public draft of the Servlet API 2.3 this
> should be valid and no null value is returned by the functions (if I
> deactivate the crossContext I get the expected behavior in getContext).
>
> I have two webapps in my setup :
> /caller
> /webraptor which is the web app I want to dispatch to
>
> Now the problem. When the above code execute, this is the stack trace I
get :
>
> 2001-04-27 05:11:08 StandardWrapper[/webraptor:WebRaptor]: Marking servlet
> WebRaptor as unavailable
> 2001-04-27 05:11:08 ApplicationDispatcher[/webraptor] Allocate exception
> for servlet WebRaptor
> javax.servlet.ServletException: Wrapper cannot find servlet class
> com.xo3.webraptor.MainServlet or a class it depends on
> at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:786)
> at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> at
>
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.
java:513)
> at
>
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatch
er.java:414)
> at
>
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher
.java:378)
> ...my stuff
> ----- Root Cause -----
> java.lang.ClassNotFoundException: com.xo3.webraptor.MainServlet
> at
>
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader
.java:1064)
> at
>
org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader
.java:929)
> at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:781)
> at
org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> at
>
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.
java:513)
> at
>
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatch
er.java:414)
> at
>
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher
.java:378)
> ... my stuff
>
> Seems to be a problem with the class loader code when doing dispatching,
> because if I call the destination servlet directly I do not get the same
> behaviour and the servlet is loaded and executed correctly. The code for
> the webapps is all in its right place since calling the servlet manually
> works fine.
>
> I have been scratching my head over this one for a while now and I would
> appreciate any pointer. For information, I can reproduce the problem on
> both tomcat4.0b3, tomcat4.0b4-dev-20010426 (the latest nightly snapshot I
> could get my hands on).
>
> Last but not least I must say that this worked fine under tomcat4.0b1 and
> that I am willing to patch tomcat code if needed.

I can confirm the issue : the thread context classloader is not properly set
when including a servlet from another context. In TC 4b1, it wasn't that bad
(although it could still lead to some problems in some rare cases), but it
TC 4b3 and up, it breaks classloading.
That will have to be fixed.

Remy


Re: Cross context class loader bug ?

Posted by Serge Huber <sh...@mycomponents.com>.
I understand that the patch would be welcome :) But I must say that it's 
definitely not easy to get down into the class loading code of Tomcat.

My gut feeling about this bug is that somehow the class loader isn't the 
right one once the dispatching process starts. In my example it seems like 
the class loader in effet during the dispatch is still the /caller one when 
it should be the /webraptor one. This would explain why it doesn't work 
when dispatching and fine when calling directly...

         Serge...


At 20:52 26.04.2001 -0700, you wrote:
>Yep, that definitely looks like a bug.  Any proposed patch would
>*definitely* be welcome.
>
>Craig
>
>
>On Fri, 27 Apr 2001, Serge Huber wrote:
>
> >
> > Hi all,
> >
> > I am using cross context dispatching in one of my web applications. In
> > order to do this I have the following setup in my server.xml file :
> >
> >          <DefaultContext crossContext="true" reloadable="true" debug="999">
> >          </DefaultContext>
> >
> > This is of course in a <Host> tag. I know this is a little extreme to put
> > the cross context in the default context but well the problem is not 
> here :)
> >
> > Basically my code does the following :
> >
> >       ServletContext dispatchContext = 
> request.getContext(contextNameWithSlash);
> >       RequestDispatcher dispatcher =
> > dispatchContext.getNamedDispatcher(servletName);
> >       dispatcher.include(requestWrapper, responseWrapper);
> >
> > As far as I can tell from the public draft of the Servlet API 2.3 this
> > should be valid and no null value is returned by the functions (if I
> > deactivate the crossContext I get the expected behavior in getContext).
> >
> > I have two webapps in my setup :
> >       /caller
> >       /webraptor which is the web app I want to dispatch to
> >
> > Now the problem. When the above code execute, this is the stack trace I 
> get :
> >
> > 2001-04-27 05:11:08 StandardWrapper[/webraptor:WebRaptor]: Marking servlet
> > WebRaptor as unavailable
> > 2001-04-27 05:11:08 ApplicationDispatcher[/webraptor] Allocate exception
> > for servlet WebRaptor
> > javax.servlet.ServletException: Wrapper cannot find servlet class
> > com.xo3.webraptor.MainServlet or a class it depends on
> >       at 
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:786)
> >       at 
> org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> >       ...my stuff
> > ----- Root Cause -----
> > java.lang.ClassNotFoundException: com.xo3.webraptor.MainServlet
> >       at
> > 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1064)
> >       at
> > 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:929)
> >       at 
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:781)
> >       at 
> org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> >       ... my stuff
> >
> > Seems to be a problem with the class loader code when doing dispatching,
> > because if I call the destination servlet directly I do not get the same
> > behaviour and the servlet is loaded and executed correctly. The code for
> > the webapps is all in its right place since calling the servlet manually
> > works fine.
> >
> > I have been scratching my head over this one for a while now and I would
> > appreciate any pointer. For information, I can reproduce the problem on
> > both tomcat4.0b3, tomcat4.0b4-dev-20010426 (the latest nightly snapshot I
> > could get my hands on).
> >
> > Last but not least I must say that this worked fine under tomcat4.0b1 and
> > that I am willing to patch tomcat code if needed.
> >
> > Thanks a lot,
> >
> >       Serge Huber.
> >
> >


Re: Cross context class loader bug ?

Posted by Serge Huber <sh...@mycomponents.com>.
Another point I forgot to say is that I tried forcing initial load by 
setting the webraptor web application servlet to load on startup. Then 
during the dispatch process, as soon as the called web application accesses 
ANOTHER of it's classes that hasn't been loaded yet I get exactly the same 
error.

greetings,

         Serge...

At 20:52 26.04.2001 -0700, you wrote:
>Yep, that definitely looks like a bug.  Any proposed patch would
>*definitely* be welcome.
>
>Craig
>
>
>On Fri, 27 Apr 2001, Serge Huber wrote:
>
> >
> > Hi all,
> >
> > I am using cross context dispatching in one of my web applications. In
> > order to do this I have the following setup in my server.xml file :
> >
> >          <DefaultContext crossContext="true" reloadable="true" debug="999">
> >          </DefaultContext>
> >
> > This is of course in a <Host> tag. I know this is a little extreme to put
> > the cross context in the default context but well the problem is not 
> here :)
> >
> > Basically my code does the following :
> >
> >       ServletContext dispatchContext = 
> request.getContext(contextNameWithSlash);
> >       RequestDispatcher dispatcher =
> > dispatchContext.getNamedDispatcher(servletName);
> >       dispatcher.include(requestWrapper, responseWrapper);
> >
> > As far as I can tell from the public draft of the Servlet API 2.3 this
> > should be valid and no null value is returned by the functions (if I
> > deactivate the crossContext I get the expected behavior in getContext).
> >
> > I have two webapps in my setup :
> >       /caller
> >       /webraptor which is the web app I want to dispatch to
> >
> > Now the problem. When the above code execute, this is the stack trace I 
> get :
> >
> > 2001-04-27 05:11:08 StandardWrapper[/webraptor:WebRaptor]: Marking servlet
> > WebRaptor as unavailable
> > 2001-04-27 05:11:08 ApplicationDispatcher[/webraptor] Allocate exception
> > for servlet WebRaptor
> > javax.servlet.ServletException: Wrapper cannot find servlet class
> > com.xo3.webraptor.MainServlet or a class it depends on
> >       at 
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:786)
> >       at 
> org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> >       ...my stuff
> > ----- Root Cause -----
> > java.lang.ClassNotFoundException: com.xo3.webraptor.MainServlet
> >       at
> > 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1064)
> >       at
> > 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:929)
> >       at 
> org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:781)
> >       at 
> org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> >       at
> > 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> >       ... my stuff
> >
> > Seems to be a problem with the class loader code when doing dispatching,
> > because if I call the destination servlet directly I do not get the same
> > behaviour and the servlet is loaded and executed correctly. The code for
> > the webapps is all in its right place since calling the servlet manually
> > works fine.
> >
> > I have been scratching my head over this one for a while now and I would
> > appreciate any pointer. For information, I can reproduce the problem on
> > both tomcat4.0b3, tomcat4.0b4-dev-20010426 (the latest nightly snapshot I
> > could get my hands on).
> >
> > Last but not least I must say that this worked fine under tomcat4.0b1 and
> > that I am willing to patch tomcat code if needed.
> >
> > Thanks a lot,
> >
> >       Serge Huber.
> >
> >


Re: Cross context class loader bug ?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Yep, that definitely looks like a bug.  Any proposed patch would
*definitely* be welcome.

Craig


On Fri, 27 Apr 2001, Serge Huber wrote:

> 	
> Hi all,
> 
> I am using cross context dispatching in one of my web applications. In 
> order to do this I have the following setup in my server.xml file :
> 
>          <DefaultContext crossContext="true" reloadable="true" debug="999">
>          </DefaultContext>
> 
> This is of course in a <Host> tag. I know this is a little extreme to put 
> the cross context in the default context but well the problem is not here :)
> 
> Basically my code does the following :
> 
> 	ServletContext dispatchContext = request.getContext(contextNameWithSlash);
> 	RequestDispatcher dispatcher = 
> dispatchContext.getNamedDispatcher(servletName);
> 	dispatcher.include(requestWrapper, responseWrapper);
> 
> As far as I can tell from the public draft of the Servlet API 2.3 this 
> should be valid and no null value is returned by the functions (if I 
> deactivate the crossContext I get the expected behavior in getContext).
> 
> I have two webapps in my setup :
> 	/caller
> 	/webraptor which is the web app I want to dispatch to
> 
> Now the problem. When the above code execute, this is the stack trace I get :
> 
> 2001-04-27 05:11:08 StandardWrapper[/webraptor:WebRaptor]: Marking servlet 
> WebRaptor as unavailable
> 2001-04-27 05:11:08 ApplicationDispatcher[/webraptor] Allocate exception 
> for servlet WebRaptor
> javax.servlet.ServletException: Wrapper cannot find servlet class 
> com.xo3.webraptor.MainServlet or a class it depends on
> 	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:786)
> 	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> 	...my stuff
> ----- Root Cause -----
> java.lang.ClassNotFoundException: com.xo3.webraptor.MainServlet
> 	at 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1064)
> 	at 
> org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:929)
> 	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:781)
> 	at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:594)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:513)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:414)
> 	at 
> org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:378)
> 	... my stuff
> 
> Seems to be a problem with the class loader code when doing dispatching, 
> because if I call the destination servlet directly I do not get the same 
> behaviour and the servlet is loaded and executed correctly. The code for 
> the webapps is all in its right place since calling the servlet manually 
> works fine.
> 
> I have been scratching my head over this one for a while now and I would 
> appreciate any pointer. For information, I can reproduce the problem on 
> both tomcat4.0b3, tomcat4.0b4-dev-20010426 (the latest nightly snapshot I 
> could get my hands on).
> 
> Last but not least I must say that this worked fine under tomcat4.0b1 and 
> that I am willing to patch tomcat code if needed.
> 
> Thanks a lot,
> 
> 	Serge Huber.
> 
>