glenn       2002/11/12 18:23:11

  Modified:    catalina/src/share/org/apache/catalina/core
                        NamingContextListener.java StandardContext.java
               catalina/src/share/org/apache/naming ContextBindings.java
  Log:
  Bug fix for BUG #13364
  
  A Web Application Context reload by the manager web application
  was causing named JNDI resources to disappear.
  
  A webapp reload needs to dump the webapp classloader, then
  recreate. The CL is bound to the naming context so the
  reload was issing a NamingContext STOP_EVENT and then a
  START_EVENT.  This removed all the JNDI named resources
  but the code which runs at webapp startup which creates
  the JNDI named resources is not run on a reload.
  
  I fixed this by removing the START and STOP events and
  adding BEFORE_STOP_EVENT and AFTER_START_EVENT
  lifecycle events whose only purpose is to bind or unbind the
  ClassLoader to the JNDI context.
  
  Defined JNDI resources are now preserved on a web app reload.
  
  Revision  Changes    Path
  1.20      +43 -18    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/NamingContextListener.java
  
  Index: NamingContextListener.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/NamingContextListener.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- NamingContextListener.java        25 Jun 2002 22:29:23 -0000      1.19
  +++ NamingContextListener.java        13 Nov 2002 02:23:10 -0000      1.20
  @@ -293,26 +293,13 @@
                   log(sm.getString("naming.namingContextCreationFailed", e));
               }
   
  -            // Binding the naming context to the class loader
  -            if (container instanceof Context) {
  -                // Setting the context in read only mode
  -                ContextAccessController.setReadOnly(getName());
  -                try {
  -                    ContextBindings.bindClassLoader
  -                        (container, container, 
  -                         ((Container) container).getLoader().getClassLoader());
  -                } catch (NamingException e) {
  -                    log(sm.getString("naming.bindFailed", e));
  -                }
  -            }
  -
               if (container instanceof Server) {
                   namingResources.addPropertyChangeListener(this);
                   org.apache.naming.factory.ResourceLinkFactory.setGlobalContext
                       (namingContext);
                   try {
                       ContextBindings.bindClassLoader
  -                        (container, container, 
  +                        (container, container,
                            this.getClass().getClassLoader());
                   } catch (NamingException e) {
                       log(sm.getString("naming.bindFailed", e));
  @@ -321,9 +308,47 @@
                       ((StandardServer) container).setGlobalNamingContext
                           (namingContext);
                   }
  +            } else if (container instanceof Context) {
  +                // Setting the context in read only mode
  +                ContextAccessController.setReadOnly(getName());
  +                try {
  +                    ContextBindings.bindClassLoader
  +                        (container, container,
  +                         ((Container) container).getLoader().getClassLoader());
  +                } catch (NamingException e) {
  +                    log(sm.getString("naming.bindFailed", e));
  +                }
               }
   
               initialized = true;
  +
  +        } else if (event.getType() == Lifecycle.AFTER_START_EVENT ) {
  +            // Used at end of a Web Application Context reload
  +            if (container instanceof Context) {
  +                // Setting the context in read only mode
  +                ContextAccessController.setReadOnly(getName());
  +                try {
  +                    ContextBindings.bindClassLoader
  +                        (container, container,
  +                         ((Container) container).getLoader().getClassLoader());
  +                } catch (NamingException e) {
  +                    log(sm.getString("naming.bindFailed", e));
  +                }
  +            }
  +
  +        } else if (event.getType() == Lifecycle.BEFORE_STOP_EVENT) {
  +            // Used when starting a Web Application Context reload
  +            if (!initialized)
  +                return;
  +
  +            // Setting the context in read/write mode
  +            ContextAccessController.setWritable(getName(), container);
  +
  +            if (container instanceof Context) {
  +                ContextBindings.unbindClassLoader
  +                    (container, container,
  +                     ((Container) container).getLoader().getClassLoader());
  +            }
   
           } else if (event.getType() == Lifecycle.STOP_EVENT) {
   
  
  
  
  1.114     +6 -6      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -r1.113 -r1.114
  --- StandardContext.java      26 Sep 2002 10:25:03 -0000      1.113
  +++ StandardContext.java      13 Nov 2002 02:23:10 -0000      1.114
  @@ -2486,7 +2486,7 @@
           if (isUseNaming()) {
               // Start
               namingContextListener.lifecycleEvent
  -                (new LifecycleEvent(this, Lifecycle.STOP_EVENT));
  +                (new LifecycleEvent(this, Lifecycle.BEFORE_STOP_EVENT));
           }
   
           // Binding thread
  @@ -2522,7 +2522,7 @@
           if (isUseNaming()) {
               // Start
               namingContextListener.lifecycleEvent
  -                (new LifecycleEvent(this, Lifecycle.START_EVENT));
  +                (new LifecycleEvent(this, Lifecycle.AFTER_START_EVENT));
           }
   
           // Binding thread
  
  
  
  1.8       +10 -6     
jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java
  
  Index: ContextBindings.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/ContextBindings.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ContextBindings.java      31 May 2002 02:55:21 -0000      1.7
  +++ ContextBindings.java      13 Nov 2002 02:23:11 -0000      1.8
  @@ -309,8 +309,12 @@
               if (context == null)
                   throw new NamingException
                       (sm.getString("contextBindings.unknownContext", name));
  -            clBindings.put(classLoader, context);
  -            clNameBindings.put(classLoader, name);
  +            Object n = clNameBindings.get(classLoader);
  +            // Only bind CL if it isn't already bound to the context
  +            if (n == null) {
  +                clBindings.put(classLoader, context);
  +                clNameBindings.put(classLoader, name);
  +            }
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@;jakarta.apache.org>

Reply via email to