hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r957015 - in /httpcomponents/httpclient/branches/4.0.x: ./ httpclient/src/main/java/org/apache/http/impl/client/ httpclient/src/test/java/org/apache/http/impl/client/
Date Tue, 22 Jun 2010 20:24:40 GMT
Author: olegk
Date: Tue Jun 22 20:24:39 2010
New Revision: 957015

URL: http://svn.apache.org/viewvc?rev=957015&view=rev
Log:
HTTPCLIENT-951: Non-repeatable entity enclosing requests are not correctly retried when 'expect-continue'
handshake is active


Modified:
    httpcomponents/httpclient/branches/4.0.x/   (props changed)
    httpcomponents/httpclient/branches/4.0.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
    httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
    httpcomponents/httpclient/branches/4.0.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java

Propchange: httpcomponents/httpclient/branches/4.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 22 20:24:39 2010
@@ -1 +1 @@
-/httpcomponents/httpclient/trunk:825864-828185,954258
+/httpcomponents/httpclient/trunk:825864-828185,954258,956989-957002

Modified: httpcomponents/httpclient/branches/4.0.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.0.x/RELEASE_NOTES.txt?rev=957015&r1=957014&r2=957015&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.0.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.0.x/RELEASE_NOTES.txt Tue Jun 22 20:24:39 2010
@@ -1,6 +1,10 @@
 Changes since 4.0.1
 -------------------
 
+* [HTTPCLIENT-951] Non-repeatable entity enclosing requests are not correctly
+  retried when 'expect-continue' handshake is active.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-953] IllegalStateException thrown by RouteSpecificPool.
   Contributed by Guillaume <gueugaie at gmail.com>
 

Modified: httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java?rev=957015&r1=957014&r2=957015&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/DefaultRequestDirector.java
Tue Jun 22 20:24:39 2010
@@ -464,7 +464,7 @@ public class DefaultRequestDirector impl
                     execCount++;
                     // Increment exec count for this particular request
                     wrapper.incrementExecCount();
-                    if (wrapper.getExecCount() > 1 && !wrapper.isRepeatable())
{
+                    if (!wrapper.isRepeatable()) {
                         this.log.debug("Cannot retry non-repeatable request");
                         if (retryReason != null) {
                             throw new NonRepeatableRequestException("Cannot retry request
" +

Modified: httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java?rev=957015&r1=957014&r2=957015&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
(original)
+++ httpcomponents/httpclient/branches/4.0.x/httpclient/src/main/java/org/apache/http/impl/client/EntityEnclosingRequestWrapper.java
Tue Jun 22 20:24:39 2010
@@ -27,7 +27,12 @@
 
 package org.apache.http.impl.client;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
 import org.apache.http.annotation.NotThreadSafe;
+import org.apache.http.entity.HttpEntityWrapper;
 
 import org.apache.http.Header;
 import org.apache.http.HttpEntity;
@@ -51,11 +56,12 @@ public class EntityEnclosingRequestWrapp
     implements HttpEntityEnclosingRequest {
     
     private HttpEntity entity;
+    private boolean consumed;
     
-    public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request) 
+    public EntityEnclosingRequestWrapper(final HttpEntityEnclosingRequest request)
         throws ProtocolException {
         super(request);
-        this.entity = request.getEntity();
+        setEntity(request.getEntity());
     }
 
     public HttpEntity getEntity() {
@@ -63,7 +69,8 @@ public class EntityEnclosingRequestWrapp
     }
 
     public void setEntity(final HttpEntity entity) {
-        this.entity = entity;
+        this.entity = entity != null ? new EntityWrapper(entity) : null;
+        this.consumed = false;
     }
     
     public boolean expectContinue() {
@@ -73,7 +80,33 @@ public class EntityEnclosingRequestWrapp
 
     @Override
     public boolean isRepeatable() {
-        return this.entity == null || this.entity.isRepeatable();
+        return this.entity == null || this.entity.isRepeatable() || !this.consumed;
+    }
+    
+    class EntityWrapper extends HttpEntityWrapper {
+        
+        EntityWrapper(final HttpEntity entity) {
+            super(entity);
+        }
+
+        @Override
+        public void consumeContent() throws IOException {
+            consumed = true;
+            super.consumeContent();
+        }
+
+        @Override
+        public InputStream getContent() throws IOException {
+            consumed = true;
+            return super.getContent();
+        }
+
+        @Override
+        public void writeTo(final OutputStream outstream) throws IOException {
+            consumed = true;
+            super.writeTo(outstream);
+        }
+        
     }
     
 }

Modified: httpcomponents/httpclient/branches/4.0.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.0.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java?rev=957015&r1=957014&r2=957015&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.0.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
(original)
+++ httpcomponents/httpclient/branches/4.0.x/httpclient/src/test/java/org/apache/http/impl/client/TestDefaultClientRequestDirector.java
Tue Jun 22 20:24:39 2010
@@ -658,12 +658,13 @@ public class TestDefaultClientRequestDir
                 final HttpClientConnection conn, 
                 final HttpContext context) throws IOException, HttpException {
             
+            HttpResponse response = super.execute(request, conn, context);
             Object marker = context.getAttribute(MARKER);
             if (marker == null) {
                 context.setAttribute(MARKER, Boolean.TRUE);
                 throw new IOException(failureMsg);
             }
-            return super.execute(request, conn, context);
+            return response;
         }
         
     }
@@ -744,6 +745,16 @@ public class TestDefaultClientRequestDir
         String failureMsg = "a message showing that this failed";
         
         FaultyHttpClient client = new FaultyHttpClient(failureMsg); 
+        client.setHttpRequestRetryHandler(new HttpRequestRetryHandler() {
+
+            public boolean retryRequest(
+                    final IOException exception,
+                    int executionCount,
+                    final HttpContext context) {
+                return true;
+            }
+
+        });
         HttpContext context = new BasicHttpContext();
 
         String s = "http://localhost:" + port;



Mime
View raw message