You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2011/11/22 08:14:09 UTC

DO NOT REPLY [Bug 52225] New: Adding Alias for existing host on running Tomcat causes ClassCastException

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


DO NOT REPLY [Bug 52225] Adding Alias for existing host on running Tomcat causes ClassCastException

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52225

--- Comment #3 from Mark Thomas <ma...@apache.org> 2011-12-20 20:17:40 UTC ---
Fixed in 5.5.x and will be in 5.5.35 onwards.

-- 
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


DO NOT REPLY [Bug 52225] Adding Alias for existing host on running Tomcat causes ClassCastException

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52225

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|Catalina                    |Catalina
            Version|7.0.23                      |6.0.33
            Product|Tomcat 7                    |Tomcat 6
   Target Milestone|---                         |default

--- Comment #2 from Mark Thomas <ma...@apache.org> 2011-11-22 19:25:49 UTC ---
Moving to 6.0.x

-- 
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


DO NOT REPLY [Bug 52225] Adding Alias for existing host on running Tomcat causes ClassCastException

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52225

--- Comment #1 from Konstantin Kolinko <kn...@gmail.com> 2011-11-22 08:59:11 UTC ---
Fixed in trunk and 7.0 with r1204856 and r1204860 and will be in 7.0.24.
Proposed for 6.0 and 5.5.

-- 
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


DO NOT REPLY [Bug 52225] Adding Alias for existing host on running Tomcat causes ClassCastException

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=52225

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

--- Comment #4 from Mark Thomas <ma...@apache.org> 2011-12-20 20:20:02 UTC ---
Fixed in 6.0.x and will be included in 6.0.36 onwards.

-- 
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