Author: violetagg Date: Tue Sep 2 13:11:20 2014 New Revision: 1621975 URL: http://svn.apache.org/r1621975 Log: According to JavaDoc javax.servlet.jsp.PageContext.include(String) and javax.servlet.jsp.PageContext.include(String, boolean) must throw IOException if I/O error occur during the operation. When JSPServlet init parameter "development" is "false" then IOException is re-thrown, but when the parameter is "true", JasperException is thrown instead of IOException. This change guarantees that IOException is always re-thrown.
Added: tomcat/trunk/test/webapp/jsp/pageContext1.jsp tomcat/trunk/test/webapp/jsp/pageContext2.jsp Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java tomcat/trunk/test/org/apache/jasper/runtime/TestPageContextImpl.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java?rev=1621975&r1=1621974&r2=1621975&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java (original) +++ tomcat/trunk/java/org/apache/jasper/servlet/JspServletWrapper.java Tue Sep 2 13:11:20 2014 @@ -456,8 +456,8 @@ public class JspServletWrapper { } throw ex; } catch (IOException ex) { - if(options.getDevelopment()) { - throw handleJspException(ex); + if (options.getDevelopment()) { + throw new IOException(handleJspException(ex).getMessage(), ex); } throw ex; } catch (IllegalStateException ex) { Modified: tomcat/trunk/test/org/apache/jasper/runtime/TestPageContextImpl.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/runtime/TestPageContextImpl.java?rev=1621975&r1=1621974&r2=1621975&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/jasper/runtime/TestPageContextImpl.java (original) +++ tomcat/trunk/test/org/apache/jasper/runtime/TestPageContextImpl.java Tue Sep 2 13:11:20 2014 @@ -80,6 +80,38 @@ public class TestPageContextImpl extends Assert.assertTrue(result.contains("OK")); } + @Test + public void testIncludeThrowsIOException() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk res = new ByteChunk(); + + int rc = getUrl("http://localhost:" + getPort() + "/test/jsp/pageContext1.jsp", res, null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + + String body = res.toString(); + Assert.assertTrue(body.contains("OK")); + Assert.assertFalse(body.contains("FAILED")); + + res = new ByteChunk(); + + rc = getUrl("http://localhost:" + getPort() + "/test/jsp/pageContext1.jsp?flush=true", res, + null); + + Assert.assertEquals(HttpServletResponse.SC_OK, rc); + + body = res.toString(); + Assert.assertTrue(body.contains("Flush")); + Assert.assertTrue(body.contains("OK")); + Assert.assertFalse(body.contains("FAILED")); + } + public static class Bug56010 extends HttpServlet { private static final long serialVersionUID = 1L; Added: tomcat/trunk/test/webapp/jsp/pageContext1.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/jsp/pageContext1.jsp?rev=1621975&view=auto ============================================================================== --- tomcat/trunk/test/webapp/jsp/pageContext1.jsp (added) +++ tomcat/trunk/test/webapp/jsp/pageContext1.jsp Tue Sep 2 13:11:20 2014 @@ -0,0 +1,39 @@ +<%-- + 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 import="java.io.IOException" contentType="text/plain"%> +<% + boolean flush = Boolean.valueOf(request.getParameter("flush")); + if (pageContext != null) { + try { + if (flush) { + out.println("Flush"); + pageContext.include("/jsp/pageContext2.jsp", true); + } else { + pageContext.include("/jsp/pageContext2.jsp"); + } + } catch (IOException e) { + out.println("OK"); + return; + } catch (Throwable t) { + out.println("FAILED. Expected IOException, received: " + t.getClass().getName()); + return; + } + out.println("FAILED. Expected IOException."); + } else { + out.println("FAILED. Expected IOException."); + } +%> \ No newline at end of file Added: tomcat/trunk/test/webapp/jsp/pageContext2.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/jsp/pageContext2.jsp?rev=1621975&view=auto ============================================================================== --- tomcat/trunk/test/webapp/jsp/pageContext2.jsp (added) +++ tomcat/trunk/test/webapp/jsp/pageContext2.jsp Tue Sep 2 13:11:20 2014 @@ -0,0 +1,18 @@ +<%-- + 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 import="java.io.IOException" contentType="text/plain"%> +<% throw new IOException("Throws IOException."); %> \ No newline at end of file Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1621975&r1=1621974&r2=1621975&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Tue Sep 2 13:11:20 2014 @@ -65,6 +65,18 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + Ensure that the implementation of + <code>javax.servlet.jsp.PageContext.include(String)</code> + and + <code>javax.servlet.jsp.PageContext.include(String, boolean)</code> + will throw <code>IOException</code> when an I/O error occur during + the operation. (violetagg) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 8.0.12 (markt)"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org