tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 57733] New: ServletContext.getContext(String) always returns null for the root context ("/")
Date Sat, 21 Mar 2015 18:03:59 GMT
https://bz.apache.org/bugzilla/show_bug.cgi?id=57733

            Bug ID: 57733
           Summary: ServletContext.getContext(String) always returns null
                    for the root context ("/")
           Product: Tomcat 8
           Version: 8.0.20
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: ivannikolchov@gmail.com

The cause of the problem is the fix for bug #57190 for version 8.0.16
(https://bz.apache.org/bugzilla/show_bug.cgi?id=57190) 

It is not present in version 8.0.15

I have the following configuration running on Tomcat 8.0.20:

C:\tomcat
   conf
     server.xml
     context.xml
   webapps
     app
   ......
C:\external
     app3
        web
     app4
        web
In context.xml I have <Context crossContext="true"> .... </Context>

And in server.xml:
 ..........
 <Host name="host.com"  appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Context 
      docBase="C:\external\app3\web" 
      path="" 
      crossContext="true"
      reloadable="true" />

    <Context 
      crossContext="true"
      docBase="C:\external\app4\web" 
      path="/app4"
      reloadable="true" />
 </Host>
Obtaining the Context of /app works as espected:

request.getServletContext().getContext("/app") is not null.

However, requesting the Context of the root app (app3) with:

request.getServletContext().getContext("/") ALWAYS returns null.

After some debugging found out that this is a regression caused by the fix for
#57190  in org.apache.catalina.core.ApplicationContext#getContext(String)

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-catalina/8.0.17/org/apache/catalina/core/ApplicationContext.java#286

on line 286 we have
284             // Must be an exact match. It is no good returning the ROOT
285             // context if the caller is looking for "/something-else"
286             if (mappingData.context.getPath().equals(uri)) {
287                 child = mappingData.context;
288             }

Here uri is "/" and mappingData.context.getPath() is "" hence the null result.

Probably it should be:
String contextPath = mappingData.context.getPath();
if (contextPath.equals(uri) || contextPath.isEmpty() && uri.equals("/")) {
....
}

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