Author: kkolinko
Date: Thu Jul 17 22:38:15 2014
New Revision: 1611496
URL: http://svn.apache.org/r1611496
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56717
Allow repeated Mapper.addHost() calls for the same host. E.g. if the host has
been implicitly added by addContextVersion() call.
It is backport of r1610564.
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/LocalStrings.properties
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/LocalStrings.properties
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/LocalStrings.properties?rev=1611496&r1=1611495&r2=1611496&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/LocalStrings.properties
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/mapper/LocalStrings.properties
Thu Jul 17 22:38:15 2014
@@ -13,6 +13,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+mapper.addHost.success=Registered host [{0}]
+mapper.addHost.sameHost=Duplicate registration of the same host [{0}]. Ignored.
+mapper.addHostAlias.success=Registered alias [{0}] for host [{1}]
+mapper.addHostAlias.sameHost=Duplicate registration of alias [{0}] for the
same host [{1}]. Ignored.
mapper.removeWrapper=Removing wrapper from Context [{0}] with path [{1}]
mapper.duplicateHost=Duplicate Host [{0}]. The name is already used by Host
[{1}]. This Host will be ignored.
mapper.duplicateHostAlias=Duplicate host Alias [{0}] in Host [{1}]. The name
is already used by Host [{2}]. This Alias will be ignored.
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=1611496&r1=1611495&r2=1611496&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 22:38:15 2014
@@ -97,12 +97,25 @@ public final class Mapper {
Host newHost = new Host(name, host);
if (insertMap(hosts, newHosts, newHost)) {
hosts = newHosts;
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("mapper.addHost.success", name));
+ }
} else {
Host duplicate = hosts[find(hosts, name)];
- log.error(sm.getString("mapper.duplicateHost", name,
- duplicate.getRealHostName()));
- // Do not add aliases, as removeHost(hostName) won't be able to
remove them
- return;
+ if (duplicate.object == host) {
+ // The host is already registered in the mapper.
+ // E.g. it might have been added by addContextVersion()
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("mapper.addHost.sameHost", name));
+ }
+ newHost = duplicate;
+ } else {
+ log.error(sm.getString("mapper.duplicateHost", name,
+ duplicate.getRealHostName()));
+ // Do not add aliases, as removeHost(hostName) won't be able to
+ // remove them
+ return;
+ }
}
List<Host> newAliases = new ArrayList<Host>(aliases.length);
for (String alias : aliases) {
@@ -159,6 +172,10 @@ public final class Mapper {
Host[] newHosts = new Host[hosts.length + 1];
if (insertMap(hosts, newHosts, newAlias)) {
hosts = newHosts;
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("mapper.addHostAlias.success",
+ newAlias.name, newAlias.getRealHostName()));
+ }
return true;
} else {
Host duplicate = hosts[find(hosts, newAlias.name)];
@@ -166,6 +183,10 @@ public final class Mapper {
// A duplicate Alias for the same Host.
// A harmless redundancy. E.g.
// <Host name="localhost"><Alias>localhost</Alias></Host>
+ if (log.isDebugEnabled()) {
+ log.debug(sm.getString("mapper.addHostAlias.sameHost",
+ newAlias.name, newAlias.getRealHostName()));
+ }
return false;
}
log.error(sm.getString("mapper.duplicateHostAlias", newAlias.name,
Modified:
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java?rev=1611496&r1=1611495&r2=1611496&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
(original)
+++
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
Thu Jul 17 22:38:15 2014
@@ -144,6 +144,28 @@ public class TestMapper extends LoggingB
assertFalse(host.isAlias());
assertTrue(alias.isAlias());
assertEquals(host.object, alias.object);
+
+ // Test addContextVersion() followed by addHost()
+ Object hostZ = "zzzz";
+ Object contextZ = "contextZ";
+
+ assertEquals(16, mapper.hosts.length);
+ mapper.addContextVersion("zzzz", hostZ, "/", "", contextZ, null, null,
+ null);
+ assertEquals(17, mapper.hosts.length);
+
+ mapper.addHost("zzzz", new String[] { "zzzz_alias1", "zzzz_alias2" },
+ hostZ);
+ assertEquals(19, mapper.hosts.length);
+
+ assertEquals("zzzz", mapper.hosts[16].name);
+ assertEquals("zzzz_alias1", mapper.hosts[17].name);
+ assertEquals("zzzz_alias2", mapper.hosts[18].name);
+ assertEquals(2, mapper.hosts[16].getAliases().size());
+ assertSame(contextZ,
+ mapper.hosts[16].contextList.contexts[0].versions[0].object);
+ assertSame(contextZ,
+ mapper.hosts[18].contextList.contexts[0].versions[0].object);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]