Author: kkolinko
Date: Sun Jul 13 14:54:04 2014
New Revision: 1610220

URL: http://svn.apache.org/r1610220
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().

Modified:
    tomcat/trunk/java/org/apache/catalina/mapper/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
    tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/mapper/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/LocalStrings.properties?rev=1610220&r1=1610219&r2=1610220&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/LocalStrings.properties 
(original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/LocalStrings.properties Sun 
Jul 13 14:54:04 2014
@@ -22,5 +22,6 @@ mapperListener.registerHost=Register hos
 mapperListener.unregisterHost=Unregister host [{0}] at domain [{1}] for 
service [{2}]
 mapperListener.registerContext=Register Context [{0}] for service [{1}]
 mapperListener.unregisterContext=Unregister Context [{0}] for service [{1}]
+mapperListener.pauseContext=Register Context [{0}] as being reloaded for 
service [{1}]
 mapperListener.registerWrapper=Register Wrapper [{0}] in Context [{1}] for 
service [{2}]
 mapperListener.unregisterWrapper=Unregister Wrapper [{0}] in Context [{1}] for 
service [{2}]

Modified: tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java?rev=1610220&r1=1610219&r2=1610220&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java Sun Jul 13 
14:54:04 2014
@@ -335,6 +335,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(Context 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) {
         MappedHost host = exactFind(hosts, hostName);
@@ -478,7 +499,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);
@@ -583,7 +604,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;
@@ -763,13 +784,16 @@ 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];
         }
         mappingData.context = contextVersion.object;
         mappingData.contextSlashCount = contextVersion.slashCount;
 
         // Wrapper mapping
-        internalMapWrapper(contextVersion, uri, mappingData);
+        if (!contextVersion.isPaused()) {
+            internalMapWrapper(contextVersion, uri, mappingData);
+        }
 
     }
 
@@ -1604,6 +1628,7 @@ public final class Mapper {
         public MappedWrapper[] wildcardWrappers = new MappedWrapper[0];
         public MappedWrapper[] extensionWrappers = new MappedWrapper[0];
         public int nesting = 0;
+        private volatile boolean paused;
 
         public ContextVersion(String version, String path, int slashCount,
                 Context context, WebResourceRoot resources,
@@ -1614,6 +1639,14 @@ public final class Mapper {
             this.resources = resources;
             this.welcomeResources = welcomeResources;
         }
+
+        public boolean isPaused() {
+            return paused;
+        }
+
+        public void markPaused() {
+            paused = true;
+        }
     }
 
     // ---------------------------------------------------- Wrapper Inner Class

Modified: tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java?rev=1610220&r1=1610219&r2=1610220&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java Sun Jul 13 
14:54:04 2014
@@ -386,24 +386,29 @@ 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 = "";
         }
         String hostName = context.getParent().getName();
 
-        if(log.isDebugEnabled()) {
-            log.debug(sm.getString("mapperListener.unregisterContext",
-                    contextPath, service));
-        }
+        if (context.getPaused()) {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("mapperListener.pauseContext",
+                        contextPath, service));
+            }
 
-        mapper.removeContextVersion(context, hostName, contextPath,
-                context.getWebappVersion());
+            mapper.pauseContextVersion(context, hostName, contextPath,
+                    context.getWebappVersion());
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug(sm.getString("mapperListener.unregisterContext",
+                        contextPath, service));
+            }
+
+            mapper.removeContextVersion(context, hostName, contextPath,
+                    context.getWebappVersion());
+        }
     }
 
 
@@ -477,12 +482,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/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1610220&r1=1610219&r2=1610220&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sun Jul 13 14:54:04 2014
@@ -52,6 +52,10 @@
         reload. (kkolinko)
       </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