I think there's another place the context ClassLoader should be
set: right before init(ServletConfig) is called. Attached is a
patch that sets the current Thread's ContextClassLoader and then to the 
servlet context's ClassLoader and restores it after init() completes.
This ensures that the webapp is able to use the context ClassLoader
to refer to its own ClassLoader during init() phase as well as 
service(). I tested this with the latest from CVS, and it worked.

--kd

Index: StandardWrapper.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v
retrieving revision 1.18
diff -u -r1.18 StandardWrapper.java
--- StandardWrapper.java        2001/04/07 22:33:01     1.18
+++ StandardWrapper.java        2001/04/19 16:24:29
@@ -749,6 +749,8 @@
                (sm.getString("standardWrapper.missingLoader", getName()));
        }
        ClassLoader classLoader = loader.getClassLoader();
+ 
ClassLoader oldCtxClassLoader = Thread.currentThread().
+ 
     getContextClassLoader();

          // Special case class loader for a Catalina internal servlet
        if (isContainerServlet(actualClass)) {
@@ -800,6 +802,7 @@
        try {
            instanceSupport.fireInstanceEvent(InstanceEvent.BEFORE_INIT_EVENT,
         
                              servlet);
+ 
     Thread.currentThread().setContextClassLoader(classLoader);
            servlet.init((ServletConfig) this);
            instanceSupport.fireInstanceEvent(InstanceEvent.AFTER_INIT_EVENT,
         
                              servlet);
@@ -821,6 +824,9 @@
            // said so, so do not call unavailable(null).
            throw new ServletException
                (sm.getString("standardWrapper.initException", getName()), f);
+ 
} finally {
+ 
     // restore the context ClassLoader
+ 
     Thread.currentThread().setContextClassLoader(oldCtxClassLoader);
        }

        // Register our newly initialized instance

Reply via email to