From 99d2666b7442ee65baf424527a097d5c27a15bc0 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Tue, 6 Mar 2012 11:36:29 +0100 Subject: [PATCH] Add additional AsyncContextTest.java test case with encoded path and queryString Change-Id: I8b592030fa6548ece7ebe56da1dc6f27d8b6f1e9 --- .../jetty/servlet/AsyncContextTest.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 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 f591a65ada0..bf38fb92b46 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 @@ -1,5 +1,9 @@ package org.eclipse.jetty.servlet; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -8,8 +12,7 @@ import javax.servlet.ServletException; 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 junit.framework.Assert; import org.eclipse.jetty.continuation.ContinuationSupport; @@ -48,6 +51,7 @@ public class AsyncContextTest _contextHandler.setContextPath("/"); _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"); @@ -92,6 +96,24 @@ public class AsyncContextTest 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 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" + + "Connection: close\r\n" + "\r\n"; + String responseString = _connector.getResponses(request); + + BufferedReader br = parseHeader(responseString); + + assertThat("servlet gets right path",br.readLine(),equalTo("doGet:getServletPath:/servletPath2")); + assertThat("async context gets right path in get",br.readLine(), equalTo("doGet:async:getServletPath:/servletPath2")); + 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")); + } @Test public void testSimpleWithContextAsyncContext() throws Exception