commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsde...@apache.org
Subject cvs commit: jakarta-commons/httpclient/src/test-webapp/src/org/apache/commons/httpclient RedirectServlet.java
Date Sat, 01 Feb 2003 20:40:03 GMT
jsdever     2003/02/01 12:40:03

  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:
  Bugfix for 303 redirects
  
  Bugzilla: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=1647
  Contributed by: Jeff Dever
  
  Revision  Changes    Path
  1.107     +5 -4      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.106
  retrieving revision 1.107
  diff -u -r1.106 -r1.107
  --- HttpMethodBase.java	1 Feb 2003 18:50:42 -0000	1.106
  +++ HttpMethodBase.java	1 Feb 2003 20:40:02 -0000	1.107
  @@ -861,6 +861,7 @@
   
               case HttpStatus.SC_MOVED_TEMPORARILY:
               case HttpStatus.SC_MOVED_PERMANENTLY:
  +            case HttpStatus.SC_SEE_OTHER:
               case HttpStatus.SC_TEMPORARY_REDIRECT:
                   LOG.debug("Redirect required");
   
  
  
  
  1.16      +25 -23    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- TestWebappRedirect.java	1 Feb 2003 18:50:42 -0000	1.15
  +++ TestWebappRedirect.java	1 Feb 2003 20:40:03 -0000	1.16
  @@ -119,12 +119,10 @@
           junit.textui.TestRunner.main(testCaseName);
       }
   
  -    // ------------------------------------------------------------------ Tests
  -
  -    public void testRedirect() throws Exception {
  +    public void absoluteRedirectHelper(int code) throws Exception {
           HttpClient client = new HttpClient();
           GetMethod method = new GetMethod(redirectUrl);
  -        method.setQueryString("to=" + paramsUrl);
  +        method.setQueryString("to=" + paramsUrl + "&code=" + code);
           try {
               client.executeMethod(method);
           } catch (Throwable t) {
  @@ -135,23 +133,26 @@
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet:
GET</title>") >= 0);
       }
   
  -    // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5870
  -    public void testRelativeRedirect1() throws Exception {
  -        HttpClient client = new HttpClient();
  -        GetMethod method = new GetMethod(redirectUrl);
  -        method.setQueryString("to=/" + context + "/params");
  -        try {
  -            client.executeMethod(method);
  -        } catch (Throwable t) {
  -            t.printStackTrace();
  -            fail("Unable to execute method : " + t.toString());
  -        }
  -        assertEquals(200,method.getStatusCode());
  -        assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet:
GET</title>") >= 0);
  +
  +    // ------------------------------------------------------------------ Tests
  +
  +    public void testAbsoluteRedirectCode301() throws Exception {
  +        absoluteRedirectHelper(301);
  +    }
  +
  +    public void testAbsoluteRedirectCode302() throws Exception {
  +        absoluteRedirectHelper(302);
       }
   
  -    // see http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16460
  -    public void testRelativeRedirect2() throws Exception {
  +    public void testAbsoluteRedirectCode303() throws Exception {
  +        absoluteRedirectHelper(303);
  +    }
  +
  +    public void testAbsoluteRedirectCode307() throws Exception {
  +        absoluteRedirectHelper(307);
  +    }
  +
  +    public void testRelativeRedirect() throws Exception {
           HttpClient client = new HttpClient();
           GetMethod method = new GetMethod(redirectUrl);
           method.setQueryString("to=params");
  @@ -164,6 +165,7 @@
           assertEquals(200,method.getStatusCode());
           assertTrue(method.getResponseBodyAsString().indexOf("<title>Param Servlet:
GET</title>") >= 0);
       }
  +
   
       public void testRedirectWithQueryString() throws Exception {
           HttpClient client = new HttpClient();
  
  
  
  1.6       +11 -4     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RedirectServlet.java	1 Feb 2003 18:50:42 -0000	1.5
  +++ RedirectServlet.java	1 Feb 2003 20:40:03 -0000	1.6
  @@ -79,8 +79,15 @@
           if(null == to) {
               to = "/";
           }
  -        response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
           response.setHeader("Location",to);
  +
  +        try {
  +            int status = Integer.parseInt(request.getParameter("code"));
  +            response.setStatus(status);
  +        } catch (Exception e) {
  +            response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
  +        }
  +
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message