Author: kkolinko Date: Tue Jul 8 15:43:21 2014 New Revision: 1608833 URL: http://svn.apache.org/r1608833 Log: Improve the fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=44312 Check that addContextVersion/removeContextVersion, addWrapper/removeWrapper, add/clear/removeWelcomeFile[s] are performed on the real Host, as expected by the caller.
This backports the checks from r1606680 and r1608824. Modified: 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/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=1608833&r1=1608832&r2=1608833&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 Tue Jul 8 15:43:21 2014 @@ -231,6 +231,10 @@ public final class Mapper { return; } } + if (mappedHost.isAlias()) { + log.error("No host found: " + hostName); + return; + } int slashCount = slashCount(path); synchronized (mappedHost) { Context[] contexts = mappedHost.contextList.contexts; @@ -276,7 +280,7 @@ public final class Mapper { public void removeContextVersion(String hostName, String path, String version) { Host host = exactFind(hosts, hostName); - if (host == null) { + if (host == null || host.isAlias()) { return; } synchronized (host) { @@ -312,22 +316,40 @@ public final class Mapper { } - public void addWrapper(String hostName, String contextPath, String version, - String path, Object wrapper, boolean jspWildCard, - boolean resourceOnly) { + private ContextVersion findContextVersion(String hostName, + String contextPath, String version, boolean silent) { Host host = exactFind(hosts, hostName); - if (host == null) { - return; + if (host == null || host.isAlias()) { + if (!silent) { + log.error("No host found: " + hostName); + } + return null; } Context context = exactFind(host.contextList.contexts, contextPath); if (context == null) { - log.error("No context found: " + contextPath); - return; + if (!silent) { + log.error("No context found: " + contextPath); + } + return null; } ContextVersion contextVersion = exactFind(context.versions, version); if (contextVersion == null) { - log.error("No context version found: " + contextPath + " " - + version); + if (!silent) { + log.error("No context version found: " + contextPath + " " + + version); + } + return null; + } + return contextVersion; + } + + + public void addWrapper(String hostName, String contextPath, String version, + String path, Object wrapper, boolean jspWildCard, + boolean resourceOnly) { + ContextVersion contextVersion = findContextVersion(hostName, + contextPath, version, false); + if (contextVersion == null) { return; } addWrapper(contextVersion, path, wrapper, jspWildCard, resourceOnly); @@ -428,15 +450,8 @@ public final class Mapper { */ public void removeWrapper(String hostName, String contextPath, String version, String path) { - Host host = exactFind(hosts, hostName); - if (host == null) { - return; - } - Context context = exactFind(host.contextList.contexts, contextPath); - if (context == null) { - return; - } - ContextVersion contextVersion = exactFind(context.versions, version); + ContextVersion contextVersion = findContextVersion(hostName, + contextPath, version, true); if (contextVersion == null) { return; } @@ -518,19 +533,9 @@ public final class Mapper { */ public void addWelcomeFile(String hostName, String contextPath, String version, String welcomeFile) { - Host host = exactFind(hosts, hostName); - if (host == null) { - return; - } - Context context = exactFind(host.contextList.contexts, contextPath); - if (context == null) { - log.error("No context found: " + contextPath); - return; - } - ContextVersion contextVersion = exactFind(context.versions, version); + ContextVersion contextVersion = findContextVersion(hostName, + contextPath, version, false); if (contextVersion == null) { - log.error("No context version found: " + contextPath + " " - + version); return; } int len = contextVersion.welcomeResources.length + 1; @@ -550,19 +555,9 @@ public final class Mapper { */ public void removeWelcomeFile(String hostName, String contextPath, String version, String welcomeFile) { - Host host = exactFind(hosts, hostName); - if (host == null) { - return; - } - Context context = exactFind(host.contextList.contexts, contextPath); - if (context == null) { - log.error("No context found: " + contextPath); - return; - } - ContextVersion contextVersion = exactFind(context.versions, version); + ContextVersion contextVersion = findContextVersion(hostName, + contextPath, version, false); if (contextVersion == null) { - log.error("No context version found: " + contextPath + " " - + version); return; } int match = -1; @@ -593,19 +588,9 @@ public final class Mapper { */ public void clearWelcomeFiles(String hostName, String contextPath, String version) { - Host host = exactFind(hosts, hostName); - if (host == null) { - return; - } - Context context = exactFind(host.contextList.contexts, contextPath); - if (context == null) { - log.error("No context found: " + contextPath); - return; - } - ContextVersion contextVersion = exactFind(context.versions, version); + ContextVersion contextVersion = findContextVersion(hostName, + contextPath, version, false); if (contextVersion == null) { - log.error("No context version found: " + contextPath + " " - + version); return; } contextVersion.welcomeResources = new String[0]; 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=1608833&r1=1608832&r2=1608833&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Jul 8 15:43:21 2014 @@ -61,7 +61,8 @@ <fix> <bug>44312</bug>: Log an error if there is a conflict between Host and Alias names. Improve host management methods in <code>Mapper</code> - to avoid occasionally removing a wrong host. (kkolinko) + to avoid occasionally removing a wrong host. Check that host management + operations are performed on the host and not on an alias. (kkolinko) </fix> <fix> <bug>55282</bug>: Ensure that one and the same application listener is --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org