Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: tomcat7
    • Labels:
      None
    • Environment:
      Mac OS X, Apple JRE 1.6

      Description

      Using the Servlet 3.0 possibilities to add and configure servlet (ServletContainerInitializer through Spring 3.1 WebApplicationInitializer), I try to map a servlet "/", but is not working properly.
      The servlet is started correctly, but the mapping does not work.
      If I replace "/" by "test/*", everything work perfectly.

      For information, the "/" mapping works well in a standalone tomcat 7.0.25.

      I put a sample project on github that reproduce the bug : https://github.com/hikage/tomcat7-bug

        Activity

        Hide
        Gildas Cuisinier added a comment - - edited

        I try to map servlet to "/" in web.xml, that works.

        For information, in Spring documentation, you have this quote :

        Mapping to '/' under Tomcat
        Apache Tomcat maps its internal DefaultServlet to "/", and on Tomcat versions <= 7.0.14, this servlet mapping cannot be overridden programmatically. 7.0.15 fixes this issue. Overriding the "/" servlet mapping has also been tested successfully under GlassFish 3.1.

        The related issue in tomcat : https://issues.apache.org/bugzilla/show_bug.cgi?id=51278

        Show
        Gildas Cuisinier added a comment - - edited I try to map servlet to "/" in web.xml, that works. For information, in Spring documentation, you have this quote : Mapping to '/' under Tomcat Apache Tomcat maps its internal DefaultServlet to "/", and on Tomcat versions <= 7.0.14, this servlet mapping cannot be overridden programmatically. 7.0.15 fixes this issue. Overriding the "/" servlet mapping has also been tested successfully under GlassFish 3.1. The related issue in tomcat : https://issues.apache.org/bugzilla/show_bug.cgi?id=51278
        Hide
        Gildas Cuisinier added a comment -

        Here is new information to solve this bug:

        The code to add mapping :
        ServletRegistration.Dynamic myServlet = servletContext.addServlet(//);
        Set<String> conflicts = myServlet.addMapping("/");

        In Tomcat 7 standalone, the conflits set is empty.
        In Maven Tomcat 7 plugin, the conflicts set contains the String "/".

        I investigate, and one difference I found is that the "Wrapper" for the jsp servlet and the default servlet is "overridable" in tomcat 7 but not in maven plugin context.

        Show
        Gildas Cuisinier added a comment - Here is new information to solve this bug: The code to add mapping : ServletRegistration.Dynamic myServlet = servletContext.addServlet(//); Set<String> conflicts = myServlet.addMapping("/"); In Tomcat 7 standalone, the conflits set is empty. In Maven Tomcat 7 plugin, the conflicts set contains the String "/". I investigate, and one difference I found is that the "Wrapper" for the jsp servlet and the default servlet is "overridable" in tomcat 7 but not in maven plugin context.
        Hide
        Gildas Cuisinier added a comment -

        The difference comes from the declaration of default servlets.

        In the plugin, the declaration is made into "Tomcat" class, in the method initWebappDefaults.

        Wrapper servlet = addServlet(
        ctx, "default", "org.apache.catalina.servlets.DefaultServlet");
        servlet.setLoadOnStartup(1);

        // JSP servlet (by class name - to avoid loading all deps)
        servlet = addServlet(
        ctx, "jsp", "org.apache.jasper.servlet.JspServlet");
        servlet.addInitParameter("fork", "false");
        servlet.setLoadOnStartup(3)

        And in this way, the wrapper is not set as overridable.

        Show
        Gildas Cuisinier added a comment - The difference comes from the declaration of default servlets. In the plugin, the declaration is made into "Tomcat" class, in the method initWebappDefaults. Wrapper servlet = addServlet( ctx, "default", "org.apache.catalina.servlets.DefaultServlet"); servlet.setLoadOnStartup(1); // JSP servlet (by class name - to avoid loading all deps) servlet = addServlet( ctx, "jsp", "org.apache.jasper.servlet.JspServlet"); servlet.addInitParameter("fork", "false"); servlet.setLoadOnStartup(3) And in this way, the wrapper is not set as overridable.
        Hide
        Olivier Lamy (*$^¨%`£) added a comment -

        fixed.

        Show
        Olivier Lamy (*$^¨%`£) added a comment - fixed.
        Hide
        Hudson added a comment -

        Integrated in TomcatMavenPlugin-mvn3.x #123 (See https://builds.apache.org/job/TomcatMavenPlugin-mvn3.x/123/)
        MTOMCAT-133 Servlet mapping to "/" does not work
        apply same fix for the exec war feature. (Revision 1310131)
        MTOMCAT-133 Servlet mapping to "/" does not work
        use the defaut web.xml (Revision 1310113)

        Result = FAILURE
        olamy : http://svn.apache.org/viewvc/?view=rev&rev=1310131
        Files :

        • /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java
        • /tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java

        olamy : http://svn.apache.org/viewvc/?view=rev&rev=1310113
        Files :

        • /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java
        Show
        Hudson added a comment - Integrated in TomcatMavenPlugin-mvn3.x #123 (See https://builds.apache.org/job/TomcatMavenPlugin-mvn3.x/123/ ) MTOMCAT-133 Servlet mapping to "/" does not work apply same fix for the exec war feature. (Revision 1310131) MTOMCAT-133 Servlet mapping to "/" does not work use the defaut web.xml (Revision 1310113) Result = FAILURE olamy : http://svn.apache.org/viewvc/?view=rev&rev=1310131 Files : /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractExecWarMojo.java /tomcat/maven-plugin/trunk/tomcat7-war-runner/src/main/java/org/apache/tomcat/maven/runner/Tomcat7Runner.java olamy : http://svn.apache.org/viewvc/?view=rev&rev=1310113 Files : /tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/main/java/org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java

          People

          • Assignee:
            Olivier Lamy (*$^¨%`£)
            Reporter:
            Gildas Cuisinier
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development