Author: markt
Date: Wed Jun 4 09:22:21 2014
New Revision: 1600051
URL: http://svn.apache.org/r1600051
Log:
Add a (currently disabled) test for errors with a chunked response after the
response has been committed.
Modified:
tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
Modified:
tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java?rev=1600051&r1=1600050&r2=1600051&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
(original)
+++ tomcat/trunk/test/org/apache/coyote/http11/TestAbstractHttp11Processor.java
Wed Jun 4 09:22:21 2014
@@ -40,6 +40,7 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertTrue;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import org.apache.catalina.Context;
@@ -53,6 +54,75 @@ import org.apache.tomcat.util.buf.ByteCh
public class TestAbstractHttp11Processor extends TomcatBaseTest {
@Test
+ @Ignore
+ public void testResponseWithErrorChunked() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // Must have a real docBase - just use temp
+ Context ctxt = tomcat.addContext("",
System.getProperty("java.io.tmpdir"));
+
+ // Add protected servlet
+ Tomcat.addServlet(ctxt, "ChunkedResponseWithErrorServlet",
+ new ResponseWithErrorServlet(true));
+ ctxt.addServletMapping("/*", "ChunkedResponseWithErrorServlet");
+
+ tomcat.start();
+
+ String request =
+ "GET /anything HTTP/1.1" + SimpleHttpClient.CRLF +
+ "Host: any" + SimpleHttpClient.CRLF +
+ SimpleHttpClient.CRLF;
+
+ Client client = new Client(tomcat.getConnector().getLocalPort());
+ client.setRequest(new String[] {request});
+
+ client.connect();
+ client.processRequest();
+
+ // Expected response is a 200 response followed by an incomplete
chunked
+ // body.
+ assertTrue(client.isResponse200());
+ // There should not be an end chunk
+ assertFalse(client.getResponseBody().endsWith("0"));
+ }
+
+ private static class ResponseWithErrorServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ private final boolean useChunks;
+
+ public ResponseWithErrorServlet(boolean useChunks) {
+ this.useChunks = useChunks;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("UTF-8");
+ if (!useChunks) {
+ // Longer than it needs to be because response will fail before
+ // it is complete
+ resp.setContentLength(100);
+ }
+ PrintWriter pw = resp.getWriter();
+ pw.print("line01");
+ pw.flush();
+ resp.flushBuffer();
+ pw.print("line02");
+ pw.flush();
+ resp.flushBuffer();
+ pw.print("line03");
+
+ // Now throw a RuntimeException to end this request
+ throw new ServletException("Deliberate failure");
+ }
+ }
+
+
+ @Test
public void testWithUnknownExpectation() throws Exception {
Tomcat tomcat = getTomcatInstance();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]