Author: markt
Date: Sun Jun 11 10:58:48 2006
New Revision: 413490
URL: http://svn.apache.org/viewvc?rev=413490&view=rev
Log:
Port fix for 38795 to ensure the thread's contextClassLoader is always reset on
an exception. Based on a port provided by Darryl Miles.
Modified:
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardContext.java
Modified:
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardContext.java?rev=413490&r1=413489&r2=413490&view=diff
==============================================================================
---
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardContext.java
(original)
+++
tomcat/container/branches/tc4.1.x/catalina/src/share/org/apache/catalina/core/StandardContext.java
Sun Jun 11 10:58:48 2006
@@ -2493,49 +2493,53 @@
// Binding thread
ClassLoader oldCCL = bindThread();
- // Shut down filters
- filterStop();
-
- // Shut down our session manager
- if ((manager != null) && (manager instanceof Lifecycle)) {
- try {
- ((Lifecycle) manager).stop();
- } catch (LifecycleException e) {
- log(sm.getString("standardContext.stoppingManager"), e);
- }
- }
-
- // Shut down the current version of all active servlets
- Container children[] = findChildren();
- for (int i = 0; i < children.length; i++) {
- Wrapper wrapper = (Wrapper) children[i];
- if (wrapper instanceof Lifecycle) {
+ Container children[] = new Container[0];
+
+ try {
+ // Shut down filters
+ filterStop();
+
+ // Shut down our session manager
+ if ((manager != null) && (manager instanceof Lifecycle)) {
try {
- ((Lifecycle) wrapper).stop();
+ ((Lifecycle) manager).stop();
} catch (LifecycleException e) {
- log(sm.getString("standardContext.stoppingWrapper",
- wrapper.getName()),
- e);
+ log(sm.getString("standardContext.stoppingManager"), e);
}
}
+
+ // Shut down the current version of all active servlets
+ children = findChildren();
+ for (int i = 0; i < children.length; i++) {
+ Wrapper wrapper = (Wrapper) children[i];
+ if (wrapper instanceof Lifecycle) {
+ try {
+ ((Lifecycle) wrapper).stop();
+ } catch (LifecycleException e) {
+ log(sm.getString("standardContext.stoppingWrapper",
+ wrapper.getName()),
+ e);
+ }
+ }
+ }
+
+ // Shut down application event listeners
+ listenerStop();
+
+ // Clear all application-originated servlet context attributes
+ if (context != null)
+ context.clearAttributes();
+
+ if (isUseNaming()) {
+ // Stop
+ namingContextListener.lifecycleEvent
+ (new LifecycleEvent(this, Lifecycle.STOP_EVENT));
+ }
+ } finally {
+ // Binding thread
+ unbindThread(oldCCL);
}
-
- // Shut down application event listeners
- listenerStop();
-
- // Clear all application-originated servlet context attributes
- if (context != null)
- context.clearAttributes();
-
- if (isUseNaming()) {
- // Stop
- namingContextListener.lifecycleEvent
- (new LifecycleEvent(this, Lifecycle.STOP_EVENT));
- }
-
- // Binding thread
- unbindThread(oldCCL);
-
+
// Shut down our application class loader
if ((loader != null) && (loader instanceof Lifecycle)) {
try {
@@ -2548,18 +2552,20 @@
// Binding thread
oldCCL = bindThread();
- // Restart our application class loader
- if ((loader != null) && (loader instanceof Lifecycle)) {
- try {
- ((Lifecycle) loader).start();
- } catch (LifecycleException e) {
- log(sm.getString("standardContext.startingLoader"), e);
+ try {
+ // Restart our application class loader
+ if ((loader != null) && (loader instanceof Lifecycle)) {
+ try {
+ ((Lifecycle) loader).start();
+ } catch (LifecycleException e) {
+ log(sm.getString("standardContext.startingLoader"), e);
+ }
}
+ } finally {
+ // Binding thread
+ unbindThread(oldCCL);
}
-
- // Binding thread
- unbindThread(oldCCL);
-
+
// Create and register the associated naming context, if internal
// naming is used
boolean ok = true;
@@ -2572,56 +2578,58 @@
// Binding thread
oldCCL = bindThread();
- // Restore the "Welcome Files" and "Resources" context attributes
- postResources();
- postWelcomeFiles();
-
- // Restart our application event listeners and filters
- if (ok) {
- if (!listenerStart()) {
- log(sm.getString("standardContext.listenerStartFailed"));
- ok = false;
+ try {
+ // Restore the "Welcome Files" and "Resources" context attributes
+ postResources();
+ postWelcomeFiles();
+
+ // Restart our application event listeners and filters
+ if (ok) {
+ if (!listenerStart()) {
+ log(sm.getString("standardContext.listenerStartFailed"));
+ ok = false;
+ }
}
- }
- if (ok) {
- if (!filterStart()) {
- log(sm.getString("standardContext.filterStartFailed"));
- ok = false;
+ if (ok) {
+ if (!filterStart()) {
+ log(sm.getString("standardContext.filterStartFailed"));
+ ok = false;
+ }
}
- }
-
- // Restart our currently defined servlets
- for (int i = 0; i < children.length; i++) {
- if (!ok)
- break;
- Wrapper wrapper = (Wrapper) children[i];
- if (wrapper instanceof Lifecycle) {
+
+ // Restart our currently defined servlets
+ for (int i = 0; i < children.length; i++) {
+ if (!ok)
+ break;
+ Wrapper wrapper = (Wrapper) children[i];
+ if (wrapper instanceof Lifecycle) {
+ try {
+ ((Lifecycle) wrapper).start();
+ } catch (LifecycleException e) {
+ log(sm.getString("standardContext.startingWrapper",
+ wrapper.getName()),
+ e);
+ ok = false;
+ }
+ }
+ }
+
+ // Reinitialize all load on startup servlets
+ loadOnStartup(children);
+
+ // Restart our session manager (AFTER naming context
recreated/bound)
+ if ((manager != null) && (manager instanceof Lifecycle)) {
try {
- ((Lifecycle) wrapper).start();
+ ((Lifecycle) manager).start();
} catch (LifecycleException e) {
- log(sm.getString("standardContext.startingWrapper",
- wrapper.getName()),
- e);
- ok = false;
+ log(sm.getString("standardContext.startingManager"), e);
}
}
+ } finally {
+ // Unbinding thread
+ unbindThread(oldCCL);
}
-
- // Reinitialize all load on startup servlets
- loadOnStartup(children);
-
- // Restart our session manager (AFTER naming context recreated/bound)
- if ((manager != null) && (manager instanceof Lifecycle)) {
- try {
- ((Lifecycle) manager).start();
- } catch (LifecycleException e) {
- log(sm.getString("standardContext.startingManager"), e);
- }
- }
-
- // Unbinding thread
- unbindThread(oldCCL);
-
+
// Start accepting requests again
if (ok) {
log(sm.getString("standardContext.reloadingCompleted"));
@@ -3586,9 +3594,9 @@
if (debug >= 1)
log("Processing standard container startup");
- if (ok) {
-
- try {
+ try {
+
+ if (ok) {
addDefaultMapper(this.mapperClass);
started = true;
@@ -3637,12 +3645,12 @@
if ((manager != null) && (manager instanceof Lifecycle))
((Lifecycle) manager).start();
- } finally {
- // Unbinding thread
- unbindThread(oldCCL);
}
-
+ } finally {
+ // Unbinding thread
+ unbindThread(oldCCL);
}
+
if (!getConfigured())
ok = false;
@@ -3654,26 +3662,28 @@
// Binding thread
oldCCL = bindThread();
- // Create context attributes that will be required
- if (ok) {
- if (debug >= 1)
- log("Posting standard context attributes");
- postWelcomeFiles();
- }
-
- // Configure and call application event listeners and filters
- if (ok) {
- if (!listenerStart())
- ok = false;
- }
- if (ok) {
- if (!filterStart())
- ok = false;
+ try {
+ // Create context attributes that will be required
+ if (ok) {
+ if (debug >= 1)
+ log("Posting standard context attributes");
+ postWelcomeFiles();
+ }
+
+ // Configure and call application event listeners and filters
+ if (ok) {
+ if (!listenerStart())
+ ok = false;
+ }
+ if (ok) {
+ if (!filterStart())
+ ok = false;
+ }
+ } finally {
+ // Unbinding thread
+ unbindThread(oldCCL);
}
-
- // Unbinding thread
- unbindThread(oldCCL);
-
+
// Set available status depending upon startup success
if (ok) {
if (debug >= 1)
@@ -3695,8 +3705,11 @@
// Load and initialize all "load on startup" servlets
oldCCL = bindThread();
- loadOnStartup(findChildren());
- unbindThread(oldCCL);
+ try {
+ loadOnStartup(findChildren());
+ } finally {
+ unbindThread(oldCCL);
+ }
}
@@ -3724,24 +3737,24 @@
// Binding thread
ClassLoader oldCCL = bindThread();
- // Stop our filters
- filterStop();
-
- // Finalize our character set mapper
- setCharsetMapper(null);
-
- if ((manager != null) && (manager instanceof Lifecycle)) {
- ((Lifecycle) manager).stop();
- }
-
- // Normal container shutdown processing
- if (debug >= 1)
- log("Processing standard container shutdown");
- // Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
- started = false;
-
try {
+
+ // Stop our filters
+ filterStop();
+
+ // Finalize our character set mapper
+ setCharsetMapper(null);
+
+ if ((manager != null) && (manager instanceof Lifecycle)) {
+ ((Lifecycle) manager).stop();
+ }
+
+ // Normal container shutdown processing
+ if (debug >= 1)
+ log("Processing standard container shutdown");
+ // Notify our interested LifecycleListeners
+ lifecycle.fireLifecycleEvent(STOP_EVENT, null);
+ started = false;
// Stop the Valves in our pipeline (including the basic), if any
if (pipeline instanceof Lifecycle) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]