Author: kkolinko
Date: Thu Jul 17 20:50:46 2014
New Revision: 1611472

URL: http://svn.apache.org/r1611472
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56710
Do not perform wrapper mapping if context is being reloaded,
as such mapping is useless and may fail unexpectedly.
Let mapper know that context is being reloaded.

Ignore removeWrapper(), removeWelcomeFile() calls when context is being 
reloaded,
as that is useless work.
During undeploy the context should have already been unregistered.
During reload the context will be re-registered via addContextVersion().

It is backport of r1610220

Modified:
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=1611472&r1=1611471&r2=1611472&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/LocalStrings.properties 
Thu Jul 17 20:50:46 2014
@@ -90,6 +90,7 @@ mapperListener.registerHost=Register hos
 mapperListener.unregisterHost=Unregister host [{0}] at domain [{1}] for 
connector [{2}]
 mapperListener.registerContext=Register Context [{0}] for connector [{1}]
 mapperListener.unregisterContext=Unregister Context [{0}] for connector [{1}]
+mapperListener.pauseContext=Register Context [{0}] as being reloaded for 
connector [{1}]
 mapperListener.registerWrapper=Register Wrapper [{0}] in Context [{1}] for 
connector [{2}]
 mapperListener.unregisterWrapper=Unregister Wrapper [{0}] in Context [{1}] for 
connector [{2}]
 mapperListener.addMBeanListenerFail=Failed to add MBean notification listener 
for connector [{0}] in domain [{1}]. Adding Hosts, Contexts and Wrappers will 
not be visible to the connector.

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=1611472&r1=1611471&r2=1611472&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java 
Thu Jul 17 20:50:46 2014
@@ -391,11 +391,6 @@ public class MapperListener extends Life
      */
     private void unregisterContext(Context context) {
 
-        // Don't un-map a context that is paused
-        if (context.getPaused()){
-            return;
-        }
-
         String contextPath = context.getPath();
         if ("/".equals(contextPath)) {
             contextPath = "";
@@ -407,8 +402,23 @@ public class MapperListener extends Life
                     contextPath, connector));
         }
 
-        mapper.removeContextVersion(hostName, contextPath,
-                context.getWebappVersion());
+        if (context.getPaused()) {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("mapperListener.pauseContext",
+                        contextPath, connector));
+            }
+
+            mapper.pauseContextVersion(context, hostName, contextPath,
+                    context.getWebappVersion());
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("mapperListener.unregisterContext",
+                        contextPath, connector));
+            }
+
+            mapper.removeContextVersion(hostName, contextPath,
+                    context.getWebappVersion());
+        }
     }
 
 
@@ -482,12 +492,7 @@ public class MapperListener extends Life
             if (obj instanceof Wrapper) {
                 unregisterWrapper((Wrapper) obj);
             } else if (obj instanceof Context) {
-                Context c = (Context) obj;
-                // Only unregister if not paused. If paused, need to keep
-                // registration in place to prevent 404's during reload
-                if (!c.getPaused()) {
-                    unregisterContext(c);
-                }
+                unregisterContext((Context) obj);
             } else if (obj instanceof Host) {
                 unregisterHost((Host) obj);
             }

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?rev=1611472&r1=1611471&r2=1611472&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 
(original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 
Thu Jul 17 20:50:46 2014
@@ -344,6 +344,27 @@ public final class Mapper {
     }
 
 
+    /**
+     * Mark a context as being reloaded. Reversion of this state is performed
+     * by calling <code>addContextVersion(...)</code> when context starts up.
+     *
+     * @param ctxt      The actual context
+     * @param hostName  Virtual host name this context belongs to
+     * @param contextPath Context path
+     * @param version   Context version
+     */
+    public void pauseContextVersion(Object ctxt, String hostName,
+            String contextPath, String version) {
+
+        ContextVersion contextVersion = findContextVersion(hostName,
+                contextPath, version, true);
+        if (contextVersion == null || !ctxt.equals(contextVersion.object)) {
+            return;
+        }
+        contextVersion.markPaused();
+    }
+
+
     private ContextVersion findContextVersion(String hostName,
             String contextPath, String version, boolean silent) {
         Host host = exactFind(hosts, hostName);
@@ -504,7 +525,7 @@ public final class Mapper {
             String version, String path) {
         ContextVersion contextVersion = findContextVersion(hostName,
                 contextPath, version, true);
-        if (contextVersion == null) {
+        if (contextVersion == null || contextVersion.isPaused()) {
             return;
         }
         removeWrapper(contextVersion, path);
@@ -609,7 +630,7 @@ public final class Mapper {
             String version, String welcomeFile) {
         ContextVersion contextVersion = findContextVersion(hostName,
                 contextPath, version, false);
-        if (contextVersion == null) {
+        if (contextVersion == null || contextVersion.isPaused()) {
             return;
         }
         int match = -1;
@@ -789,6 +810,7 @@ public final class Mapper {
         }
         if (contextVersion == null) {
             // Return the latest version
+            // The versions array is known to contain at least one element
             contextVersion = contextVersions[versionCount - 1];
         }
 
@@ -796,7 +818,9 @@ public final class Mapper {
         mappingData.contextSlashCount = contextVersion.slashCount;
 
         // Wrapper mapping
-        internalMapWrapper(contextVersion, uri, mappingData);
+        if (!contextVersion.isPaused()) {
+            internalMapWrapper(contextVersion, uri, mappingData);
+        }
 
     }
 
@@ -1639,6 +1663,7 @@ public final class Mapper {
         public Wrapper[] wildcardWrappers = new Wrapper[0];
         public Wrapper[] extensionWrappers = new Wrapper[0];
         public int nesting = 0;
+        private volatile boolean paused;
 
         public ContextVersion() {
             super(null, null);
@@ -1647,6 +1672,14 @@ public final class Mapper {
         public ContextVersion(String version, Object context) {
             super(version, context);
         }
+
+        public boolean isPaused() {
+            return paused;
+        }
+
+        public void markPaused() {
+            paused = true;
+        }
     }
 
 

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=1611472&r1=1611471&r2=1611472&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Thu Jul 17 20:50:46 2014
@@ -160,6 +160,10 @@
         sessions. Patch provided by Felix Schumacher. (markt)
       </fix>
       <fix>
+        <bug>56710</bug>: Do not map requests to servlets when context is
+        being reloaded. (kkolinko)
+      </fix>
+      <fix>
         <bug>56712</bug>: Fix session idle time calculations in
         <code>PersistenceManager</code>. (kkolinko)
       </fix>



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

Reply via email to