Author: kkolinko
Date: Thu May 8 19:19:42 2014
New Revision: 1593389
URL: http://svn.apache.org/r1593389
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.
It is backport of r1593356 from tomcat/trunk.
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1593356
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java?rev=1593389&r1=1593388&r2=1593389&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/NamingContextListener.java
Thu May 8 19:19:42 2014
@@ -246,102 +246,109 @@ public class NamingContextListener
if (initialized)
return;
- Hashtable<String, Object> contextEnv = new Hashtable<String,
Object>();
try {
- namingContext = new NamingContext(contextEnv, getName());
- } catch (NamingException e) {
- // Never happens
- }
- ContextAccessController.setSecurityToken(getName(), container);
- ContextAccessController.setSecurityToken(container, container);
- ContextBindings.bindContext(container, namingContext, container);
- if( log.isDebugEnabled() ) {
- log.debug("Bound " + container );
- }
+ Hashtable<String, Object> contextEnv = new Hashtable<String,
Object>();
+ try {
+ namingContext = new NamingContext(contextEnv, getName());
+ } catch (NamingException e) {
+ // Never happens
+ }
+ ContextAccessController.setSecurityToken(getName(), container);
+ ContextAccessController.setSecurityToken(container, container);
+ ContextBindings.bindContext(container, namingContext,
container);
+ if( log.isDebugEnabled() ) {
+ log.debug("Bound " + container );
+ }
- // Configure write when read-only behaviour
- namingContext.setExceptionOnFailedWrite(
- getExceptionOnFailedWrite());
+ // Configure write when read-only behaviour
+ namingContext.setExceptionOnFailedWrite(
+ getExceptionOnFailedWrite());
- // Setting the context in read/write mode
- ContextAccessController.setWritable(getName(), container);
+ // Setting the context in read/write mode
+ ContextAccessController.setWritable(getName(), container);
- try {
- createNamingContext();
- } catch (NamingException e) {
- logger.error
+ try {
+ createNamingContext();
+ } catch (NamingException e) {
+ logger.error
(sm.getString("naming.namingContextCreationFailed", e));
- }
+ }
- namingResources.addPropertyChangeListener(this);
+ 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
+ // 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) {
- logger.error(sm.getString("naming.bindFailed", e));
+ ((Container)
container).getLoader().getClassLoader());
+ } catch (NamingException e) {
+ logger.error(sm.getString("naming.bindFailed", e));
+ }
}
- }
- if (container instanceof Server) {
- org.apache.naming.factory.ResourceLinkFactory.setGlobalContext
+ if (container instanceof Server) {
+
org.apache.naming.factory.ResourceLinkFactory.setGlobalContext
(namingContext);
- try {
- ContextBindings.bindClassLoader
+ try {
+ ContextBindings.bindClassLoader
(container, container,
- this.getClass().getClassLoader());
- } catch (NamingException e) {
- logger.error(sm.getString("naming.bindFailed", e));
- }
- if (container instanceof StandardServer) {
- ((StandardServer) container).setGlobalNamingContext
+ 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(), container);
- ContextBindings.unbindContext(container, container);
+ try {
+ // Setting the context in read/write mode
+ ContextAccessController.setWritable(getName(), container);
+ ContextBindings.unbindContext(container, container);
- if (container instanceof Context) {
- ContextBindings.unbindClassLoader
+ if (container instanceof Context) {
+ ContextBindings.unbindClassLoader
(container, container,
- ((Container) container).getLoader().getClassLoader());
- }
+ ((Container)
container).getLoader().getClassLoader());
+ }
- if (container instanceof Server) {
- namingResources.removePropertyChangeListener(this);
- ContextBindings.unbindClassLoader
+ if (container instanceof Server) {
+ namingResources.removePropertyChangeListener(this);
+ ContextBindings.unbindClassLoader
(container, container,
- this.getClass().getClassLoader());
- }
+ this.getClass().getClassLoader());
+ }
- ContextAccessController.unsetSecurityToken(getName(), container);
- ContextAccessController.unsetSecurityToken(container, container);
+ ContextAccessController.unsetSecurityToken(getName(),
container);
+ ContextAccessController.unsetSecurityToken(container,
container);
- // unregister mbeans.
- Collection<ObjectName> names = objectNames.values();
- for (ObjectName objectName : names) {
- Registry.getRegistry(null,
null).unregisterComponent(objectName);
- }
- objectNames.clear();
+ // 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;
+ namingContext = null;
+ envCtx = null;
+ compCtx = null;
+ initialized = false;
+ }
}
Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1593389&r1=1593388&r2=1593389&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu May 8 19:19:42 2014
@@ -160,6 +160,10 @@
Make the naming context tokens for containers more robust by using a
separate object. (markt/kkolinko)
</fix>
+ <fix>
+ <bug>56472</bug>: Allow NamingContextListener to clean up on stop if
its
+ start failed. (kkolinko)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]