You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/01/23 13:17:00 UTC
svn commit: r1560656 -
/tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java
Author: markt
Date: Thu Jan 23 12:17:00 2014
New Revision: 1560656
URL: http://svn.apache.org/r1560656
Log:
Migrate StandardHostValve to use Context bind/unbind
Modified:
tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java?rev=1560656&r1=1560655&r2=1560656&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java Thu Jan 23 12:17:00 2014
@@ -14,14 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
package org.apache.catalina.core;
-
import java.io.IOException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import javax.servlet.DispatcherType;
import javax.servlet.RequestDispatcher;
@@ -31,7 +26,6 @@ import javax.servlet.http.HttpServletRes
import org.apache.catalina.Context;
import org.apache.catalina.Globals;
-import org.apache.catalina.ThreadBindingListener;
import org.apache.catalina.Wrapper;
import org.apache.catalina.comet.CometEvent;
import org.apache.catalina.connector.ClientAbortException;
@@ -44,7 +38,6 @@ import org.apache.tomcat.util.ExceptionU
import org.apache.tomcat.util.descriptor.web.ErrorPage;
import org.apache.tomcat.util.res.StringManager;
-
/**
* Valve that implements the default basic behavior for the
* <code>StandardHost</code> container implementation.
@@ -56,7 +49,6 @@ import org.apache.tomcat.util.res.String
* @author Remy Maucherat
* @version $Id$
*/
-
final class StandardHostValve extends ValveBase {
private static final Log log = LogFactory.getLog(StandardHostValve.class);
@@ -125,22 +117,8 @@ final class StandardHostValve extends Va
return;
}
- // Bind the context CL to the current thread
- if( context.getLoader() != null ) {
- // Not started - it should check for availability first
- // This should eventually move to Engine, it's generic.
- if (Globals.IS_SECURITY_ENABLED) {
- PrivilegedAction<Void> pa = new PrivilegedSetTccl(
- context.getLoader().getClassLoader(),
- context.getThreadBindingListener(),
- true);
- AccessController.doPrivileged(pa);
- } else {
- Thread.currentThread().setContextClassLoader
- (context.getLoader().getClassLoader());
- context.getThreadBindingListener().bind();
- }
- }
+ context.bind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER);
+
if (request.isAsyncSupported()) {
request.setAsyncSupported(context.getPipeline().isAsyncSupported());
}
@@ -203,15 +181,7 @@ final class StandardHostValve extends Va
request.getSession(false);
}
- // Restore the context classloader
- if (Globals.IS_SECURITY_ENABLED) {
- PrivilegedAction<Void> pa = new PrivilegedSetTccl(MY_CLASSLOADER,
- context.getThreadBindingListener(), false);
- AccessController.doPrivileged(pa);
- } else {
- context.getThreadBindingListener().unbind();
- Thread.currentThread().setContextClassLoader(MY_CLASSLOADER);
- }
+ context.unbind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER);
}
@@ -232,14 +202,7 @@ final class StandardHostValve extends Va
// Select the Context to be used for this Request
Context context = request.getContext();
- // Bind the context CL to the current thread
- if( context.getLoader() != null ) {
- // Not started - it should check for availability first
- // This should eventually move to Engine, it's generic.
- Thread.currentThread().setContextClassLoader
- (context.getLoader().getClassLoader());
- context.getThreadBindingListener().bind();
- }
+ context.bind(false, MY_CLASSLOADER);
// Ask this Context to process this request
context.getPipeline().getFirst().event(request, response, event);
@@ -264,10 +227,7 @@ final class StandardHostValve extends Va
}
// Restore the context classloader
- context.getThreadBindingListener().unbind();
- Thread.currentThread().setContextClassLoader
- (StandardHostValve.class.getClassLoader());
-
+ context.unbind(false, MY_CLASSLOADER);
}
@@ -511,29 +471,4 @@ final class StandardHostValve extends Va
return (null);
}
-
-
- private static class PrivilegedSetTccl implements PrivilegedAction<Void> {
-
- private final ClassLoader cl;
- private final ThreadBindingListener tbl;
- private final boolean bind;
-
- PrivilegedSetTccl(ClassLoader cl, ThreadBindingListener tbl, boolean bind) {
- this.cl = cl;
- this.bind = bind;
- this.tbl = tbl;
- }
-
- @Override
- public Void run() {
- Thread.currentThread().setContextClassLoader(cl);
- if (bind) {
- tbl.bind();
- } else {
- tbl.unbind();
- }
- return null;
- }
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org