Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51396
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 20 Jun 2011 22:34:16 +0000 (22:34 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 20 Jun 2011 22:34:16 +0000 (22:34 +0000)
Correctly handle jsp-file entries in web.xml when the JSP servlet has been configured via code when embedding Tomcat.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1137806 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/startup/ContextConfig.java
test/org/apache/catalina/startup/TestContextConfig.java
test/webapp-3.0-fragments/WEB-INF/web.xml
test/webapp-3.0-fragments/bug51396.jsp [new file with mode: 0644]
webapps/docs/changelog.xml

index 4e50dd0..bf83949 100644 (file)
@@ -1381,15 +1381,29 @@ public class ContextConfig
     }
 
     private void convertJsps(WebXml webXml) {
+        Map<String,String> jspInitParams;
         ServletDef jspServlet = webXml.getServlets().get("jsp");
+        if (jspServlet == null) {
+            jspInitParams = new HashMap<String,String>();
+            Wrapper w = (Wrapper) context.findChild("jsp");
+            if (w != null) {
+                String[] params = w.findInitParameters();
+                for (String param : params) {
+                    jspInitParams.put(param, w.findInitParameter(param));
+                }
+            }
+        } else {
+            jspInitParams = jspServlet.getParameterMap();
+        }
         for (ServletDef servletDef: webXml.getServlets().values()) {
             if (servletDef.getJspFile() != null) {
-                convertJsp(servletDef, jspServlet);
+                convertJsp(servletDef, jspInitParams);
             }
         }
     }
 
-    private void convertJsp(ServletDef servletDef, ServletDef jspServletDef) {
+    private void convertJsp(ServletDef servletDef,
+            Map<String,String> jspInitParams) {
         servletDef.setServletClass(org.apache.catalina.core.Constants.JSP_SERVLET_CLASS);
         String jspFile = servletDef.getJspFile();
         if ((jspFile != null) && !jspFile.startsWith("/")) {
@@ -1405,7 +1419,7 @@ public class ContextConfig
         }
         servletDef.getParameterMap().put("jspFile", jspFile);
         servletDef.setJspFile(null);
-        for (Map.Entry<String, String> initParam: jspServletDef.getParameterMap().entrySet()) {
+        for (Map.Entry<String, String> initParam: jspInitParams.entrySet()) {
             servletDef.addInitParameter(initParam.getKey(), initParam.getValue());
         }
     }
index 3c78258..ca29e64 100644 (file)
@@ -69,6 +69,23 @@ public class TestContextConfig extends TomcatBaseTest {
         assertEquals("OK - Custom default Servlet", res.toString());
     }
 
+    public void testBug51396() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir =  new File("test/webapp-3.0-fragments");
+        // app dir is relative to server home
+        tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+        int rc = getUrl("http://localhost:" + getPort() +
+                "/test/bug51396.jsp", bc, null);
+        
+        assertEquals(HttpServletResponse.SC_OK, rc);
+        assertTrue(bc.toString().contains("<p>OK</p>"));
+    }
+
     private static class CustomDefaultServletSCI
             implements ServletContainerInitializer {
 
index 4dca982..177185c 100644 (file)
     </web-resource-collection>
   </security-constraint>
 
+  <!-- Bug 51396 -->
+  <servlet>
+    <servlet-name>bug51396</servlet-name>
+    <jsp-file>/bug51396.jsp</jsp-file>
+  </servlet>
+
 </web-app>
\ No newline at end of file
diff --git a/test/webapp-3.0-fragments/bug51396.jsp b/test/webapp-3.0-fragments/bug51396.jsp
new file mode 100644 (file)
index 0000000..9863826
--- /dev/null
@@ -0,0 +1,21 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+--%>
+<html>
+  <body>
+    <p>OK</p>
+  </body>
+</html>
\ No newline at end of file
index 09e0207..e267c4e 100644 (file)
         includes a SAXParserFactory is the first web application to be loaded.
         (markt)
       </fix>
+      <fix>
+        <bug>51396</bug>: Correctly handle jsp-file entries in web.xml when the
+        JSP servlet has been configured via code when embedding Tomcat. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">