Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-11-08 03:32:50 +0000
committerGreg Wilkins2013-11-08 04:08:01 +0000
commit1d5635c76c7de641441d180d7c74e8392b05e22f (patch)
tree15ca262cbcdf2cfda9c511dc5d833b804b3860ca /jetty-servlet
parented1555e0c416fcf3912b9e475705204931289d97 (diff)
downloadorg.eclipse.jetty.project-1d5635c76c7de641441d180d7c74e8392b05e22f.tar.gz
org.eclipse.jetty.project-1d5635c76c7de641441d180d7c74e8392b05e22f.tar.xz
org.eclipse.jetty.project-1d5635c76c7de641441d180d7c74e8392b05e22f.zip
420776 complete error pages after startAsync
handle complete and dispatch calls before the thrown exception Conflicts: jetty-server/src/main/java/org/eclipse/jetty/server/AbstractHttpConnection.java jetty-server/src/main/java/org/eclipse/jetty/server/AsyncContinuation.java jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java4
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java83
2 files changed, 82 insertions, 5 deletions
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
index 4d210c2470..4904ffc8a9 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java
@@ -21,7 +21,6 @@ package org.eclipse.jetty.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@@ -56,7 +55,6 @@ import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.security.IdentityService;
import org.eclipse.jetty.security.SecurityHandler;
-import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.QuietServletException;
import org.eclipse.jetty.server.Request;
@@ -615,7 +613,7 @@ public class ServletHandler extends ScopedHandler
{
// Complete async errored requests
if (th!=null && request.isAsyncStarted())
- request.getAsyncContext().complete();
+ baseRequest.getHttpChannelState().errorComplete();
if (servlet_holder!=null)
baseRequest.setHandled(true);
diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
index e707884f9f..bcc6ae89a4 100644
--- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
+++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java
@@ -122,8 +122,11 @@ public class AsyncContextTest
@Test
public void testStartThrow() throws Exception
{
- String request = "GET /ctx/startthrow HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
- + "Connection: close\r\n" + "\r\n";
+ String request =
+ "GET /ctx/startthrow HTTP/1.1\r\n" +
+ "Host: localhost\r\n" +
+ "Connection: close\r\n" +
+ "\r\n";
String responseString = _connector.getResponses(request);
BufferedReader br = new BufferedReader(new StringReader(responseString));
@@ -137,6 +140,68 @@ public class AsyncContextTest
Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: Test",br.readLine());
}
+
+ @Test
+ public void testStartDispatchThrow() throws Exception
+ {
+ String request = "GET /ctx/startthrow?dispatch=true HTTP/1.1\r\n" +
+ "Host: localhost\r\n" +
+ "Content-Type: application/x-www-form-urlencoded\r\n" +
+ "Connection: close\r\n" +
+ "\r\n";
+ String responseString = _connector.getResponses(request);
+
+ BufferedReader br = new BufferedReader(new StringReader(responseString));
+
+ assertEquals("HTTP/1.1 500 Server Error",br.readLine());
+ br.readLine();// connection close
+ br.readLine();// server
+ br.readLine();// empty
+ Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
+ Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
+ Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: Test",br.readLine());
+ }
+
+ @Test
+ public void testStartCompleteThrow() throws Exception
+ {
+ String request = "GET /ctx/startthrow?complete=true HTTP/1.1\r\n" +
+ "Host: localhost\r\n" +
+ "Content-Type: application/x-www-form-urlencoded\r\n" +
+ "Connection: close\r\n" +
+ "\r\n";
+ String responseString = _connector.getResponses(request);
+
+ BufferedReader br = new BufferedReader(new StringReader(responseString));
+
+ assertEquals("HTTP/1.1 500 Server Error",br.readLine());
+ br.readLine();// connection close
+ br.readLine();// server
+ br.readLine();// empty
+ Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
+ Assert.assertEquals("error servlet","PathInfo= /IOE",br.readLine());
+ Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: Test",br.readLine());
+ }
+
+ @Test
+ public void testStartFlushCompleteThrow() throws Exception
+ {
+ String request = "GET /ctx/startthrow?flush=true&complete=true HTTP/1.1\r\n" +
+ "Host: localhost\r\n" +
+ "Content-Type: application/x-www-form-urlencoded\r\n" +
+ "Connection: close\r\n" +
+ "\r\n";
+ String responseString = _connector.getResponses(request);
+
+ BufferedReader br = new BufferedReader(new StringReader(responseString));
+
+ assertEquals("HTTP/1.1 200 OK",br.readLine());
+ br.readLine();// connection close
+ br.readLine();// server
+ br.readLine();// empty
+
+ Assert.assertEquals("error servlet","completeBeforeThrow",br.readLine());
+ }
@Test
public void testDispatchAsyncContext() throws Exception
@@ -497,6 +562,20 @@ public class AsyncContextTest
if (request.getDispatcherType()==DispatcherType.REQUEST)
{
request.startAsync(request, response);
+
+ if (Boolean.valueOf(request.getParameter("dispatch")))
+ {
+ request.getAsyncContext().dispatch();
+ }
+
+ if (Boolean.valueOf(request.getParameter("complete")))
+ {
+ response.getOutputStream().write("completeBeforeThrow".getBytes());
+ if (Boolean.valueOf(request.getParameter("flush")))
+ response.flushBuffer();
+ request.getAsyncContext().complete();
+ }
+
throw new QuietServletException(new IOException("Test"));
}
}

Back to the top