From 166b4b9e47c58af437199f9e4fe8580b90dc12ce Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 19 Jun 2017 13:38:19 -0700 Subject: [PATCH] Issue #1618 - new testcase for startAsync(req,resp).dispatch() behavior with regards to URL/URI --- .../jetty/servlet/AsyncContextTest.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) 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 4830c61120a..884396bcd62 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 @@ -51,6 +51,7 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.StacklessLogging; import org.junit.After; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; /** @@ -79,12 +80,13 @@ public class AsyncContextTest _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/path with spaces/servletPath"); _contextHandler.addServlet(new ServletHolder(new TestServlet2()), "/servletPath2"); - ServletHolder testHolder = new ServletHolder(new TestServlet()); testHolder.setInitParameter("dispatchPath", "/test2/something%2felse"); _contextHandler.addServlet(testHolder, "/test/*"); _contextHandler.addServlet(new ServletHolder(new TestServlet2()), "/test2/*"); + _contextHandler.addServlet(new ServletHolder(new SelfDispatchingServlet()), "/self/*"); + _contextHandler.addServlet(new ServletHolder(new TestStartThrowServlet()), "/startthrow/*"); _contextHandler.addServlet(new ServletHolder(new ForwardingServlet()), "/forward"); _contextHandler.addServlet(new ServletHolder(new AsyncDispatchingServlet()), "/dispatchingServlet"); @@ -258,6 +260,24 @@ public class AsyncContextTest assertThat("async run request uri has correct encoding", responseBody, containsString("async:run:attr:requestURI:/ctx/test/hello%2fthere")); } + @Test + @Ignore("See https://github.com/eclipse/jetty.project/issues/1618") + public void testDispatchAsyncContext_SelfEncodedUrl() throws Exception + { + String request = "GET /ctx/self/hello%2fthere?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"; + HttpTester.Response response = HttpTester.parseResponse(_connector.getResponse(request)); + assertThat("Response.status", response.getStatus(), is(HttpServletResponse.SC_OK)); + + String responseBody = response.getContent(); + + assertThat("servlet request uri initial", responseBody, containsString("doGet:REQUEST.requestURI:/ctx/self/hello%2fthere")); + assertThat("servlet request uri async", responseBody, containsString("doGet:ASYNC.requestURI:/ctx/self/hello%2fthere")); + } + @Test public void testDispatchAsyncContextEncodedPathAndQueryString() throws Exception { @@ -378,6 +398,28 @@ public class AsyncContextTest } } + private class SelfDispatchingServlet extends HttpServlet + { + private static final long serialVersionUID = 1L; + + @Override + protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException + { + DispatcherType dispatcherType = request.getDispatcherType(); + response.getOutputStream().print("doGet." + dispatcherType.name() + ".requestURI:" + request.getRequestURI() + "\n"); + + if (dispatcherType == DispatcherType.ASYNC) + { + response.getOutputStream().print("Dispatched back to " + SelfDispatchingServlet.class.getSimpleName() + "\n"); + } + else + { + final AsyncContext asyncContext = request.startAsync(request, response); + new Thread(() -> asyncContext.dispatch()).start(); + } + } + } + private class AsyncDispatchingServlet extends HttpServlet { private static final long serialVersionUID = 1L;