Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2013-10-24 05:02:35 +0000
committerGreg Wilkins2013-10-24 05:02:35 +0000
commitd6e301d7fd3f2f5dcfce66d9792ab493634e3b56 (patch)
treee6e0c9f11d806d50ce2fa42241018950219ca3be /jetty-servlet
parent6ef9108cf692c870b7dfaf15ee350074ba99761f (diff)
parentac3787b16729725b992eb0bc4b56b5cccc5d4f77 (diff)
downloadorg.eclipse.jetty.project-d6e301d7fd3f2f5dcfce66d9792ab493634e3b56.tar.gz
org.eclipse.jetty.project-d6e301d7fd3f2f5dcfce66d9792ab493634e3b56.tar.xz
org.eclipse.jetty.project-d6e301d7fd3f2f5dcfce66d9792ab493634e3b56.zip
Merge remote-tracking branch 'origin/master' into jetty-9.1
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java76
1 files changed, 72 insertions, 4 deletions
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 ae74bf7e60..121874ce76 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
@@ -28,7 +28,10 @@ import java.io.IOException;
import java.io.StringReader;
import javax.servlet.AsyncContext;
+import javax.servlet.AsyncEvent;
+import javax.servlet.AsyncListener;
import javax.servlet.DispatcherType;
+import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@@ -76,6 +79,7 @@ public class AsyncContextTest
_contextHandler.addServlet(new ServletHolder(new ForwardingServlet()),"/forward");
_contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()),"/dispatchingServlet");
_contextHandler.addServlet(new ServletHolder(new ExpireServlet()),"/expire/*");
+ _contextHandler.addServlet(new ServletHolder(new BadExpireServlet()),"/badexpire/*");
_contextHandler.addServlet(new ServletHolder(new ErrorServlet()),"/error/*");
ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
@@ -287,8 +291,11 @@ public class AsyncContextTest
@Test
public void testExpire() throws Exception
{
- String request = "GET /ctx/expire 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/expire 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));
@@ -299,7 +306,28 @@ public class AsyncContextTest
br.readLine();// server
br.readLine();// empty
- Assert.assertEquals("error servlet","ERROR:/error",br.readLine());
+ Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
+ }
+
+ @Test
+ public void testBadExpire() throws Exception
+ {
+ String request = "GET /ctx/badexpire 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 Async Exception",br.readLine());
+ br.readLine();// connection close
+ br.readLine();// server
+ br.readLine();// empty
+
+ Assert.assertEquals("error servlet","ERROR: /error",br.readLine());
+ Assert.assertEquals("error servlet","EXCEPTION: java.io.IOException: TEST",br.readLine());
}
private class DispatchingRunnable implements Runnable
@@ -336,7 +364,9 @@ public class AsyncContextTest
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
- response.getOutputStream().print("ERROR:" + request.getServletPath() + "\n");
+ response.getOutputStream().print("ERROR: " + request.getServletPath() + "\n");
+ if (request.getAttribute(RequestDispatcher.ERROR_EXCEPTION)!=null)
+ response.getOutputStream().print("EXCEPTION: " + request.getAttribute(RequestDispatcher.ERROR_EXCEPTION) + "\n");
}
}
@@ -355,6 +385,44 @@ public class AsyncContextTest
}
}
+ private class BadExpireServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ if (request.getDispatcherType()==DispatcherType.REQUEST)
+ {
+ AsyncContext asyncContext = request.startAsync();
+ asyncContext.addListener(new AsyncListener()
+ {
+ @Override
+ public void onTimeout(AsyncEvent event) throws IOException
+ {
+ throw new IOException("TEST");
+ }
+
+ @Override
+ public void onStartAsync(AsyncEvent event) throws IOException
+ {
+ }
+
+ @Override
+ public void onError(AsyncEvent event) throws IOException
+ {
+ }
+
+ @Override
+ public void onComplete(AsyncEvent event) throws IOException
+ {
+ }
+ });
+ asyncContext.setTimeout(100);
+ }
+ }
+ }
+
private class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;

Back to the top