You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2021/03/26 07:14:48 UTC
[httpcomponents-client] branch master updated (bde58d6 -> 18e3965)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.
from bde58d6 Fixed NPE during dispose in Response if entity is null
new f437bdd Deprecated message copiers in favor of generic message builders
new 1633e29 Cleanup of redirect request generation code in Redirect exec interceptors
new 18e3965 HTTPCLIENT-2141: HttpClient to not retry requests if the retry interval exceeds the response timeout
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../hc/client5/http/impl/cache/CachingExec.java | 14 ++---
.../http/impl/cache/AbstractProtocolTest.java | 6 +-
.../impl/cache/TestConditionalRequestBuilder.java | 10 ++--
.../client5/http/impl/async/AsyncRedirectExec.java | 6 +-
.../http/impl/classic/HttpRequestRetryExec.java | 13 ++++-
.../impl/classic/TestHttpRequestRetryExec.java | 66 ++++++++++++++++++++++
6 files changed, 95 insertions(+), 20 deletions(-)
[httpcomponents-client] 02/03: Cleanup of redirect request
generation code in Redirect exec interceptors
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 1633e29c10528cbe8da56bccc17aad3fbb356ec2
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Feb 10 11:40:42 2021 +0100
Cleanup of redirect request generation code in Redirect exec interceptors
---
.../org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
index b5c7eaf..9304e62 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRedirectExec.java
@@ -26,9 +26,6 @@
*/
package org.apache.hc.client5.http.impl.async;
-import java.io.IOException;
-import java.net.URI;
-
import org.apache.hc.client5.http.CircularRedirectException;
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.RedirectException;
@@ -60,6 +57,9 @@ import org.apache.hc.core5.util.LangUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.net.URI;
+
/**
* Request execution handler in the asynchronous request execution chain
* responsible for handling of request redirects.
[httpcomponents-client] 03/03: HTTPCLIENT-2141: HttpClient to not
retry requests if the retry interval exceeds the response timeout
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit 18e39656971ecf2c0d99e0587c26688175dc7c21
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Mar 24 19:35:55 2021 +0100
HTTPCLIENT-2141: HttpClient to not retry requests if the retry interval exceeds the response timeout
---
.../http/impl/classic/HttpRequestRetryExec.java | 13 ++++-
.../impl/classic/TestHttpRequestRetryExec.java | 66 ++++++++++++++++++++++
2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
index ffed450..71e2221 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/HttpRequestRetryExec.java
@@ -34,6 +34,7 @@ import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChain.Scope;
import org.apache.hc.client5.http.classic.ExecChainHandler;
+import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.Internal;
@@ -46,6 +47,7 @@ import org.apache.hc.core5.http.NoHttpResponseException;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -133,9 +135,16 @@ public class HttpRequestRetryExec implements ExecChainHandler {
return response;
}
if (retryStrategy.retryRequest(response, execCount, context)) {
+ final TimeValue nextInterval = retryStrategy.getRetryInterval(response, execCount, context);
+ // Make sure the retry interval does not exceed the response timeout
+ if (TimeValue.isPositive(nextInterval)) {
+ final RequestConfig requestConfig = context.getRequestConfig();
+ final Timeout responseTimeout = requestConfig.getResponseTimeout();
+ if (responseTimeout != null && nextInterval.compareTo(responseTimeout) > 0) {
+ return response;
+ }
+ }
response.close();
- final TimeValue nextInterval =
- retryStrategy.getRetryInterval(response, execCount, context);
if (TimeValue.isPositive(nextInterval)) {
try {
if (LOG.isDebugEnabled()) {
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
index 83a1b83..2c3e919 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestHttpRequestRetryExec.java
@@ -36,6 +36,7 @@ import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecRuntime;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.entity.EntityBuilder;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -47,6 +48,7 @@ import org.apache.hc.core5.http.HttpResponse;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.apache.hc.core5.http.protocol.HttpContext;
import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -106,6 +108,70 @@ public class TestHttpRequestRetryExec {
Mockito.verify(response, Mockito.times(1)).close();
}
+ @Test
+ public void testRetryIntervalGreaterResponseTimeout() throws Exception {
+ final HttpRoute route = new HttpRoute(target);
+ final HttpGet request = new HttpGet("/test");
+ final HttpClientContext context = HttpClientContext.create();
+ context.setRequestConfig(RequestConfig.custom()
+ .setResponseTimeout(Timeout.ofSeconds(3))
+ .build());
+
+ final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
+
+ Mockito.when(chain.proceed(
+ Mockito.same(request),
+ Mockito.<ExecChain.Scope>any())).thenReturn(response);
+ Mockito.when(retryStrategy.retryRequest(
+ Mockito.<HttpResponse>any(),
+ Mockito.anyInt(),
+ Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE, Boolean.FALSE);
+ Mockito.when(retryStrategy.getRetryInterval(
+ Mockito.<HttpResponse>any(),
+ Mockito.anyInt(),
+ Mockito.<HttpContext>any())).thenReturn(TimeValue.ofSeconds(5));
+
+ final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
+ retryExec.execute(request, scope, chain);
+
+ Mockito.verify(chain, Mockito.times(1)).proceed(
+ Mockito.<ClassicHttpRequest>any(),
+ Mockito.same(scope));
+ Mockito.verify(response, Mockito.times(0)).close();
+ }
+
+ @Test
+ public void testRetryIntervalResponseTimeoutNull() throws Exception {
+ final HttpRoute route = new HttpRoute(target);
+ final HttpGet request = new HttpGet("/test");
+ final HttpClientContext context = HttpClientContext.create();
+ context.setRequestConfig(RequestConfig.custom()
+ .setResponseTimeout(null)
+ .build());
+
+ final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
+
+ Mockito.when(chain.proceed(
+ Mockito.same(request),
+ Mockito.<ExecChain.Scope>any())).thenReturn(response);
+ Mockito.when(retryStrategy.retryRequest(
+ Mockito.<HttpResponse>any(),
+ Mockito.anyInt(),
+ Mockito.<HttpContext>any())).thenReturn(Boolean.TRUE, Boolean.FALSE);
+ Mockito.when(retryStrategy.getRetryInterval(
+ Mockito.<HttpResponse>any(),
+ Mockito.anyInt(),
+ Mockito.<HttpContext>any())).thenReturn(TimeValue.ofSeconds(1));
+
+ final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context);
+ retryExec.execute(request, scope, chain);
+
+ Mockito.verify(chain, Mockito.times(2)).proceed(
+ Mockito.<ClassicHttpRequest>any(),
+ Mockito.same(scope));
+ Mockito.verify(response, Mockito.times(1)).close();
+ }
+
@Test(expected = RuntimeException.class)
public void testStrategyRuntimeException() throws Exception {
final HttpRoute route = new HttpRoute(target);
[httpcomponents-client] 01/03: Deprecated message copiers in favor
of generic message builders
Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git
commit f437bdd84236cb6173cbf855d4e8e22d06f1a61b
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Wed Feb 10 09:43:55 2021 +0100
Deprecated message copiers in favor of generic message builders
---
.../org/apache/hc/client5/http/impl/cache/CachingExec.java | 14 +++++++-------
.../hc/client5/http/impl/cache/AbstractProtocolTest.java | 6 +++---
.../http/impl/cache/TestConditionalRequestBuilder.java | 10 +++++-----
3 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
index fa702e0..d6b11fd 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java
@@ -26,13 +26,6 @@
*/
package org.apache.hc.client5.http.impl.cache;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ScheduledExecutorService;
-
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.async.methods.SimpleBody;
import org.apache.hc.client5.http.async.methods.SimpleHttpResponse;
@@ -71,6 +64,13 @@ import org.apache.hc.core5.util.ByteArrayBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+
/**
* <p>
* Request executor in the request execution chain that is responsible for
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
index 8d83f7f..2a36752 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/AbstractProtocolTest.java
@@ -26,9 +26,6 @@
*/
package org.apache.hc.client5.http.impl.cache;
-import java.io.IOException;
-import java.util.HashMap;
-
import org.apache.hc.client5.http.HttpRoute;
import org.apache.hc.client5.http.classic.ExecChain;
import org.apache.hc.client5.http.classic.ExecChainHandler;
@@ -47,6 +44,9 @@ import org.easymock.EasyMock;
import org.easymock.IExpectationSetters;
import org.junit.Before;
+import java.io.IOException;
+import java.util.HashMap;
+
public abstract class AbstractProtocolTest {
protected static final int MAX_BYTES = 1024;
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
index 186b886..6bcdd98 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestConditionalRequestBuilder.java
@@ -26,11 +26,6 @@
*/
package org.apache.hc.client5.http.impl.cache;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
import org.apache.hc.client5.http.cache.HeaderConstants;
import org.apache.hc.client5.http.cache.HttpCacheEntry;
import org.apache.hc.client5.http.utils.DateUtils;
@@ -46,6 +41,11 @@ import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
public class TestConditionalRequestBuilder {
private ConditionalRequestBuilder<HttpRequest> impl;