Author: markt Date: Mon Jun 20 22:34:16 2011 New Revision: 1137806 URL: http://svn.apache.org/viewvc?rev=1137806&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51396 Correctly handle jsp-file entries in web.xml when the JSP servlet has been configured via code when embedding Tomcat.
Added: tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp (with props) Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java tomcat/trunk/test/org/apache/catalina/startup/TestContextConfig.java tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=1137806&r1=1137805&r2=1137806&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original) +++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Mon Jun 20 22:34:16 2011 @@ -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()); } } Modified: tomcat/trunk/test/org/apache/catalina/startup/TestContextConfig.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestContextConfig.java?rev=1137806&r1=1137805&r2=1137806&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/startup/TestContextConfig.java (original) +++ tomcat/trunk/test/org/apache/catalina/startup/TestContextConfig.java Mon Jun 20 22:34:16 2011 @@ -69,6 +69,23 @@ public class TestContextConfig extends T 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 { Modified: tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml?rev=1137806&r1=1137805&r2=1137806&view=diff ============================================================================== --- tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml (original) +++ tomcat/trunk/test/webapp-3.0-fragments/WEB-INF/web.xml Mon Jun 20 22:34:16 2011 @@ -43,4 +43,10 @@ </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 Added: tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp?rev=1137806&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp (added) +++ tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp Mon Jun 20 22:34:16 2011 @@ -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 Propchange: tomcat/trunk/test/webapp-3.0-fragments/bug51396.jsp ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1137806&r1=1137805&r2=1137806&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Jun 20 22:34:16 2011 @@ -91,6 +91,10 @@ 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"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org