tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 47837] New: RequestDispatcher for root context has incorrect requestURI (extra "/" at start)
Date Mon, 14 Sep 2009 16:11:59 GMT

           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

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

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

    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,
        Tomcat.addServlet(standardContext, "spam", "NoSuchClass");
        standardContext.addServletMapping("/", "spam", false);
        standardContext.getMapper().setContext("spam", null, null);
        ApplicationContext applicationContext = new ApplicationContext("/foo",
        RequestDispatcher requestDispatcher =
        Field field = findField(requestDispatcher.getClass(), "requestURI");
        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;

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

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

(add the if statement).

Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message