Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2013-10-18 23:12:00 +0000
committerJoakim Erdfelt2013-10-18 23:12:00 +0000
commitd6d54e048b6d32f2af78dfa4e5b0155182f6b37e (patch)
tree8ac4f3c4e52205267aabab2aebdd9fc7904f10e5 /jetty-servlet
parent2d6190da59ae843ea57cc0298f4e2350bef14ec8 (diff)
parent61dc8e1eff408abe5424c8dffacdd14fa93c977a (diff)
downloadorg.eclipse.jetty.project-d6d54e048b6d32f2af78dfa4e5b0155182f6b37e.tar.gz
org.eclipse.jetty.project-d6d54e048b6d32f2af78dfa4e5b0155182f6b37e.tar.xz
org.eclipse.jetty.project-d6d54e048b6d32f2af78dfa4e5b0155182f6b37e.zip
Merge branch 'master' into jetty-9.1
Conflicts: jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/WebSocketClientTest.java jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/AnnotatedMaxMessageSizeTest.java
Diffstat (limited to 'jetty-servlet')
-rw-r--r--jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextTest.java83
1 files changed, 65 insertions, 18 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 a34d185bd0..ae74bf7e60 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
@@ -69,12 +69,18 @@ public class AsyncContextTest
_server.setConnectors(new Connector[]
{ _connector });
- _contextHandler.setContextPath("/");
+ _contextHandler.setContextPath("/ctx");
_contextHandler.addServlet(new ServletHolder(new TestServlet()),"/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet()),"/path with spaces/servletPath");
_contextHandler.addServlet(new ServletHolder(new TestServlet2()),"/servletPath2");
_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 ErrorServlet()),"/error/*");
+
+ ErrorPageErrorHandler error_handler = new ErrorPageErrorHandler();
+ _contextHandler.setErrorHandler(error_handler);
+ error_handler.addErrorPage(500,"/error");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]
@@ -93,7 +99,7 @@ public class AsyncContextTest
@Test
public void testSimpleAsyncContext() throws Exception
{
- String request = "GET /servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ String request = "GET /ctx/servletPath 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);
@@ -109,7 +115,7 @@ public class AsyncContextTest
@Test
public void testDispatchAsyncContext() throws Exception
{
- String request = "GET /servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ String request = "GET /ctx/servletPath?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);
@@ -120,8 +126,8 @@ public class AsyncContextTest
Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath",br.readLine());
Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null",br.readLine());
Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true",br.readLine());
- Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:",br.readLine());
- Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/servletPath",br.readLine());
+ Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:/ctx",br.readLine());
+ Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/ctx/servletPath",br.readLine());
try
{
@@ -137,7 +143,7 @@ public class AsyncContextTest
@Test
public void testDispatchAsyncContextEncodedPathAndQueryString() throws Exception
{
- String request = "GET /path%20with%20spaces/servletPath?dispatch=true&queryStringWithEncoding=space%20space HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ String request = "GET /ctx/path%20with%20spaces/servletPath?dispatch=true&queryStringWithEncoding=space%20space 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);
@@ -148,16 +154,14 @@ public class AsyncContextTest
assertThat("servlet path attr is original",br.readLine(),equalTo("async:run:attr:servletPath:/path with spaces/servletPath"));
assertThat("path info attr is correct",br.readLine(),equalTo("async:run:attr:pathInfo:null"));
assertThat("query string attr is correct",br.readLine(),equalTo("async:run:attr:queryString:dispatch=true&queryStringWithEncoding=space%20space"));
- assertThat("context path attr is correct",br.readLine(),equalTo("async:run:attr:contextPath:"));
- assertThat("request uri attr is correct",br.readLine(),equalTo("async:run:attr:requestURI:/path%20with%20spaces/servletPath"));
+ assertThat("context path attr is correct",br.readLine(),equalTo("async:run:attr:contextPath:/ctx"));
+ assertThat("request uri attr is correct",br.readLine(),equalTo("async:run:attr:requestURI:/ctx/path%20with%20spaces/servletPath"));
}
@Test
public void testSimpleWithContextAsyncContext() throws Exception
{
- _contextHandler.setContextPath("/foo");
-
- String request = "GET /foo/servletPath HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ String request = "GET /ctx/servletPath 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);
@@ -172,9 +176,7 @@ public class AsyncContextTest
@Test
public void testDispatchWithContextAsyncContext() throws Exception
{
- _contextHandler.setContextPath("/foo");
-
- String request = "GET /foo/servletPath?dispatch=true HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n"
+ String request = "GET /ctx/servletPath?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);
@@ -186,14 +188,14 @@ public class AsyncContextTest
Assert.assertEquals("servlet path attr is original","async:run:attr:servletPath:/servletPath",br.readLine());
Assert.assertEquals("path info attr is correct","async:run:attr:pathInfo:null",br.readLine());
Assert.assertEquals("query string attr is correct","async:run:attr:queryString:dispatch=true",br.readLine());
- Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:/foo",br.readLine());
- Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/foo/servletPath",br.readLine());
+ Assert.assertEquals("context path attr is correct","async:run:attr:contextPath:/ctx",br.readLine());
+ Assert.assertEquals("request uri attr is correct","async:run:attr:requestURI:/ctx/servletPath",br.readLine());
}
@Test
public void testDispatch() throws Exception
{
- String request = "GET /forward HTTP/1.1\r\n" + "Host: localhost\r\n" + "Content-Type: application/x-www-form-urlencoded\r\n" + "Connection: close\r\n"
+ String request = "GET /ctx/forward 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);
@@ -204,7 +206,7 @@ public class AsyncContextTest
@Test
public void testDispatchRequestResponse() throws Exception
{
- String request = "GET /forward?dispatchRequestResponse=true HTTP/1.1\r\n" +
+ String request = "GET /ctx/forward?dispatchRequestResponse=true HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
"Connection: close\r\n" +
@@ -282,6 +284,24 @@ 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 responseString = _connector.getResponses(request);
+
+ BufferedReader br = new BufferedReader(new StringReader(responseString));
+
+ assertEquals("HTTP/1.1 500 Async Timeout",br.readLine());
+
+ br.readLine();// connection close
+ br.readLine();// server
+ br.readLine();// empty
+
+ Assert.assertEquals("error servlet","ERROR:/error",br.readLine());
+ }
+
private class DispatchingRunnable implements Runnable
{
private AsyncContext asyncContext;
@@ -308,6 +328,33 @@ public class AsyncContextTest
_server.join();
}
+
+ private class ErrorServlet extends HttpServlet
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.getOutputStream().print("ERROR:" + request.getServletPath() + "\n");
+ }
+ }
+
+ private class ExpireServlet 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.setTimeout(100);
+ }
+ }
+ }
+
private class TestServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;

Back to the top