Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 64224 invoked from network); 1 Feb 2003 18:50:45 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 1 Feb 2003 18:50:45 -0000 Received: (qmail 2810 invoked by uid 97); 1 Feb 2003 18:52:16 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@nagoya.betaversion.org Received: (qmail 2803 invoked from network); 1 Feb 2003 18:52:16 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 1 Feb 2003 18:52:16 -0000 Received: (qmail 64028 invoked by uid 500); 1 Feb 2003 18:50:43 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 64017 invoked by uid 500); 1 Feb 2003 18:50:43 -0000 Received: (qmail 64014 invoked from network); 1 Feb 2003 18:50:43 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 1 Feb 2003 18:50:43 -0000 Received: (qmail 38812 invoked by uid 1536); 1 Feb 2003 18:50:43 -0000 Date: 1 Feb 2003 18:50:43 -0000 Message-ID: <20030201185043.38811.qmail@icarus.apache.org> From: jsdever@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient RedirectServlet.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N jsdever 2003/02/01 10:50:43 Modified: httpclient/src/java/org/apache/commons/httpclient HttpMethodBase.java httpclient/src/test/org/apache/commons/httpclient TestWebappRedirect.java httpclient/src/test-webapp/src/org/apache/commons/httpclient RedirectServlet.java Log: Fix relative redirect bug. -ensure that path is part of the currentUrl in HttpMethodBase so the redirected URL is handled correctly when relative -added redirect test case -simplified the redirect tests Bug: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16460 Contributed by: Jeff Dever Revision Changes Path 1.106 +5 -5 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java Index: HttpMethodBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.105 retrieving revision 1.106 diff -u -r1.105 -r1.106 --- HttpMethodBase.java 31 Jan 2003 23:23:14 -0000 1.105 +++ HttpMethodBase.java 1 Feb 2003 18:50:42 -0000 1.106 @@ -1045,7 +1045,7 @@ try { currentUrl = new URL(conn.getProtocol().getScheme(), - conn.getHost(), conn.getPort(), ""); + conn.getHost(), conn.getPort(), this.getPath()); redirectUrl = new URL(location); } catch (MalformedURLException e) { if (isStrictMode()) { 1.15 +44 -35 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java Index: TestWebappRedirect.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestWebappRedirect.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- TestWebappRedirect.java 31 Jan 2003 23:23:18 -0000 1.14 +++ TestWebappRedirect.java 1 Feb 2003 18:50:42 -0000 1.15 @@ -2,6 +2,7 @@ * $Header$ * $Revision$ * $Date$ + * * ==================================================================== * * The Apache Software License, Version 1.1 @@ -93,8 +94,17 @@ * @version $Id$ */ public class TestWebappRedirect extends TestWebappBase { + private static final Log log = LogFactory.getLog(TestWebappRedirect.class); + private static final String baseUrl = "http://" + host + ":" + port + "/" + context; + + private static final String redirectUrl = baseUrl + "/redirect"; + + private static final String paramsUrl = baseUrl + "/params"; + + private static final String bodyUrl = baseUrl + "/body"; + public TestWebappRedirect(String testName) { super(testName); } @@ -113,10 +123,8 @@ public void testRedirect() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - GetMethod method = new GetMethod("/" + context + "/redirect"); - method.setQueryString("to=http://" + host + ":" + port + "/" + context + "/params"); - method.setUseDisk(false); + GetMethod method = new GetMethod(redirectUrl); + method.setQueryString("to=" + paramsUrl); try { client.executeMethod(method); } catch (Throwable t) { @@ -128,12 +136,25 @@ } // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5870 - public void testRelativeRedirect() throws Exception { + public void testRelativeRedirect1() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - GetMethod method = new GetMethod("/" + context + "/redirect"); + GetMethod method = new GetMethod(redirectUrl); method.setQueryString("to=/" + context + "/params"); - method.setUseDisk(false); + try { + client.executeMethod(method); + } catch (Throwable t) { + t.printStackTrace(); + fail("Unable to execute method : " + t.toString()); + } + assertEquals(200,method.getStatusCode()); + assertTrue(method.getResponseBodyAsString().indexOf("Param Servlet: GET") >= 0); + } + + // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16460 + public void testRelativeRedirect2() throws Exception { + HttpClient client = new HttpClient(); + GetMethod method = new GetMethod(redirectUrl); + method.setQueryString("to=params"); try { client.executeMethod(method); } catch (Throwable t) { @@ -146,13 +167,11 @@ public void testRedirectWithQueryString() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - GetMethod method = new GetMethod("/" + context + "/redirect"); + GetMethod method = new GetMethod(redirectUrl); method.setQueryString(new NameValuePair[] { - new NameValuePair("to", "http://" + host + ":" + port + "/" + context + "/params?foo=bar&bar=foo") + new NameValuePair("to", paramsUrl + "?foo=bar&bar=foo") } ); - method.setUseDisk(false); try { client.executeMethod(method); } catch (Throwable t) { @@ -166,16 +185,13 @@ public void testRecursiveRedirect() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - GetMethod method = new GetMethod("/" + context + "/redirect"); + GetMethod method = new GetMethod(redirectUrl); - String qs = "http://" + host + ":" + port + "/" + context + "/params?foo=bar&bar=foo"; + String qs = paramsUrl + "?foo=bar&bar=foo"; for(int i=0;i<2;i++) { - qs = "http://" + host + ":" + port + "/" + context + - "/redirect?to=" + URIUtil.encodeWithinQuery(qs); + qs = redirectUrl + "?to=" + URIUtil.encodeWithinQuery(qs); } method.setQueryString("to=" + URIUtil.encodeWithinQuery(qs)); - method.setUseDisk(false); try { client.executeMethod(method); } catch (Throwable t) { @@ -189,8 +205,7 @@ public void testDetectRedirectLoop() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - GetMethod method = new GetMethod("/" + context + "/redirect"); + GetMethod method = new GetMethod(redirectUrl); method.setQueryString("loop=true"); try { client.executeMethod(method); @@ -208,8 +223,7 @@ public void testPostRedirect() throws Exception { String bodyStr = "Hello World"; HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - PostMethod method = new PostMethod("/" + context + "/redirect"); + PostMethod method = new PostMethod(redirectUrl); method.setQueryString("to=" + URIUtil.encodeWithinQuery("http://" + host + ":" + port + "/" + context + "/params?foo=bar&bar=foo")); @@ -227,10 +241,8 @@ //unbuffered request can not be redirected assertEquals(HttpStatus.SC_MOVED_TEMPORARILY,method.getStatusCode()); - method = new PostMethod("/" + context + "/redirect"); - method.setQueryString("to=" + URIUtil.encodeWithinQuery("http://" + - host + ":" + port + "/" + context + - "/params?foo=bar&bar=foo")); + method = new PostMethod(redirectUrl); + method.setQueryString("to=" + URIUtil.encodeWithinQuery(paramsUrl + "?foo=bar&bar=foo")); method.setRequestBody(new ByteArrayInputStream(body)); method.setRequestContentLength(PostMethod.CONTENT_LENGTH_AUTO); //buffered request method.setFollowRedirects(true); @@ -247,11 +259,8 @@ public void testPutRedirect() throws Exception { HttpClient client = new HttpClient(); - client.getHostConfiguration().setHost(host, port, "http"); - PutMethod method = new PutMethod("/" + context + "/redirect"); - method.setQueryString("to=" + URIUtil.encodeWithinQuery("http://" + - host + ":" + port + "/" + context + - "/body?foo=bar&bar=foo")); + PutMethod method = new PutMethod(redirectUrl); + method.setQueryString("to=" + URIUtil.encodeWithinQuery(bodyUrl + "?foo=bar&bar=foo")); method.setRequestBody("This is data to be sent in the body of an HTTP PUT."); try { client.executeMethod(method); 1.5 +4 -3 jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java Index: RedirectServlet.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient/RedirectServlet.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- RedirectServlet.java 23 Jan 2003 22:48:49 -0000 1.4 +++ RedirectServlet.java 1 Feb 2003 18:50:42 -0000 1.5 @@ -2,6 +2,7 @@ * $Header$ * $Revision$ * $Date$ + * * ==================================================================== * * The Apache Software License, Version 1.1 --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org