Bug 27925 - getContext() fails for xml-specified contexts
Summary: getContext() fails for xml-specified contexts
Status: CLOSED INVALID
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 5.0.19
Hardware: Other All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-24 23:10 UTC by Juergen Weber
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Juergen Weber 2004-03-24 23:10:55 UTC
If you run with crosscontext enabled:

<%

javax.servlet.ServletContext context =
pageContext.getServletContext().getContext("/jsp-examples/cal/");

if (null!= context)
{
	out.print(context.getRealPath("/"));
}
%>


Fine, result is: 

D:\java\jakarta-tomcat-5.0.19\webapps\jsp-examples\


If you call getContext("/anothercontext");

it still works if /anothercontext is included with a context.xml file in 
D:\java\jakarta-tomcat-5.0.19\conf\Catalina\localhost


But getContext("/anothercontext/") i.e. the slash or any existing path appended

results in D:\java\jakarta-tomcat-5.0.19\webapps\ROOT\

It seems the context-lookup algorithm checks only the part specified with 
<Context path="/anothercontext" in the xml file.

But getContext() should find a context, regardless how the context is made known
to the container.
Comment 1 Remy Maucherat 2004-03-24 23:24:02 UTC
Obviously not.
Comment 2 Juergen Weber 2004-03-25 08:59:50 UTC
I get 

C:\java\jakarta-tomcat-5.0.19\webapps\ROOT\

C:\java\jakarta-tomcat-5.0.19\webapps\ROOT\

C:\java\jakarta-tomcat-5.0.19\webapps\..\server\webapps\manager\ 

for 

<%
javax.servlet.ServletContext context;

context = pageContext.getServletContext().getContext("/manager/");
if (null!= context)
{
	out.print(context.getRealPath("/"));
}

out.print("<p>");

context = pageContext.getServletContext().getContext("/manager/manager-howto.html");
if (null!= context)
{
	out.print(context.getRealPath("/"));
}

out.print("<p>");

context = pageContext.getServletContext().getContext("/manager");
if (null!= context)
{
	out.print(context.getRealPath("/"));
}

%>

Note that the scriptlet must be run from a context with crossContext="true".

The output should be three times the third output line,
corresponding to
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/javax/servlet/ServletContext.html#getContext(java.lang.String)
Comment 3 Remy Maucherat 2004-03-25 10:53:48 UTC
I did test it. Thanks for not wasting my time.
Comment 4 Juergen Weber 2004-03-29 07:51:39 UTC
For those that also run into this bug, it was fixed after the release of
jakarta-tomcat-5.0.19.

In ApplicationContextFacade.java there was

while (true) {
                child = (Context) host.findChild(mapuri);
                if (context != null)
                    break;
                int slash = mapuri.lastIndexOf('/');
                if (slash < 0)
                    break;
                mapuri = mapuri.substring(0, slash);
            }

The if (context != null) was always true, it is now if (child != null).