hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r664326 - in /httpcomponents/httpclient/trunk/module-client/src: main/java/org/apache/http/client/ main/java/org/apache/http/impl/client/ test/java/org/apache/http/impl/client/
Date Sat, 07 Jun 2008 11:48:27 GMT
Author: olegk
Date: Sat Jun  7 04:48:27 2008
New Revision: 664326

URL: http://svn.apache.org/viewvc?rev=664326&view=rev
Log:
Better code for handling of non-repeatable requests

Added:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java
      - copied, changed from r664066, httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
Removed:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
Modified:
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
    httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java

Copied: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java
(from r664066, httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java?p2=httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java&p1=httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java&r1=664066&r2=664326&rev=664326&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableEntityException.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/NonRepeatableRequestException.java
Sat Jun  7 04:48:27 2008
@@ -1,7 +1,7 @@
 /*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
+ * $HeadURL$
+ * $Revision$
+ * $Date$
  *
  * ====================================================================
  *
@@ -40,14 +40,14 @@
  * 
  * @since 4.0
  */
-public class NonRepeatableEntityException extends ProtocolException {
+public class NonRepeatableRequestException extends ProtocolException {
 
     private static final long serialVersionUID = 82685265288806048L;
 
     /**
      * Creates a new NonRepeatableEntityException with a <tt>null</tt> detail
message. 
      */
-    public NonRepeatableEntityException() {
+    public NonRepeatableRequestException() {
         super();
     }
 
@@ -56,7 +56,7 @@
      * 
      * @param message The exception detail message
      */
-    public NonRepeatableEntityException(String message) {
+    public NonRepeatableRequestException(String message) {
         super(message);
     }
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java?rev=664326&r1=664325&r2=664326&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultClientRequestDirector.java
Sat Jun  7 04:48:27 2008
@@ -61,7 +61,7 @@
 import org.apache.http.client.ClientRequestDirector;
 import org.apache.http.client.CredentialsProvider;
 import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.client.NonRepeatableEntityException;
+import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.RedirectException;
 import org.apache.http.client.RedirectHandler;
 import org.apache.http.client.UserTokenHandler;
@@ -384,17 +384,13 @@
 
                 boolean retrying = true;
                 while (retrying) {
+                    // Increment total exec count (with redirects)
                     execCount++;
-                    
-                    if (execCount > 1) {
-                        if (request instanceof HttpEntityEnclosingRequest) {
-                            HttpEntity entity = 
-                                ((HttpEntityEnclosingRequest) request).getEntity();
-                            if (entity != null && !entity.isRepeatable()) {
-                                throw new NonRepeatableEntityException(
-                                        "Cannot retry the request");
-                            }
-                        }
+                    // Increment exec count for this particular request
+                    wrapper.incrementExecCount();
+                    if (wrapper.getExecCount() > 1 && !wrapper.isRepeatable())
{
+                        throw new NonRepeatableRequestException("Cannot retry request " +
+                                "with a non-repeatable request entity");
                     }
                     
                     try {

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java?rev=664326&r1=664325&r2=664326&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
Sat Jun  7 04:48:27 2008
@@ -74,5 +74,10 @@
         Header expect = getFirstHeader(HTTP.EXPECT_DIRECTIVE);
         return expect != null && HTTP.EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
     }
-        
+
+    @Override
+    public boolean isRepeatable() {
+        return this.entity == null || this.entity.isRepeatable();
+    }
+    
 }

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java?rev=664326&r1=664325&r2=664326&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/RequestWrapper.java
Sat Jun  7 04:48:27 2008
@@ -64,6 +64,7 @@
     private URI uri;
     private String method;
     private ProtocolVersion version;
+    private int execCount;
     
     public RequestWrapper(final HttpRequest request) throws ProtocolException {
         super();
@@ -88,8 +89,15 @@
             this.method = requestLine.getMethod();
             this.version = request.getProtocolVersion();
         }
+        this.execCount = 0;
     }
 
+    public void resetHeaders() {
+        // Make a copy of original headers
+        this.headergroup.clear();
+        setHeaders(this.original.getAllHeaders());
+    }
+    
     public String getMethod() {
         return this.method;
     }
@@ -147,10 +155,16 @@
         return this.original;
     }
     
-    public void resetHeaders() {
-        // Make a copy of original headers
-        this.headergroup.clear();
-        setHeaders(this.original.getAllHeaders());
+    public boolean isRepeatable() {
+        return true;
+    }
+
+    public int getExecCount() {
+        return this.execCount;
+    }
+    
+    public void incrementExecCount() {
+        this.execCount++;
     }
     
 }

Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=664326&r1=664325&r2=664326&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Sat Jun  7 04:48:27 2008
@@ -50,7 +50,7 @@
 import org.apache.http.HttpStatus;
 import org.apache.http.ProtocolVersion;
 import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.client.NonRepeatableEntityException;
+import org.apache.http.client.NonRepeatableRequestException;
 import org.apache.http.client.methods.AbortableHttpRequest;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPost;
@@ -727,7 +727,7 @@
         try {
             client.execute(getServerHttp(), httppost, context);
             fail("NonRepeatableEntityException should have been thrown");
-        } catch (NonRepeatableEntityException ex) {
+        } catch (NonRepeatableRequestException ex) {
            // expected
         }
     }



Mime
View raw message