Bug 42707 - add host alias using jmx doesn't take affect until restart
add host alias using jmx doesn't take affect until restart
Status: RESOLVED FIXED
Product: Tomcat 5
Classification: Unclassified
Component: Catalina
5.5.27
PC Linux
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
: 44856 (view as bug list)
Depends on:
Blocks: 44856
  Show dependency tree
 
Reported: 2007-06-20 14:46 UTC by Ted Leung
Modified: 2009-06-04 08:06 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Leung 2007-06-20 14:46:49 UTC
Adding a host alias using jmx doesn't take affect until tomcat is restarted.

To test it I started tomcat using 
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=6702
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

I created a webapps_test/test/index.html
I created a new host 
      <Host
          appBase="webapps_test"
          name="test.localdomain">
      </Host>

I tested the url http://test.localdomain:8080/test/ and the index page showed up
as expected.

I used jconsole under Catalina/Host/test.localdomain/Operations/addAlias and
added test1.localdomain (I edited my /etc/hosts file to map test.localdomain and
test1.localdomain to 127.0.0.1).

I went to the url http://test1.localdomain:8080/test/ and instead of the
index.html page I received a 404 error. I tried starting and stopping the host
from within jmx, it didn't help, I tried Catalina/Server/Operations/storeConfig
and starting and stopping the host and that didn't help either.

I tested with the following versions for the server
jdk 1.6.0_01-b06
tomcat 5.5.20, 6.0.10, 6.0.13

for the client I was using the jdk 1.6.0_01-b06 jconsole, as well as a custom
application I had written as well as the the "administration web application 5.5.23"

all the combinations above had similar results.

I will briefly mention that in tomcat 6.0.10/13 I was unable to save the
configuration due to an error :
   Jun 20, 2007 5:26:11 PM org.apache.catalina.core.StandardServer storeConfig
   SEVERE: StoreConfig mbean not registeredCatalina:type=StoreConfig
I will open a separate bug for that.

In tomcat 5 I was able to save the config.

If I restart tomcat5 after saving the config (using catalina.sh stop / start)
the new alias works properly. 

Likewise, if I edit the tomcat 6 conf/server.xml and add the alias entry in
manually and restart tomcat, the url http://test1.localdomain:8080/test/ works fine.

So, the main problem is that adding an alias dynamically doesn't seem to work.
Comment 1 Andrew Mottaz 2008-04-22 13:03:42 UTC
The support for this in Mapper.java is easy to add: (Note -- this is based on code posted by Luke Kirby, inelegantly re-written)

    public synchronized void addHost(String name, String[] aliases,
                                     Object host) {
        Host[] newHosts = new Host[hosts.length + 1];
        Host newHost = new Host();
        ContextList contextList = new ContextList();
        newHost.name = name;
        newHost.contextList = contextList;
        newHost.object = host;
        if (insertMap(hosts, newHosts, newHost)) {
            hosts = newHosts;
        
        for (int i = 0; i < aliases.length; i++) {
            newHosts = new Host[hosts.length + 1];
            newHost = new Host();
            newHost.name = aliases[i];
            newHost.contextList = contextList;
            newHost.object = host;
            if (insertMap(hosts, newHosts, newHost)) {
                hosts = newHosts;
            }
        }
        }
        else {
        	Host aliasedHost;
        	// insert failed because the host already exists; grab it
        	int hostPos = find(hosts, name);
        	if (hostPos >= 0) {
        	aliasedHost = hosts[hostPos];
                for (int i = 0; i < aliases.length; i++) {
                    newHosts = new Host[hosts.length + 1];
                    newHost = new Host();
                    newHost.name = aliases[i];
                    newHost.contextList = aliasedHost.contextList;
                    newHost.object = aliasedHost.object;
                    if (insertMap(hosts, newHosts, newHost)) {
                        hosts = newHosts;
                    }
                }
        	} else {
        		
        		System.out.println("huh?");
        	}

        }
    }
Comment 2 Mark Thomas 2008-04-23 14:56:22 UTC
*** Bug 44856 has been marked as a duplicate of this bug. ***
Comment 3 Mark Thomas 2008-04-23 14:56:47 UTC
Note to self - need to port this to 5.5.x when fixed.
Comment 4 Mark Thomas 2008-11-08 17:58:34 UTC
I have added a fix for this to trunk. There are a couple of ways if implementing this so I'll leave it a little while to let people comment before proposing it for 6.0.x.
Comment 5 Mark Thomas 2008-12-28 16:16:01 UTC
No-one commented so I have proposed the fix for 6.0.x
Comment 6 Mark Thomas 2009-01-14 16:09:20 UTC
This has been fixed in 6.0.x and will be included in 6.0.19 onwards.
Comment 7 Mark Thomas 2009-04-09 08:23:38 UTC
I've proposed backporting the fix to 5.5.x
Comment 8 Mark Thomas 2009-06-04 08:06:52 UTC
The patch has been applied to 5.5.x and will be included in 5.5.28 onwards.