Author: markt Date: Mon Aug 23 19:23:28 2010 New Revision: 988262 URL: http://svn.apache.org/viewvc?rev=988262&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49726 Specifying a default content type via a JSP property group should not prevent a page from setting some other content type Includes test cases
Added: tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java (with props) tomcat/trunk/test/webapp-3.0/bug49726a.jsp (with props) tomcat/trunk/test/webapp-3.0/bug49726b.jsp (with props) Modified: tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java?rev=988262&r1=988261&r2=988262&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Compiler.java Mon Aug 23 19:23:28 2010 @@ -140,9 +140,8 @@ public abstract class Compiler { pageInfo.setTrimDirectiveWhitespaces(JspUtil.booleanValue(jspProperty .isTrimDirectiveWhitespaces())); } - if (jspProperty.getDefaultContentType() != null) { - pageInfo.setContentType(jspProperty.getDefaultContentType()); - } + // Default ContentType processing is deferred until after the page has + // been parsed if (jspProperty.getBuffer() != null) { pageInfo.setBufferValue(jspProperty.getBuffer(), null, errDispatcher); @@ -197,6 +196,12 @@ public abstract class Compiler { // Pass 2 - the whole translation unit pageNodes = parserCtl.parse(ctxt.getJspFile()); + // Leave this until now since it can only be set once - bug 49726 + if (pageInfo.getContentType() == null && + jspProperty.getDefaultContentType() != null) { + pageInfo.setContentType(jspProperty.getDefaultContentType()); + } + if (ctxt.isPrototypeMode()) { // generate prototype .java file for the tag file writer = setupContextWriter(javaFileName); Added: tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java?rev=988262&view=auto ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java (added) +++ tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java Mon Aug 23 19:23:28 2010 @@ -0,0 +1,77 @@ +/* + * 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. + */ + +package org.apache.jasper.compiler; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestCompiler extends TomcatBaseTest { + + public void testBug49726a() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + tomcat.start(); + + ByteChunk res = new ByteChunk(); + Map<String,List<String>> headers = new HashMap<String,List<String>>(); + + getUrl("http://localhost:" + getPort() + "/test/bug49726a.jsp", res, + headers); + + // Check request completed + String result = res.toString(); + assertEcho(result, "OK"); + + // Check content type + assertTrue(headers.get("Content-Type").get(0).startsWith("text/html")); + } + + public void testBug49726b() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + tomcat.start(); + + ByteChunk res = new ByteChunk(); + Map<String,List<String>> headers = new HashMap<String,List<String>>(); + + getUrl("http://localhost:" + getPort() + "/test/bug49726b.jsp", res, + headers); + + // Check request completed + String result = res.toString(); + assertEcho(result, "OK"); + + // Check content type + assertTrue(headers.get("Content-Type").get(0).startsWith("text/plain")); + } + + /** Assertion for text printed by tags:echo */ + private static void assertEcho(String result, String expected) { + assertTrue(result.indexOf("<p>" + expected + "</p>") > 0); + } +} Propchange: tomcat/trunk/test/org/apache/jasper/compiler/TestCompiler.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml?rev=988262&r1=988261&r2=988262&view=diff ============================================================================== --- tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml (original) +++ tomcat/trunk/test/webapp-3.0/WEB-INF/web.xml Mon Aug 23 19:23:28 2010 @@ -27,4 +27,11 @@ Used as part of the Tomcat unit tests when a full web application is required. </description> + <jsp-config> + <jsp-property-group> + <default-content-type>text/plain</default-content-type> + <url-pattern>/bug49726a.jsp</url-pattern> + <url-pattern>/bug49726b.jsp</url-pattern> + </jsp-property-group> + </jsp-config> </web-app> \ No newline at end of file Added: tomcat/trunk/test/webapp-3.0/bug49726a.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49726a.jsp?rev=988262&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/bug49726a.jsp (added) +++ tomcat/trunk/test/webapp-3.0/bug49726a.jsp Mon Aug 23 19:23:28 2010 @@ -0,0 +1,24 @@ +<%-- + 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. +--%> +<%@ page contentType="text/html"%> +<html> + <head><title>Bug 49726 test case</title></head> + <body> + <p>OK</p> + </body> +</html> + Propchange: tomcat/trunk/test/webapp-3.0/bug49726a.jsp ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/test/webapp-3.0/bug49726b.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49726b.jsp?rev=988262&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/bug49726b.jsp (added) +++ tomcat/trunk/test/webapp-3.0/bug49726b.jsp Mon Aug 23 19:23:28 2010 @@ -0,0 +1,23 @@ +<%-- + 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> + <head><title>Bug 49726 test case</title></head> + <body> + <p>OK</p> + </body> +</html> + Propchange: tomcat/trunk/test/webapp-3.0/bug49726b.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=988262&r1=988261&r2=988262&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Aug 23 19:23:28 2010 @@ -76,6 +76,15 @@ </add> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + <bug>49726</bug>: Specifying a default content type via a JSP property + group should not prevent a page from setting some other content type. + (markt) + </fix> + </changelog> + </subsection> <subsection name="Cluster"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org