hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject httpcomponents-client git commit: [HTTPCLIENT-1865] DefaultServiceUnavailableRetryStrategy does not respect HttpEntity#isRepeatable.
Date Tue, 01 Aug 2017 06:07:58 GMT
Repository: httpcomponents-client
Updated Branches:
  refs/heads/4.6.x 88c261d8c -> 8ec17b682


[HTTPCLIENT-1865] DefaultServiceUnavailableRetryStrategy does not
respect HttpEntity#isRepeatable.

Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/8ec17b68
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/8ec17b68
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/8ec17b68

Branch: refs/heads/4.6.x
Commit: 8ec17b68222b7907852badc7d9efa9ebdaa18bf9
Parents: 88c261d
Author: Tomas Celaya <tjcelaya@joyent.com>
Authored: Mon Jul 31 23:07:56 2017 -0700
Committer: Gary Gregory <ggregory@apache.org>
Committed: Mon Jul 31 23:07:56 2017 -0700

----------------------------------------------------------------------
 RELEASE_NOTES.txt                               |  3 ++
 .../execchain/ServiceUnavailableRetryExec.java  |  3 +-
 .../TestServiceUnavailableRetryExec.java        | 32 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8ec17b68/RELEASE_NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index c42c3a1..cd76eec 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -8,6 +8,9 @@ Please note that as of 4.4 HttpClient requires Java 1.6 or newer.
 Change log:
 -------------------
 
+* [HTTPCLIENT-1865] DefaultServiceUnavailableRetryStrategy does not respect HttpEntity#isRepeatable.
+  Contributed by Tomas Celaya <tjcelaya at joyent dot com>
+
 * [HTTPCLIENT-1833] Fix Windows Negotiate-NTLM handling of proxies.
   Contributed by Roman Stoffel <roman.stoffel at gamler.info>
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8ec17b68/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
----------------------------------------------------------------------
diff --git a/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
b/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
index 8b0c6f4..f2131df 100644
--- a/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
+++ b/httpclient/src/main/java/org/apache/http/impl/execchain/ServiceUnavailableRetryExec.java
@@ -85,7 +85,8 @@ public class ServiceUnavailableRetryExec implements ClientExecChain {
             final CloseableHttpResponse response = this.requestExecutor.execute(
                     route, request, context, execAware);
             try {
-                if (this.retryStrategy.retryRequest(response, c, context)) {
+                if (this.retryStrategy.retryRequest(response, c, context)
+                        && RequestEntityProxy.isRepeatable(request)) {
                     response.close();
                     final long nextInterval = this.retryStrategy.getRetryInterval();
                     if (nextInterval > 0) {

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8ec17b68/httpclient/src/test/java/org/apache/http/impl/execchain/TestServiceUnavailableRetryExec.java
----------------------------------------------------------------------
diff --git a/httpclient/src/test/java/org/apache/http/impl/execchain/TestServiceUnavailableRetryExec.java
b/httpclient/src/test/java/org/apache/http/impl/execchain/TestServiceUnavailableRetryExec.java
index 8356b6f..bd4f27b 100644
--- a/httpclient/src/test/java/org/apache/http/impl/execchain/TestServiceUnavailableRetryExec.java
+++ b/httpclient/src/test/java/org/apache/http/impl/execchain/TestServiceUnavailableRetryExec.java
@@ -26,12 +26,14 @@
  */
 package org.apache.http.impl.execchain;
 
+import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ServiceUnavailableRetryStrategy;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpExecutionAware;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpRequestWrapper;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.conn.routing.HttpRoute;
@@ -115,4 +117,34 @@ public class TestServiceUnavailableRetryExec {
             throw ex;
         }
     }
+
+    @Test
+    public void testNonRepeatableEntityResponseReturnedImmediately() throws Exception {
+        final HttpRoute route = new HttpRoute(target);
+
+        final HttpEntity entity = Mockito.mock(HttpEntity.class);
+        Mockito.when(entity.isRepeatable()).thenReturn(Boolean.FALSE);
+
+        final HttpPut put = new HttpPut("/test");
+        put.setEntity(entity);
+
+        final HttpRequestWrapper request = HttpRequestWrapper.wrap(put);
+        final HttpClientContext context = HttpClientContext.create();
+        final CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
+
+        Mockito.when(requestExecutor.execute(
+                Mockito.eq(route),
+                Mockito.<HttpRequestWrapper>any(),
+                Mockito.<HttpClientContext>any(),
+                Mockito.<HttpExecutionAware>any())).thenReturn(response);
+
+        Mockito.when(retryStrategy.retryRequest(
+                Mockito.<HttpResponse>any(),
+                Mockito.anyInt(),
+                Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE, Boolean.FALSE);
+
+        retryExec.execute(route, request, context, execAware);
+
+        Mockito.verify(response, Mockito.times(0)).close();
+    }
 }


Mime
View raw message