Author: kkolinko Date: Thu May 8 18:01:35 2014 New Revision: 1593356 URL: http://svn.apache.org/r1593356 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56472#c1
Per my comment on that issue, always set 'NamingContextListener.initialized' field to 'true' so that its cleanup on configure_stop event is not skipped. Modified: tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1593356&r1=1593355&r2=1593356&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/NamingContextListener.java Thu May 8 18:01:35 2014 @@ -231,98 +231,105 @@ public class NamingContextListener if (initialized) return; - Hashtable<String, Object> contextEnv = new Hashtable<>(); try { - namingContext = new NamingContext(contextEnv, getName()); - } catch (NamingException e) { - // Never happens - } - ContextAccessController.setSecurityToken(getName(), token); - ContextAccessController.setSecurityToken(container, token); - ContextBindings.bindContext(container, namingContext, token); - if( log.isDebugEnabled() ) { - log.debug("Bound " + container ); - } - - // Configure write when read-only behaviour - namingContext.setExceptionOnFailedWrite( - getExceptionOnFailedWrite()); - - // Setting the context in read/write mode - ContextAccessController.setWritable(getName(), token); + Hashtable<String, Object> contextEnv = new Hashtable<>(); + try { + namingContext = new NamingContext(contextEnv, getName()); + } catch (NamingException e) { + // Never happens + } + ContextAccessController.setSecurityToken(getName(), token); + ContextAccessController.setSecurityToken(container, token); + ContextBindings.bindContext(container, namingContext, token); + if( log.isDebugEnabled() ) { + log.debug("Bound " + container ); + } - try { - createNamingContext(); - } catch (NamingException e) { - logger.error - (sm.getString("naming.namingContextCreationFailed", e)); - } + // Configure write when read-only behaviour + namingContext.setExceptionOnFailedWrite( + getExceptionOnFailedWrite()); - namingResources.addPropertyChangeListener(this); + // Setting the context in read/write mode + ContextAccessController.setWritable(getName(), token); - // 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, token, - ((Context) container).getLoader().getClassLoader()); + createNamingContext(); } catch (NamingException e) { - logger.error(sm.getString("naming.bindFailed", e)); + logger.error + (sm.getString("naming.namingContextCreationFailed", e)); } - } - if (container instanceof Server) { - org.apache.naming.factory.ResourceLinkFactory.setGlobalContext - (namingContext); - try { - ContextBindings.bindClassLoader(container, token, - this.getClass().getClassLoader()); - } catch (NamingException e) { - logger.error(sm.getString("naming.bindFailed", e)); + namingResources.addPropertyChangeListener(this); + + // 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, token, + ((Context) container).getLoader().getClassLoader()); + } catch (NamingException e) { + logger.error(sm.getString("naming.bindFailed", e)); + } } - if (container instanceof StandardServer) { - ((StandardServer) container).setGlobalNamingContext + + if (container instanceof Server) { + org.apache.naming.factory.ResourceLinkFactory.setGlobalContext (namingContext); + try { + ContextBindings.bindClassLoader(container, token, + this.getClass().getClassLoader()); + } catch (NamingException e) { + logger.error(sm.getString("naming.bindFailed", e)); + } + if (container instanceof StandardServer) { + ((StandardServer) container).setGlobalNamingContext + (namingContext); + } } - } - initialized = true; + } finally { + // Regardless of success, so that we can do cleanup on configure_stop + initialized = true; + } } else if (Lifecycle.CONFIGURE_STOP_EVENT.equals(event.getType())) { if (!initialized) return; - // Setting the context in read/write mode - ContextAccessController.setWritable(getName(), token); - ContextBindings.unbindContext(container, token); + try { + // Setting the context in read/write mode + ContextAccessController.setWritable(getName(), token); + ContextBindings.unbindContext(container, token); - if (container instanceof Context) { - ContextBindings.unbindClassLoader(container, token, - ((Context) container).getLoader().getClassLoader()); - } + if (container instanceof Context) { + ContextBindings.unbindClassLoader(container, token, + ((Context) container).getLoader().getClassLoader()); + } - if (container instanceof Server) { - namingResources.removePropertyChangeListener(this); - ContextBindings.unbindClassLoader(container, token, - this.getClass().getClassLoader()); - } + if (container instanceof Server) { + namingResources.removePropertyChangeListener(this); + ContextBindings.unbindClassLoader(container, token, + this.getClass().getClassLoader()); + } - ContextAccessController.unsetSecurityToken(getName(), token); - ContextAccessController.unsetSecurityToken(container, token); + ContextAccessController.unsetSecurityToken(getName(), token); + ContextAccessController.unsetSecurityToken(container, token); - // unregister mbeans. - Collection<ObjectName> names = objectNames.values(); - for (ObjectName objectName : names) { - Registry.getRegistry(null, null).unregisterComponent(objectName); + // unregister mbeans. + Collection<ObjectName> names = objectNames.values(); + for (ObjectName objectName : names) { + Registry.getRegistry(null, null).unregisterComponent(objectName); + } + } finally { + objectNames.clear(); + + namingContext = null; + envCtx = null; + compCtx = null; + initialized = false; } - objectNames.clear(); - - namingContext = null; - envCtx = null; - compCtx = null; - initialized = false; } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1593356&r1=1593355&r2=1593356&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Thu May 8 18:01:35 2014 @@ -153,6 +153,10 @@ (violetagg) </add> <fix> + <bug>56472</bug>: Allow NamingContextListener to clean up on stop if its + start failed. (kkolinko) + </fix> + <fix> <bug>56481</bug>: Work around case insensitivity issue in <code>URLClassLoader</code> exposed by some recent refactoring. (markt) </fix> @@ -167,7 +171,7 @@ </add> <fix> Make the naming context tokens for containers more robust by using a - separate object. (markt) + separate object. (markt/kkolinko) </fix> </changelog> </subsection> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org