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 9311d675f7e..f985c0f9f90 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 @@ -9,7 +9,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import static org.junit.Assert.*; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.*; import junit.framework.Assert; import org.eclipse.jetty.continuation.ContinuationSupport; @@ -62,74 +62,74 @@ 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" + "Connection: close\r\n" + "\r\n"; String responseString = _connector.getResponses(request); BufferedReader br = parseHeader(responseString); - - Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath", br.readLine()); - Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath", br.readLine()); - Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath", br.readLine()); + + Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath",br.readLine()); + Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath",br.readLine()); + Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath",br.readLine()); } - + @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" + "Connection: close\r\n" + "\r\n"; String responseString = _connector.getResponses(request); - + BufferedReader br = parseHeader(responseString); - - Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2", br.readLine()); - Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2", br.readLine()); - 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("servlet gets right path","doGet:getServletPath:/servletPath2",br.readLine()); + Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2",br.readLine()); + 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()); + } @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" + "Connection: close\r\n" + "\r\n"; String responseString = _connector.getResponses(request); - + BufferedReader br = parseHeader(responseString); - - Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath", br.readLine()); - Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath", br.readLine()); - Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath", br.readLine()); + + Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath",br.readLine()); + Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath",br.readLine()); + Assert.assertEquals("async context gets right path in async","async:run:attr:servletPath:/servletPath",br.readLine()); } - + @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" + "Connection: close\r\n" + "\r\n"; - + String responseString = _connector.getResponses(request); - + BufferedReader br = parseHeader(responseString); - - Assert.assertEquals("servlet gets right path","doGet:getServletPath:/servletPath2", br.readLine()); - Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2", br.readLine()); - 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("servlet gets right path","doGet:getServletPath:/servletPath2",br.readLine()); + Assert.assertEquals("async context gets right path in get","doGet:async:getServletPath:/servletPath2",br.readLine()); + 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()); + } @Test public void testDispatch() throws Exception @@ -187,28 +187,28 @@ public class AsyncContextTest } } - private class AsyncDispatchingServlet extends HttpServlet - { - private static final long serialVersionUID = 1L; + private class AsyncDispatchingServlet extends HttpServlet + { + private static final long serialVersionUID = 1L; - @Override - protected void doGet(HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException - { - Request request = (Request)req; - if (request.getDispatcherType() == DispatcherType.ASYNC) - { - response.getOutputStream().print("Dispatched back to AsyncDispatchingServlet"); - } - else - { - final AsyncContext asyncContext; - if (request.getParameter("dispatchRequestResponse") != null) - asyncContext = request.startAsync(request,response); - else - asyncContext = request.startAsync(); + @Override + protected void doGet(HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException + { + Request request = (Request)req; + if (request.getDispatcherType() == DispatcherType.ASYNC) + { + response.getOutputStream().print("Dispatched back to AsyncDispatchingServlet"); + } + else + { + final AsyncContext asyncContext; + if (request.getParameter("dispatchRequestResponse") != null) + asyncContext = request.startAsync(request,response); + else + asyncContext = request.startAsync(); - new Thread(new DispatchingRunnable(asyncContext)).start(); - } + new Thread(new DispatchingRunnable(asyncContext)).start(); + } } }