Author: remy.maucherat(a)jboss.com
Date: 2008-11-12 09:57:19 -0500 (Wed, 12 Nov 2008)
New Revision: 852
Modified:
trunk/java/org/apache/catalina/connector/MapperListener.java
trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
trunk/webapps/docs/changelog.xml
Log:
- Host aliases should be dynamic.
Modified: trunk/java/org/apache/catalina/connector/MapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/connector/MapperListener.java 2008-11-12 14:46:39 UTC
(rev 851)
+++ trunk/java/org/apache/catalina/connector/MapperListener.java 2008-11-12 14:57:19 UTC
(rev 852)
@@ -26,6 +26,10 @@
import javax.management.ObjectInstance;
import javax.management.ObjectName;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Host;
+import org.apache.catalina.ServerFactory;
import org.apache.catalina.core.StandardContext;
import org.apache.tomcat.util.buf.MessageBytes;
import org.apache.tomcat.util.http.mapper.Mapper;
@@ -42,7 +46,7 @@
* @author Costin Manolache
*/
public class MapperListener
- implements NotificationListener
+ implements NotificationListener, ContainerListener
{
private static Logger log = Logger.getLogger(MapperListener.class);
@@ -251,6 +255,18 @@
}
+ // --------------------------------------------- Container Listener methods
+
+ public void containerEvent(ContainerEvent event) {
+
+ if (event.getType() == Host.ADD_ALIAS_EVENT) {
+ mapper.addHostAlias(((Host) event.getSource()).getName(),
+ event.getData().toString());
+ } else if (event.getType() == Host.REMOVE_ALIAS_EVENT) {
+ mapper.removeHostAlias(event.getData().toString());
+ }
+ }
+
// ------------------------------------------------------ Protected Methods
private void registerEngine()
@@ -293,7 +309,7 @@
if (!isRegisteredWithAlias)
log.warn(sm.getString("mapperListener.unknownDefaultHost",
defaultHost));
}
- // This should probablt be called later
+ // This should probably be called later
if( defaultHost != null ) {
mapper.setDefaultHostName(defaultHost);
}
@@ -306,9 +322,11 @@
throws Exception {
String name=objectName.getKeyProperty("host");
if( name != null ) {
- String[] aliases = (String[])
- mBeanServer.invoke(objectName, "findAliases", null, null);
+ Host host = (Host) ServerFactory.getServer().findService(
+ domain).getContainer().findChild(name);
+ String[] aliases = host.findAliases();
mapper.addHost(name, aliases, objectName);
+ host.addContainerListener(this);
if(log.isDebugEnabled())
log.debug(sm.getString
("mapperListener.registerHost", name, domain));
Modified: trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2008-11-12 14:46:39 UTC (rev
851)
+++ trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2008-11-12 14:57:19 UTC (rev
852)
@@ -146,6 +146,47 @@
/**
+ * Add an alias to an existing host.
+ * @param name The name of the host
+ * @param alias The alias to add
+ */
+ public synchronized void addHostAlias(String name, String alias) {
+ int pos = find(hosts, name);
+ if (pos < 0) {
+ // Should not be adding an alias for a host that doesn't exist but
+ // just in case...
+ return;
+ }
+ Host realHost = hosts[pos];
+
+ Host[] newHosts = new Host[hosts.length + 1];
+ Host newHost = new Host();
+ newHost.name = alias;
+ newHost.contextList = realHost.contextList;
+ newHost.object = realHost;
+ if (insertMap(hosts, newHosts, newHost)) {
+ hosts = newHosts;
+ }
+ }
+
+ /**
+ * Remove a host alias
+ * @param alias The alias to remove
+ */
+ public synchronized void removeHostAlias(String alias) {
+ // Find and remove the alias
+ int pos = find(hosts, alias);
+ if (pos < 0) {
+ return;
+ }
+ Host[] newHosts = new Host[hosts.length - 1];
+ if (removeMap(hosts, newHosts, alias)) {
+ hosts = newHosts;
+ }
+
+ }
+
+ /**
* Set context, used for wrapper mapping (request dispatcher).
*
* @param welcomeResources Welcome files defined for this context
@@ -923,7 +964,7 @@
/**
- * Find a map elemnt given its name in a sorted array of map elements.
+ * Find a map element given its name in a sorted array of map elements.
* This will return the index for the closest inferior or equal item in the
* given array.
*/
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-11-12 14:46:39 UTC (rev 851)
+++ trunk/webapps/docs/changelog.xml 2008-11-12 14:57:19 UTC (rev 852)
@@ -23,6 +23,9 @@
<bug>46011</bug>: Make Principal accessible (if set) via
Subject.getSubject(AccessController.getContext()) when processing filters.
Based on a patch provided by tsveg1. (markt)
</fix>
+ <fix>
+ <bug>42707</bug>: Adding host aliases should be dynamic. (markt)
+ </fix>
</changelog>
</subsection>
</section>
Show replies by date