From 3ec94365ae5b871b78e01206ecd871d8f26b5605 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 16 Mar 2011 22:23:31 +0000 Subject: [PATCH] 324110 Added test harnesses for merging of QueryStrings git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2897 7e9141cc-0065-0410-87d8-b60c137991c4 --- VERSION.txt | 1 + .../AsyncContextDispatchWithQueryStrings.java | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextDispatchWithQueryStrings.java diff --git a/VERSION.txt b/VERSION.txt index 348e658ff5b..a4607d9b656 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,4 +1,5 @@ jetty-7.3.2-SNAPSHOT + + 324110 Added test harnesses for merging of QueryStrings. + 337685 Update websocket API in preparation for draft -07 + 338627 HashSessionManager.getIdleSavePeriod returns milliseconds instead of seconds + 338819 Externally control Deployment Manager application lifecycle diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextDispatchWithQueryStrings.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextDispatchWithQueryStrings.java new file mode 100644 index 00000000000..27497fa0854 --- /dev/null +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/AsyncContextDispatchWithQueryStrings.java @@ -0,0 +1,94 @@ +package org.eclipse.jetty.servlet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.eclipse.jetty.continuation.Continuation; +import org.eclipse.jetty.continuation.ContinuationSupport; +import org.eclipse.jetty.server.AsyncContinuation; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.Handler; +import org.eclipse.jetty.server.LocalConnector; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.DefaultHandler; +import org.eclipse.jetty.server.handler.HandlerList; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * This tests verifies that merging of queryStrings works when dispatching + * Requests via {@link Continuation} multiple times. + * + * @author tbecker + * + */ +public class AsyncContextDispatchWithQueryStrings { + + private Server _server = new Server(); + private ServletContextHandler _contextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); + private LocalConnector _connector = new LocalConnector(); + + @Before + public void setUp() throws Exception { + _connector.setMaxIdleTime(30000); + _server.setConnectors(new Connector[] { _connector }); + + _contextHandler.setContextPath("/"); + _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/initialCall"); + _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/firstDispatchWithNewQueryString"); + _contextHandler.addServlet(new ServletHolder(new TestServlet()), "/secondDispatchNewValueForExistingQueryString"); + + HandlerList handlers = new HandlerList(); + handlers.setHandlers(new Handler[] { _contextHandler, new DefaultHandler() }); + + _server.setHandler(handlers); + _server.start(); + } + + @Test + public void testMultipleDispatchesWithNewQueryStrings() throws Exception { + String request = "GET /initialCall?initialParam=right 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); + assertTrue("Not the expected response. Check STDOUT for details.", responseString.startsWith("HTTP/1.1 200")); + } + + @After + public void tearDown() throws Exception { + _server.stop(); + _server.join(); + } + + private class TestServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = request.getRequestURI(); + String queryString = request.getQueryString(); + if ("/initialCall".equals(path)) { + AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request); + continuation.suspend(); + continuation.dispatch("/firstDispatchWithNewQueryString?newQueryString=initialValue"); + assertEquals("initialParam=right", queryString); + } else if ("/firstDispatchWithNewQueryString".equals(path)) { + AsyncContinuation continuation = (AsyncContinuation) ContinuationSupport.getContinuation(request); + continuation.suspend(); + continuation.dispatch("/secondDispatchNewValueForExistingQueryString?newQueryString=newValue"); + assertEquals("newQueryString=initialValue&initialParam=right", queryString); + } else { + response.setContentType("text/html"); + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().println("

woohhooooo

"); + assertEquals("newQueryString=newValue&initialParam=right", queryString); + } + } + } +}