tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 52225] New: Adding Alias for existing host on running Tomcat causes ClassCastException
Date Tue, 22 Nov 2011 07:14:09 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=52225

             Bug #: 52225
           Summary: Adding Alias for existing host on running Tomcat
                    causes ClassCastException
           Product: Tomcat 7
           Version: 7.0.23
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: knst.kolinko@gmail.com
    Classification: Unclassified


There is an error in the fix for Bug 42707
("add host alias using jmx doesn't take affect until restart")

In Mapper#addHostAlias(String name, String alias)
the following line:
   newHost.object = realHost;

should be replaced with the following one:
   newHost.object = realHost.object;

That was r712467 (3 years ago). The issue affects current 5.5.x and 6.0.x as
well.

The issue manifests itself only if addAlias() is called on an existing Host in
embedded scenario or through JMX. The usual workflow of configuring aliases in
server.xml is not affected.



The issue was reported on the dev@ list,
http://tomcat.markmail.org/thread/sskxor4a3xtrjmk3
"Multiple Aliases Problem"

Reproduction recipe #1, as reported on dev@:

<quote>
  I created a Host instance with the localhost1 domain name.

  Host host = new StandardHost();
  host.setAppBase(CATALINA_HOSTS_HOME);
  host.setName("localhost1");
  host.setDeployOnStartup(false);
  host.setBackgroundProcessorDelay(5);
  host.setAutoDeploy(false);
  host.setRealm(engine.getRealm());
  engine.addChild(host);

  Then I added the localhost2 as a alias.

  host.addAlias("localhost2");

  If I entered localhost1 at a browser then it works fine but if I entered
localhost2 at the browser then I got an error:

Nov 21, 2011 1:29:26 PM org.apache.coyote.http11.AbstractHttp11Processor
process SEVERE: Error processing request java.lang.ClassCastException:
  org.apache.tomcat.util.http.mapper.Mapper$Host
  cannot be cast to org.apache.catalina.Host
at org.apache.catalina.connector.Request.getHost(Request.java:631)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:105) 
</quote>

A workaround for the embedded scenario should be to reorder the calls as
following:
  host.addAlias("localhost2");
  engine.addChild(host);

That will call Mapper.addHost(String name, String[] aliases, Object host) which
processes aliases correctly.


Reproduction recipe #2, using JMX:

1. In standard server.xml replace
 <Engine defaultHost="localhost" with <Engine defaultHost="foohost"
 <Host name="localhost" with <Host name="foohost"
2. Start Tomcat
3. Open http://localhost:8080/  It opens correctly
4. Start JConsole and connect to Tomcat
5. In Catalina -> Host -> foohost -> Operations
call addAlias(localhost)
6. Refresh http://localhost:8080/  Expected result: It opens correctly
Actual result:
- Blank page
- Exception in the logs,
[[[
22.11.2011 10:08:41 org.apache.coyote.http11.AbstractHttp11Processor process
SEVERE: Error processing request
java.lang.ClassCastException: org.apache.tomcat.util.http.mapper.Mapper$Host
can
not be cast to org.apache.catalina.Host
        at org.apache.catalina.connector.Request.getHost(Request.java:623)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:77)
]]]

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message