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 2015/02/27 22:27:38 UTC

[Bug 57645] New: getContext("/") returns null

https://bz.apache.org/bugzilla/show_bug.cgi?id=57645

            Bug ID: 57645
           Summary: getContext("/") returns null
           Product: Tomcat 7
           Version: 7.0.59
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: karl.olson@gmail.com

The getContext() method incorrectly returns null when requesting the ROOT
context ("/"). The following fix resolves the issue:

    public ServletContext getContext(String uri) {

        // Validate the format of the specified argument
        if ((uri == null) || (!uri.startsWith("/")))
            return (null);

        Context child = null;
        try {
            // Look for an exact match
            Container host = context.getParent();
            child = (Context) host.findChild(uri);
            if ( (child == null) && "/".equals(uri) ) { // fix
              child = (Context) host.findChild("");     // fix
            }                                           // fix

The root context was created via:

  Context context = embedded.addWebapp("", "/path/to/webapps/ROOT");

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


[Bug 57645] getContext("/") returns null

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

--- Comment #8 from Konstantin Kolinko <kn...@gmail.com> ---
Created attachment 35180
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=35180&action=edit
test.war

Sample web application that demonstrates that the feature is working
successfully.

Steps:
1. Deploy it as webapps/test.war
2. Start Tomcat
3. Access http://localhost:8080/test/
It prints:
getContext("/"): org.apache.catalina.core.ApplicationContextFacade@16b6c55

Tested with 7.0.78.

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


[Bug 57645] getContext("/") returns null

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

Paul Taylor <pa...@trapezegroup.com> changed:

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

--- Comment #6 from Paul Taylor <pa...@trapezegroup.com> ---
It looks like this bug was re-introduced on the Tomcat 7 branch in 7.0.61

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


[Bug 57645] getContext("/") returns null

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

--- Comment #3 from Mark Thomas <ma...@apache.org> ---
*** Bug 57733 has been marked as a duplicate of this bug. ***

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


[Bug 57645] getContext("/") returns null

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

--- Comment #5 from Konstantin Kolinko <kn...@gmail.com> ---
(In reply to Christopher Schultz from comment #1)
> I believe this was reported recently as a regression due to the fix for bug
> #57190 and fixed in r1661867 (trunk) r1662178 (Tomcat 8) and r1662179
> (Tomcat 7).
> 
> There was no previous BZ issue for it, so this one is as good as any to
> document it.
> 

For a reference,
discussion about ServletContext.getContext() API on dev@ list of that time,

Thread "Two serious issues have been introduced in Tomcat 7 and Tomcat 8..."
started 2015-02-23,
http://markmail.org/thread/wwfgnc6qwgaenwol

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


[Bug 57645] getContext("/") returns null

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

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
*** Bug 57733 has been marked as a duplicate of this bug. ***

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


[Bug 57645] getContext("/") returns null

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

Konstantin Kolinko <kn...@gmail.com> changed:

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

--- Comment #7 from Konstantin Kolinko <kn...@gmail.com> ---
(In reply to Paul Taylor from comment #6)

Quick test: It does work in 7.0.78.

Note that the ServletContext.getContext() method is disabled by default for
security reasons. It must be explicitly enabled by setting crossContext="true"
in Context configuration of the calling web application.

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


[Bug 57645] getContext("/") returns null

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

Christopher Schultz <ch...@christopherschultz.net> changed:

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

--- Comment #1 from Christopher Schultz <ch...@christopherschultz.net> ---
I believe this was reported recently as a regression due to the fix for bug
#57190 and fixed in r1661867 (trunk) r1662178 (Tomcat 8) and r1662179 (Tomcat
7).

There was no previous BZ issue for it, so this one is as good as any to
document it.

Changelog for the Tomcat 7 fix:

  <fix>
    Correct a regression in the fix for <bug>57190</bug> that incorrectly
    required the path passed to
    <code>ServletContext.getContext(String)</code> to be an exact match to a
    path to an existing context. (markt)
  </fix>

This fix will be included in Tomcat 7.0.60 and later.

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


[Bug 57645] getContext("/") returns null

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

Christopher Schultz <ch...@christopherschultz.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ivannikolchov@gmail.com

--- Comment #2 from Christopher Schultz <ch...@christopherschultz.net> ---
*** Bug 57733 has been marked as a duplicate of this bug. ***

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