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 2009/09/14 18:11:59 UTC

DO NOT REPLY [Bug 47837] New: RequestDispatcher for root context has incorrect requestURI (extra "/" at start)

https://issues.apache.org/bugzilla/show_bug.cgi?id=47837

           Summary: RequestDispatcher for root context has incorrect
                    requestURI (extra "/" at start)
           Product: Tomcat 7
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: david_syer@hotmail.com


RequestDispatcher for root context has incorrect requestURI (extra "/" at
start).  Here's a slightly ugly test case:

{code}
    @Test
    public void testDispatcherWithNonRootContext() throws Exception {
        String value = getRequestURIFor("/bucket", "/bar");
        // Passes
        assertEquals("/bucket/bar", value);
    }

    @Test
    public void testDispatcherWithRootContext() throws Exception {
        String value = getRequestURIFor("/", "/bar");
        // Fails
        assertEquals("/bar", value);
    }

    private String getRequestURIFor(String root, String path) throws
IllegalArgumentException, IllegalAccessException {
        Tomcat tomcat = new Tomcat();
        StandardContext standardContext = tomcat.addContext(root,
System.getProperty("java.io.tmpdir"));
        Tomcat.addServlet(standardContext, "spam", "NoSuchClass");
        standardContext.addServletMapping("/", "spam", false);
        standardContext.getMapper().setContext("spam", null, null);
        ApplicationContext applicationContext = new ApplicationContext("/foo",
standardContext);
        RequestDispatcher requestDispatcher =
applicationContext.getRequestDispatcher(path);
        Field field = findField(requestDispatcher.getClass(), "requestURI");
        field.setAccessible(true);
        return(String) field.get(requestDispatcher);
    }

    private Field findField(Class<?> clazz, String name) {
        Assert.notNull(clazz, "Class must not be null");
        Assert.isTrue(name != null, "Name of the field must be specified");
        Class<?> searchType = clazz;
        while (!Object.class.equals(searchType) && searchType != null) {
            Field[] fields = searchType.getDeclaredFields();
            for (Field field : fields) {
                if (name.equals(field.getName())) {
                    return field;
                }
            }
            searchType = searchType.getSuperclass();
        }
        return null;
    }
{code}

Suggested fix would be to check for the length of the context path in
ApplicationContext.getRequestDispatcher() around line 430:

{code}
if (context.getPath().length()>1) {
    uriCC.append(context.getPath(), 0, context.getPath().length());
}
{code}

(add the if statement).

-- 
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 47837] RequestDispatcher for root context has incorrect requestURI (extra "/" at start)

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

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

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

--- Comment #1 from Mark Thomas <ma...@apache.org> 2009-09-14 17:29:15 BST ---
"" is the correct way to refer to the ROOT context, not "/".

-- 
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 47837] RequestDispatcher for root context has incorrect requestURI (extra "/" at start)

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

--- Comment #2 from Dave Syer <da...@hotmail.com> 2009-09-14 09:59:03 PDT ---
Fair enough.  Could Tomcat.addContext() not correct the mistake (or throw an
obvious exception)?

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