tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1715897 - in /tomcat/tc8.0.x/trunk: java/org/apache/catalina/ java/org/apache/catalina/connector/ java/org/apache/coyote/ java/org/apache/tomcat/ webapps/docs/
Date Mon, 23 Nov 2015 17:23:59 GMT
Author: remm
Date: Mon Nov 23 17:23:59 2015
New Revision: 1715897

URL: http://svn.apache.org/viewvc?rev=1715897&view=rev
Log:
Extract Context.bind and unbind to an interface to make the CL bind cleaner for the upgrade
code (including using a PA if needed).

Added:
    tomcat/tc8.0.x/trunk/java/org/apache/tomcat/ContextBind.java
      - copied unchanged from r1715866, tomcat/trunk/java/org/apache/tomcat/ContextBind.java
Modified:
    tomcat/tc8.0.x/trunk/java/org/apache/catalina/Context.java
    tomcat/tc8.0.x/trunk/java/org/apache/catalina/connector/Request.java
    tomcat/tc8.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java
    tomcat/tc8.0.x/trunk/java/org/apache/coyote/UpgradeToken.java
    tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc8.0.x/trunk/java/org/apache/catalina/Context.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/catalina/Context.java?rev=1715897&r1=1715896&r2=1715897&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/catalina/Context.java Mon Nov 23 17:23:59 2015
@@ -29,6 +29,7 @@ import javax.servlet.ServletSecurityElem
 import javax.servlet.descriptor.JspConfigDescriptor;
 
 import org.apache.catalina.deploy.NamingResourcesImpl;
+import org.apache.tomcat.ContextBind;
 import org.apache.tomcat.InstanceManager;
 import org.apache.tomcat.JarScanner;
 import org.apache.tomcat.util.descriptor.web.ApplicationParameter;
@@ -57,7 +58,7 @@ import org.apache.tomcat.util.http.Cooki
  *
  * @author Craig R. McClanahan
  */
-public interface Context extends Container {
+public interface Context extends Container, ContextBind {
 
 
     // ----------------------------------------------------- Manifest Constants
@@ -1610,45 +1611,6 @@ public interface Context extends Contain
     public Map<String, String> findPreDestroyMethods();
 
     /**
-     * Change the current thread context class loader to the web application
-     * class loader. If no web application class loader is defined, or if the
-     * current thread is already using the web application class loader then no
-     * change will be made. If the class loader is changed and a
-     * {@link ThreadBindingListener} is configured then
-     * {@link ThreadBindingListener#bind()} will be called after the change has
-     * been made.
-     *
-     * @param usePrivilegedAction
-     *          Should a {@link java.security.PrivilegedAction} be used when
-     *          obtaining the current thread context class loader and setting
-     *          the new one?
-     * @param originalClassLoader
-     *          The current class loader if known to save this method having to
-     *          look it up
-     *
-     * @return If the class loader has been changed by the method it will return
-     *         the thread context class loader in use when the method was
-     *         called. If no change was made then this method returns null.
-     */
-    public ClassLoader bind(boolean usePrivilegedAction, ClassLoader originalClassLoader);
-
-    /**
-     * Restore the current thread context class loader to the original class
-     * loader in used before {@link #bind(boolean, ClassLoader)} was called. If
-     * no original class loader is passed to this method then no change will be
-     * made. If the class loader is changed and a {@link ThreadBindingListener}
-     * is configured then {@link ThreadBindingListener#unbind()} will be called
-     * before the change is made.
-     *
-     * @param usePrivilegedAction
-     *          Should a {@link java.security.PrivilegedAction} be used when
-     *          setting the current thread context class loader?
-     * @param originalClassLoader
-     *          The class loader to restore as the thread context class loader
-     */
-    public void unbind(boolean usePrivilegedAction, ClassLoader originalClassLoader);
-
-    /**
      * Obtain the token necessary for operations on the associated JNDI naming
      * context.
      */

Modified: tomcat/tc8.0.x/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/catalina/connector/Request.java?rev=1715897&r1=1715896&r2=1715897&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/catalina/connector/Request.java Mon Nov 23 17:23:59
2015
@@ -1892,7 +1892,7 @@ public class Request
             throw new ServletException(e);
         }
         UpgradeToken upgradeToken = new UpgradeToken(handler,
-                getContext().getLoader().getClassLoader(), instanceManager);
+                getContext(), instanceManager);
 
         coyoteRequest.action(ActionCode.UPGRADE, upgradeToken);
 

Modified: tomcat/tc8.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java?rev=1715897&r1=1715896&r2=1715897&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/coyote/AbstractProtocol.java Mon Nov 23 17:23:59
2015
@@ -702,14 +702,11 @@ public abstract class AbstractProtocol<S
                         if (upgradeToken.getInstanceManager() == null) {
                             httpUpgradeHandler.init((WebConnection) processor);
                         } else {
-                            Thread thread = Thread.currentThread();
-                            // Set context class loader environment for user class call
-                            ClassLoader originalClassLoader = thread.getContextClassLoader();
+                            ClassLoader oldCL = upgradeToken.getContextBind().bind(false,
null);
                             try {
-                                thread.setContextClassLoader(upgradeToken.getApplicationClassLoader());
                                 httpUpgradeHandler.init((WebConnection) processor);
                             } finally {
-                                thread.setContextClassLoader(originalClassLoader);
+                                upgradeToken.getContextBind().unbind(false, oldCL);
                             }
                         }
                     }
@@ -764,15 +761,12 @@ public abstract class AbstractProtocol<S
                         if (instanceManager == null) {
                             httpUpgradeHandler.destroy();
                         } else {
-                            Thread thread = Thread.currentThread();
-                            // Set context class loader environment for user class call
-                            ClassLoader originalClassLoader = thread.getContextClassLoader();
+                            ClassLoader oldCL = upgradeToken.getContextBind().bind(false,
null);
                             try {
-                                thread.setContextClassLoader(upgradeToken.getApplicationClassLoader());
                                 httpUpgradeHandler.destroy();
                                 instanceManager.destroyInstance(httpUpgradeHandler);
                             } finally {
-                                thread.setContextClassLoader(originalClassLoader);
+                                upgradeToken.getContextBind().unbind(false, oldCL);
                             }
                         }
                     } else {

Modified: tomcat/tc8.0.x/trunk/java/org/apache/coyote/UpgradeToken.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/java/org/apache/coyote/UpgradeToken.java?rev=1715897&r1=1715896&r2=1715897&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/java/org/apache/coyote/UpgradeToken.java (original)
+++ tomcat/tc8.0.x/trunk/java/org/apache/coyote/UpgradeToken.java Mon Nov 23 17:23:59 2015
@@ -19,6 +19,7 @@ package org.apache.coyote;
 
 import javax.servlet.http.HttpUpgradeHandler;
 
+import org.apache.tomcat.ContextBind;
 import org.apache.tomcat.InstanceManager;
 
 /**
@@ -26,19 +27,19 @@ import org.apache.tomcat.InstanceManager
  */
 public final class UpgradeToken {
 
-    private final ClassLoader applicationClassLoader;
+    private final ContextBind contextBind;
     private final HttpUpgradeHandler httpUpgradeHandler;
     private final InstanceManager instanceManager;
 
     public UpgradeToken(HttpUpgradeHandler httpUpgradeHandler,
-            ClassLoader applicationClassLoader, InstanceManager instanceManager) {
-        this.applicationClassLoader = applicationClassLoader;
+            ContextBind contextBind, InstanceManager instanceManager) {
+        this.contextBind = contextBind;
         this.httpUpgradeHandler = httpUpgradeHandler;
         this.instanceManager = instanceManager;
     }
 
-    public final ClassLoader getApplicationClassLoader() {
-        return applicationClassLoader;
+    public final ContextBind getContextBind() {
+        return contextBind;
     }
 
     public final HttpUpgradeHandler getHttpUpgradeHandler() {

Modified: tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml?rev=1715897&r1=1715896&r2=1715897&view=diff
==============================================================================
--- tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.0.x/trunk/webapps/docs/changelog.xml Mon Nov 23 17:23:59 2015
@@ -58,6 +58,14 @@
       </fix>
     </changelog>
   </subection>
+  <subsection name="Coyote">
+    <changelog>
+      <fix>
+        Improve upgrade context classloader handling by using Context.bind and
+        unbind. (remm)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Cluster">
     <changelog>
       <fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message