From 9ac5808bdbb045fedbbe99b3ca7366e50ab26b31 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 30 Sep 2017 23:00:45 +0200 Subject: [PATCH] Added MessageCopier and implementations for HttpRequest and ClassicHttpRequest messages; removed message copy methods from ExecSupport --- .../impl/cache/ConditionalRequestBuilder.java | 8 +- .../impl/cache/RequestProtocolCompliance.java | 6 +- .../http/impl/cache/AbstractProtocolTest.java | 5 +- .../TestAsynchronousValidationRequest.java | 2 +- .../impl/cache/TestAsynchronousValidator.java | 6 +- .../http/impl/cache/TestCachingExec.java | 2 +- .../http/impl/cache/TestCachingExecChain.java | 39 +++++----- .../cache/TestConditionalRequestBuilder.java | 20 ++--- ...ponentialBackingOffSchedulingStrategy.java | 2 +- .../cache/TestHttpCacheJiraNumber1147.java | 2 +- .../impl/cache/TestProtocolDeviations.java | 5 +- .../cache/TestRequestProtocolCompliance.java | 20 ++--- .../cache/TestResponseProtocolCompliance.java | 10 +-- .../hc/client5/http/classic/ExecChain.java | 4 +- .../hc/client5/http/impl/ExecSupport.java | 73 ------------------- .../hc/client5/http/impl/MessageCopier.java | 41 +++++++++++ .../hc/client5/http/impl/RequestCopier.java | 53 ++++++++++++++ .../http/impl/async/AsyncRetryExec.java | 4 +- .../impl/async/InternalHttpAsyncClient.java | 3 +- .../impl/classic/ClassicRequestCopier.java | 55 ++++++++++++++ .../http/impl/classic/InternalHttpClient.java | 5 +- .../http/impl/classic/RedirectExec.java | 1 + .../client5/http/impl/classic/RetryExec.java | 3 +- .../classic/ServiceUnavailableRetryExec.java | 3 +- .../http/impl/classic/TestConnectExec.java | 18 ++--- .../classic/TestContentCompressionExec.java | 2 +- .../http/impl/classic/TestMainClientExec.java | 18 ++--- .../http/impl/classic/TestProtocolExec.java | 16 ++-- .../http/impl/classic/TestRedirectExec.java | 12 +-- .../http/impl/classic/TestRetryExec.java | 13 ++-- .../TestServiceUnavailableRetryExec.java | 6 +- 31 files changed, 267 insertions(+), 190 deletions(-) create mode 100644 httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java create mode 100644 httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java create mode 100644 httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java index 73324ba13..d298c93af 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/ConditionalRequestBuilder.java @@ -31,7 +31,7 @@ import org.apache.hc.client5.http.cache.HeaderConstants; import org.apache.hc.client5.http.cache.HttpCacheEntry; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; import org.apache.hc.core5.http.ClassicHttpRequest; @@ -59,7 +59,7 @@ class ConditionalRequestBuilder { */ public ClassicHttpRequest buildConditionalRequest(final ClassicHttpRequest request, final HttpCacheEntry cacheEntry) throws ProtocolException { - final ClassicHttpRequest newRequest = ExecSupport.copy(request); + final ClassicHttpRequest newRequest = ClassicRequestCopier.INSTANCE.copy(request); newRequest.setHeaders(request.getAllHeaders()); final Header eTag = cacheEntry.getFirstHeader(HeaderConstants.ETAG); if (eTag != null) { @@ -99,7 +99,7 @@ public ClassicHttpRequest buildConditionalRequest(final ClassicHttpRequest reque */ public ClassicHttpRequest buildConditionalRequestFromVariants(final ClassicHttpRequest request, final Map variants) { - final ClassicHttpRequest newRequest = ExecSupport.copy(request); + final ClassicHttpRequest newRequest = ClassicRequestCopier.INSTANCE.copy(request); newRequest.setHeaders(request.getAllHeaders()); // we do not support partial content so all etags are used @@ -128,7 +128,7 @@ public ClassicHttpRequest buildConditionalRequestFromVariants(final ClassicHttpR * @return an unconditional validation request */ public ClassicHttpRequest buildUnconditionalRequest(final ClassicHttpRequest request) { - final ClassicHttpRequest newRequest = ExecSupport.copy(request); + final ClassicHttpRequest newRequest = ClassicRequestCopier.INSTANCE.copy(request); newRequest.addHeader(HeaderConstants.CACHE_CONTROL,HeaderConstants.CACHE_CONTROL_NO_CACHE); newRequest.addHeader(HeaderConstants.PRAGMA,HeaderConstants.CACHE_CONTROL_NO_CACHE); newRequest.removeHeaders(HeaderConstants.IF_RANGE); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java index 92757e048..c21b80dec 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/RequestProtocolCompliance.java @@ -257,6 +257,9 @@ private void add100ContinueHeaderIfMissing(final HttpRequest request) { protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpRequest request) { final ProtocolVersion requestProtocol = request.getVersion(); + if (requestProtocol == null) { + return false; + } if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) { return false; } @@ -269,7 +272,8 @@ protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(final HttpReque } protected boolean requestVersionIsTooLow(final HttpRequest request) { - return request.getVersion().compareToVersion(HttpVersion.HTTP_1_1) < 0; + final ProtocolVersion requestProtocol = request.getVersion(); + return requestProtocol != null && requestProtocol.compareToVersion(HttpVersion.HTTP_1_1) < 0; } /** 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 7a5be9d4a..395c9a319 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 @@ -33,7 +33,7 @@ import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; import org.apache.hc.client5.http.classic.ExecRuntime; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; @@ -107,7 +107,8 @@ public void setUp() { } public ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException { - return impl.execute(ExecSupport.copy(request), new ExecChain.Scope(route, request, mockEndpoint, context), mockExecChain); + return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope( + "test", route, request, mockEndpoint, context), mockExecChain); } protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig config) { diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java index 8f585d764..227f24046 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidationRequest.java @@ -75,7 +75,7 @@ public void setUp() { execChain = mock(ExecChain.class); mockCacheEntry = mock(HttpCacheEntry.class); mockResponse = mock(ClassicHttpResponse.class); - scope = new ExecChain.Scope(route, request, mockEndpoint, context); + scope = new ExecChain.Scope("test", route, request, mockEndpoint, context); } @Test diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java index 9e53c4be5..06c42ac78 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAsynchronousValidator.java @@ -82,7 +82,7 @@ public void setUp() { mockEndpoint = mock(ExecRuntime.class); mockCacheEntry = mock(HttpCacheEntry.class); mockSchedulingStrategy = mock(SchedulingStrategy.class); - scope = new ExecChain.Scope(route, request, mockEndpoint, context); + scope = new ExecChain.Scope("test", route, request, mockEndpoint, context); } @Test @@ -167,9 +167,9 @@ public void testVariantsBothRevalidated() { new BasicHeaderIterator(variantHeaders, HeaderConstants.VARY)); mockSchedulingStrategy.schedule(isA(AsynchronousValidationRequest.class)); - impl.revalidateCacheEntry(mockClient, host, req1, new ExecChain.Scope(route, req1, mockEndpoint, context), + impl.revalidateCacheEntry(mockClient, host, req1, new ExecChain.Scope("test", route, req1, mockEndpoint, context), mockExecChain, mockCacheEntry); - impl.revalidateCacheEntry(mockClient, host, req2, new ExecChain.Scope(route, req2, mockEndpoint, context), + impl.revalidateCacheEntry(mockClient, host, req2, new ExecChain.Scope("test", route, req2, mockEndpoint, context), mockExecChain, mockCacheEntry); verify(mockCacheEntry, times(2)).hasVariants(); diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java index 21facaa2c..366dea09f 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExec.java @@ -91,7 +91,7 @@ public class TestCachingExec extends TestCachingExecChain { public void setUp() { super.setUp(); - scope = new ExecChain.Scope(route, request, mockEndpoint, context); + scope = new ExecChain.Scope("test", route, request, mockEndpoint, context); mockBackendResponse = createNiceMock(ClassicHttpResponse.class); requestDate = new Date(System.currentTimeMillis() - 1000); diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java index cc8d86a4c..bd9f0a83f 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestCachingExecChain.java @@ -58,7 +58,7 @@ 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.HttpOptions; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.core5.http.ClassicHttpRequest; @@ -162,7 +162,8 @@ public abstract ExecChainHandler createCachingExecChain(HttpCache responseCache, public abstract ExecChainHandler createCachingExecChain(HttpCache cache, CacheConfig config); protected ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException { - return impl.execute(ExecSupport.copy(request), new ExecChain.Scope(route, request, mockEndpoint, context), mockExecChain); + return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope( + "test", route, request, mockEndpoint, context), mockExecChain); } public static ClassicHttpRequest eqRequest(final ClassicHttpRequest in) { @@ -1349,8 +1350,8 @@ public void testDoesNotSetConnectionInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), backend); } @Test @@ -1361,8 +1362,8 @@ public void testSetsTargetHostInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), backend); } @Test @@ -1373,8 +1374,8 @@ public void testSetsRouteInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), backend); assertEquals(route, ctx.getHttpRoute()); } @@ -1386,8 +1387,8 @@ public void testSetsRequestInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), backend); if (!HttpTestUtils.equivalent(request, ctx.getRequest())) { assertSame(request, ctx.getRequest()); } @@ -1401,8 +1402,8 @@ public void testSetsResponseInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - final ClassicHttpResponse result = impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), null); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + final ClassicHttpResponse result = impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), null); if (!HttpTestUtils.equivalent(result, ctx.getResponse())) { assertSame(result, ctx.getResponse()); } @@ -1416,8 +1417,8 @@ public void testSetsRequestSentInContextOnCacheHit() throws Exception { backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); final HttpClientContext ctx = HttpClientContext.create(); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, ctx), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, ctx), backend); } @Test @@ -1428,8 +1429,8 @@ public void testCanCacheAResponseWithoutABody() throws Exception { final DummyBackend backend = new DummyBackend(); backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); assertEquals(1, backend.getExecutions()); } @@ -1581,12 +1582,12 @@ public void testUsesVirtualHostForCacheKey() throws Exception { response.setHeader("Cache-Control", "max-age=3600"); backend.setResponse(response); impl = createCachingExecChain(new BasicHttpCache(), CacheConfig.DEFAULT); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); assertEquals(1, backend.getExecutions()); request.setAuthority(new URIAuthority("bar.example.com")); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); assertEquals(2, backend.getExecutions()); - impl.execute(request, new ExecChain.Scope(route, request, mockEndpoint, context), backend); + impl.execute(request, new ExecChain.Scope("test", route, request, mockEndpoint, context), backend); assertEquals(2, backend.getExecutions()); } 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 bdf7fc4ad..d5c596eb5 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 @@ -34,13 +34,12 @@ import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.cache.HeaderConstants; import org.apache.hc.client5.http.cache.HttpCacheEntry; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HeaderElement; import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.HttpVersion; import org.apache.hc.core5.http.ProtocolException; import org.apache.hc.core5.http.message.BasicClassicHttpRequest; import org.apache.hc.core5.http.message.BasicHeader; @@ -72,7 +71,7 @@ public void testBuildConditionalRequestWithLastModified() throws ProtocolExcepti final ClassicHttpRequest basicRequest = new BasicClassicHttpRequest(theMethod, theUri); basicRequest.addHeader("Accept-Encoding", "gzip"); - final ClassicHttpRequest requestWrapper = ExecSupport.copy(basicRequest); + final ClassicHttpRequest requestWrapper = ClassicRequestCopier.INSTANCE.copy(basicRequest); final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatDate(new Date())), @@ -108,7 +107,7 @@ public void testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsV new BasicHeader("ETag", etag) }; final ClassicHttpRequest basicRequest = new BasicClassicHttpRequest("GET", "/"); - final ClassicHttpRequest requestWrapper = ExecSupport.copy(basicRequest); + final ClassicHttpRequest requestWrapper = ClassicRequestCopier.INSTANCE.copy(basicRequest); final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers); final ClassicHttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry); Assert.assertEquals(lmDate, @@ -125,7 +124,7 @@ public void testBuildConditionalRequestWithETag() throws ProtocolException { final ClassicHttpRequest basicRequest = new BasicClassicHttpRequest(theMethod, theUri); basicRequest.addHeader("Accept-Encoding", "gzip"); - final ClassicHttpRequest requestWrapper = ExecSupport.copy(basicRequest); + final ClassicHttpRequest requestWrapper = ClassicRequestCopier.INSTANCE.copy(basicRequest); final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils.formatDate(new Date())), @@ -153,7 +152,7 @@ public void testBuildConditionalRequestWithETag() throws ProtocolException { @Test public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception { final ClassicHttpRequest basicRequest = new BasicClassicHttpRequest("GET","/"); - final ClassicHttpRequest requestWrapper = ExecSupport.copy(basicRequest); + final ClassicHttpRequest requestWrapper = ClassicRequestCopier.INSTANCE.copy(basicRequest); final Date now = new Date(); final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); @@ -182,7 +181,7 @@ public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Ex @Test public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception { final ClassicHttpRequest basicRequest = new BasicClassicHttpRequest("GET", "/"); - final ClassicHttpRequest requestWrapper = ExecSupport.copy(basicRequest); + final ClassicHttpRequest requestWrapper = ClassicRequestCopier.INSTANCE.copy(basicRequest); final Date now = new Date(); final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L); final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L); @@ -223,13 +222,6 @@ public void testBuildUnconditionalRequestUsesRequestUri() Assert.assertEquals(uri, result.getRequestUri()); } - @Test - public void testBuildUnconditionalRequestUsesHTTP_1_1() - throws Exception { - final ClassicHttpRequest result = impl.buildUnconditionalRequest(request); - Assert.assertEquals(HttpVersion.HTTP_1_1, result.getVersion()); - } - @Test public void testBuildUnconditionalRequestAddsCacheControlNoCache() throws Exception { diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestExponentialBackingOffSchedulingStrategy.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestExponentialBackingOffSchedulingStrategy.java index 5954c4314..277e82f71 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestExponentialBackingOffSchedulingStrategy.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestExponentialBackingOffSchedulingStrategy.java @@ -164,7 +164,7 @@ private AsynchronousValidationRequest createAsynchronousValidationRequest(final final HttpRoute route = new HttpRoute(host); final ClassicHttpRequest request = new BasicClassicHttpRequest("GET", "/"); final HttpClientContext context = new HttpClientContext(); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, mock(ExecRuntime.class), context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, mock(ExecRuntime.class), context); return new AsynchronousValidationRequest(mockValidator, cachingHttpClient, host, request, scope, mock(ExecChain.class), null, "identifier", errorCount); } diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java index da362a789..72aa987d3 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestHttpCacheJiraNumber1147.java @@ -116,7 +116,7 @@ public void testIssue1147() throws Exception { final BasicHttpCache cache = new BasicHttpCache(resourceFactory, httpCacheStorage, cacheConfig); final ExecChainHandler t = createCachingExecChain(cache, cacheConfig); - final ExecChain.Scope scope = new ExecChain.Scope(route, get, mockEndpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("teset", route, get, mockEndpoint, context); final ClassicHttpResponse response1 = t.execute(get, scope, mockExecChain); Assert.assertEquals(200, response1.getCode()); IOUtils.consume(response1.getEntity()); diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java index 0c59c04fc..48c5f6a47 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestProtocolDeviations.java @@ -36,7 +36,7 @@ import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; import org.apache.hc.client5.http.classic.ExecRuntime; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; @@ -122,7 +122,8 @@ public void setUp() { } private ClassicHttpResponse execute(final ClassicHttpRequest request) throws IOException, HttpException { - return impl.execute(ExecSupport.copy(request), new ExecChain.Scope(route, request, mockEndpoint, context), mockExecChain); + return impl.execute(ClassicRequestCopier.INSTANCE.copy(request), new ExecChain.Scope( + "test", route, request, mockEndpoint, context), mockExecChain); } protected ExecChainHandler createCachingExecChain(final HttpCache cache, final CacheConfig config) { diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java index ad9b25ae6..a538229c6 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestRequestProtocolCompliance.java @@ -33,7 +33,7 @@ import java.util.Arrays; import org.apache.hc.client5.http.classic.methods.HttpPut; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.HttpVersion; import org.apache.hc.core5.http.ProtocolVersion; @@ -82,7 +82,7 @@ public void testRequestContainsNoCacheDirectiveWithFieldName() throws Exception @Test public void doesNotModifyACompliantRequest() throws Exception { - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertTrue(HttpTestUtils.equivalent(req, wrapper)); } @@ -92,7 +92,7 @@ public void removesEntityFromTRACERequest() throws Exception { final ClassicHttpRequest request = new BasicClassicHttpRequest("TRACE", "/"); request.setVersion(HttpVersion.HTTP_1_1); request.setEntity(HttpTestUtils.makeBody(50)); - final ClassicHttpRequest wrapper = ExecSupport.copy(request); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(request); impl.makeRequestCompliant(wrapper); assertNull(wrapper.getEntity()); } @@ -101,7 +101,7 @@ public void removesEntityFromTRACERequest() throws Exception { public void upgrades1_0RequestTo1_1() throws Exception { req = new BasicClassicHttpRequest("GET", "/"); req.setVersion(HttpVersion.HTTP_1_0); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion()); } @@ -110,7 +110,7 @@ public void upgrades1_0RequestTo1_1() throws Exception { public void downgrades1_2RequestTo1_1() throws Exception { req = new BasicClassicHttpRequest("GET", "/"); req.setVersion(new ProtocolVersion("HTTP", 1, 2)); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals(HttpVersion.HTTP_1_1, wrapper.getVersion()); } @@ -119,7 +119,7 @@ public void downgrades1_2RequestTo1_1() throws Exception { public void stripsMinFreshFromRequestIfNoCachePresent() throws Exception { req.setHeader("Cache-Control", "no-cache, min-fresh=10"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals("no-cache", wrapper.getFirstHeader("Cache-Control").getValue()); @@ -129,7 +129,7 @@ public void stripsMinFreshFromRequestIfNoCachePresent() public void stripsMaxFreshFromRequestIfNoCachePresent() throws Exception { req.setHeader("Cache-Control", "no-cache, max-stale=10"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals("no-cache", wrapper.getFirstHeader("Cache-Control").getValue()); @@ -139,7 +139,7 @@ public void stripsMaxFreshFromRequestIfNoCachePresent() public void stripsMaxAgeFromRequestIfNoCachePresent() throws Exception { req.setHeader("Cache-Control", "no-cache, max-age=10"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals("no-cache", wrapper.getFirstHeader("Cache-Control").getValue()); @@ -149,7 +149,7 @@ public void stripsMaxAgeFromRequestIfNoCachePresent() public void doesNotStripMinFreshFromRequestWithoutNoCache() throws Exception { req.setHeader("Cache-Control", "min-fresh=10"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals("min-fresh=10", wrapper.getFirstHeader("Cache-Control").getValue()); @@ -159,7 +159,7 @@ public void doesNotStripMinFreshFromRequestWithoutNoCache() public void correctlyStripsMinFreshFromMiddleIfNoCache() throws Exception { req.setHeader("Cache-Control", "no-cache,min-fresh=10,no-store"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); impl.makeRequestCompliant(wrapper); assertEquals("no-cache,no-store", wrapper.getFirstHeader("Cache-Control").getValue()); diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java index e548e1870..7410c1bad 100644 --- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java +++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestResponseProtocolCompliance.java @@ -36,7 +36,7 @@ import org.apache.hc.client5.http.HttpRoute; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpHead; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.classic.ClassicRequestCopier; import org.apache.hc.client5.http.utils.DateUtils; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.ClassicHttpResponse; @@ -92,7 +92,7 @@ private ClassicHttpResponse makePartialResponse(final int nbytes) { @Test public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception { final HttpHead req = new HttpHead("http://foo.example.com/"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); final int nbytes = 128; final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_OK, "OK"); setMinimalResponseHeaders(resp); @@ -110,7 +110,7 @@ public void consumesBodyIfOriginSendsOneInResponseToHEAD() throws Exception { @Test(expected=ClientProtocolException.class) public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() throws Exception { final HttpGet req = new HttpGet("http://foo.example.com/"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); final int nbytes = 128; final ClassicHttpResponse resp = makePartialResponse(nbytes); resp.setEntity(HttpTestUtils.makeBody(nbytes)); @@ -121,7 +121,7 @@ public void throwsExceptionIfOriginReturnsPartialResponseWhenNotRequested() thro @Test public void consumesPartialContentFromOriginEvenIfNotRequested() throws Exception { final HttpGet req = new HttpGet("http://foo.example.com/"); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); final int nbytes = 128; final ClassicHttpResponse resp = makePartialResponse(nbytes); @@ -144,7 +144,7 @@ public void consumesBodyOf100ContinueResponseIfItArrives() throws Exception { req.setHeader("Content-Type", "application/octet-stream"); final HttpEntity postBody = new ByteArrayEntity(HttpTestUtils.getRandomBytes(nbytes)); req.setEntity(postBody); - final ClassicHttpRequest wrapper = ExecSupport.copy(req); + final ClassicHttpRequest wrapper = ClassicRequestCopier.INSTANCE.copy(req); final ClassicHttpResponse resp = new BasicClassicHttpResponse(HttpStatus.SC_CONTINUE, "Continue"); final Flag closed = new Flag(); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChain.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChain.java index 30ecc4772..fd1e92e27 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChain.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/ExecChain.java @@ -40,12 +40,14 @@ public interface ExecChain { final class Scope { + public final String exchangeId; public final HttpRoute route; public final ClassicHttpRequest originalRequest; public final ExecRuntime execRuntime; public final HttpClientContext clientContext; - public Scope(final HttpRoute route, final ClassicHttpRequest originalRequest, final ExecRuntime execRuntime, final HttpClientContext clientContext) { + public Scope(final String exchangeId, final HttpRoute route, final ClassicHttpRequest originalRequest, final ExecRuntime execRuntime, final HttpClientContext clientContext) { + this.exchangeId = Args.notNull(exchangeId, "Exchange id"); this.route = Args.notNull(route, "Route"); this.originalRequest = Args.notNull(originalRequest, "Original request"); this.execRuntime = Args.notNull(execRuntime, "Exec runtime"); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java index dc99528da..9be815370 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ExecSupport.java @@ -26,21 +26,8 @@ */ package org.apache.hc.client5.http.impl; -import java.util.Iterator; import java.util.concurrent.atomic.AtomicLong; -import org.apache.hc.core5.http.ClassicHttpRequest; -import org.apache.hc.core5.http.ClassicHttpResponse; -import org.apache.hc.core5.http.Header; -import org.apache.hc.core5.http.HttpMessage; -import org.apache.hc.core5.http.HttpRequest; -import org.apache.hc.core5.http.HttpResponse; -import org.apache.hc.core5.http.HttpVersion; -import org.apache.hc.core5.http.message.BasicClassicHttpRequest; -import org.apache.hc.core5.http.message.BasicClassicHttpResponse; -import org.apache.hc.core5.http.message.BasicHttpRequest; -import org.apache.hc.core5.http.message.BasicHttpResponse; - public final class ExecSupport { private static final AtomicLong COUNT = new AtomicLong(0); @@ -49,64 +36,4 @@ public static long getNextExecNumber() { return COUNT.incrementAndGet(); } - private static void copyMessageProperties(final HttpMessage original, final HttpMessage copy) { - copy.setVersion(original.getVersion()); - for (final Iterator
it = original.headerIterator(); it.hasNext(); ) { - copy.addHeader(it.next()); - } - } - - private static void copyRequestProperties(final HttpRequest original, final HttpRequest copy) { - copyMessageProperties(original, copy); - if (copy.getVersion() == null) { - copy.setVersion(HttpVersion.DEFAULT); - } - copy.setScheme(original.getScheme()); - copy.setAuthority(original.getAuthority()); - } - - private static void copyResponseProperties(final HttpResponse original, final HttpResponse copy) { - copyMessageProperties(original, copy); - copy.setLocale(copy.getLocale()); - copy.setReasonPhrase(copy.getReasonPhrase()); - } - - public static HttpRequest copy(final HttpRequest original) { - if (original == null) { - return null; - } - final BasicHttpRequest copy = new BasicHttpRequest(original.getMethod(), original.getPath()); - copyRequestProperties(original, copy); - return copy; - } - - public static HttpResponse copy(final HttpResponse original) { - if (original == null) { - return null; - } - final BasicHttpResponse copy = new BasicHttpResponse(original.getCode()); - copyResponseProperties(original, copy); - return copy; - } - - public static ClassicHttpRequest copy(final ClassicHttpRequest original) { - if (original == null) { - return null; - } - final BasicClassicHttpRequest copy = new BasicClassicHttpRequest(original.getMethod(), original.getPath()); - copyRequestProperties(original, copy); - copy.setEntity(original.getEntity()); - return copy; - } - - public static ClassicHttpResponse copy(final ClassicHttpResponse original) { - if (original == null) { - return null; - } - final BasicClassicHttpResponse copy = new BasicClassicHttpResponse(original.getCode()); - copyResponseProperties(original, copy); - copy.setEntity(original.getEntity()); - return copy; - } - } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java new file mode 100644 index 000000000..cd152ea40 --- /dev/null +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/MessageCopier.java @@ -0,0 +1,41 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.hc.client5.http.impl; + +import org.apache.hc.core5.http.HttpMessage; + +/** + * Abstract HTTP message cloner. + * + * @since 5.0 + */ +public interface MessageCopier { + + T copy(T object); + +} diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java new file mode 100644 index 000000000..b119018f5 --- /dev/null +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/RequestCopier.java @@ -0,0 +1,53 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.hc.client5.http.impl; + +import java.util.Iterator; + +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.HttpRequest; +import org.apache.hc.core5.http.message.BasicHttpRequest; + +public final class RequestCopier implements MessageCopier { + + public static final RequestCopier INSTANCE = new RequestCopier(); + + public HttpRequest copy(final HttpRequest original) { + if (original == null) { + return null; + } + final BasicHttpRequest copy = new BasicHttpRequest(original.getMethod(), original.getPath()); + copy.setVersion(original.getVersion()); + for (final Iterator
it = original.headerIterator(); it.hasNext(); ) { + copy.addHeader(it.next()); + } + copy.setScheme(original.getScheme()); + copy.setAuthority(original.getAuthority()); + return copy; + } + +} diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java index 162915ebb..82fc6f920 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncRetryExec.java @@ -33,7 +33,7 @@ import org.apache.hc.client5.http.async.AsyncExecCallback; import org.apache.hc.client5.http.async.AsyncExecChain; import org.apache.hc.client5.http.async.AsyncExecChainHandler; -import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.RequestCopier; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.http.EntityDetails; import org.apache.hc.core5.http.HttpException; @@ -64,7 +64,7 @@ private void internalExecute( final AsyncExecChain chain, final AsyncExecCallback asyncExecCallback) throws HttpException, IOException { - chain.proceed(ExecSupport.copy(request), entityProducer, scope, new AsyncExecCallback() { + chain.proceed(RequestCopier.INSTANCE.copy(request), entityProducer, scope, new AsyncExecCallback() { @Override public AsyncDataConsumer handleResponse( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java index c6f0d93a4..e1370e815 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/InternalHttpAsyncClient.java @@ -43,6 +43,7 @@ import org.apache.hc.client5.http.cookie.CookieSpecProvider; import org.apache.hc.client5.http.cookie.CookieStore; import org.apache.hc.client5.http.impl.ExecSupport; +import org.apache.hc.client5.http.impl.RequestCopier; import org.apache.hc.client5.http.nio.AsyncClientConnectionManager; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.client5.http.routing.HttpRoutePlanner; @@ -161,7 +162,7 @@ private void executeChain( final AsyncExecChain.Scope scope = new AsyncExecChain.Scope(exchangeId, route, request, clientContext, execRuntime); execChain.execute( - ExecSupport.copy(request), + RequestCopier.INSTANCE.copy(request), entityDetails != null ? new InternalAsyncEntityProducer(exchangeHandler, entityDetails) : null, scope, new AsyncExecCallback() { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java new file mode 100644 index 000000000..12f044d34 --- /dev/null +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ClassicRequestCopier.java @@ -0,0 +1,55 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ +package org.apache.hc.client5.http.impl.classic; + +import java.util.Iterator; + +import org.apache.hc.client5.http.impl.MessageCopier; +import org.apache.hc.core5.http.ClassicHttpRequest; +import org.apache.hc.core5.http.Header; +import org.apache.hc.core5.http.message.BasicClassicHttpRequest; + +public final class ClassicRequestCopier implements MessageCopier { + + public static final ClassicRequestCopier INSTANCE = new ClassicRequestCopier(); + + public ClassicHttpRequest copy(final ClassicHttpRequest original) { + if (original == null) { + return null; + } + final BasicClassicHttpRequest copy = new BasicClassicHttpRequest(original.getMethod(), original.getPath()); + copy.setVersion(original.getVersion()); + for (final Iterator
it = original.headerIterator(); it.hasNext(); ) { + copy.addHeader(it.next()); + } + copy.setScheme(original.getScheme()); + copy.setAuthority(original.getAuthority()); + copy.setEntity(original.getEntity()); + return copy; + } + +} diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java index b75980918..795938a09 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/InternalHttpClient.java @@ -157,10 +157,11 @@ protected CloseableHttpResponse doExecute( } setupContext(localcontext); final HttpRoute route = determineRoute(target, request, localcontext); + final String exchangeId = String.format("ex-%08X", ExecSupport.getNextExecNumber()); final ExecRuntime execRuntime = new ExecRuntimeImpl(log, connManager, requestExecutor, request instanceof CancellableAware ? (CancellableAware) request : null); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, localcontext); - final ClassicHttpResponse response = this.execChain.execute(ExecSupport.copy(request), scope); + final ExecChain.Scope scope = new ExecChain.Scope(exchangeId, route, request, execRuntime, localcontext); + final ClassicHttpResponse response = this.execChain.execute(ClassicRequestCopier.INSTANCE.copy(request), scope); return CloseableHttpResponse.adapt(response); } catch (final HttpException httpException) { throw new ClientProtocolException(httpException.getMessage(), httpException); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java index 556c9df06..a4fae9058 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RedirectExec.java @@ -159,6 +159,7 @@ public ClassicHttpResponse execute( } currentRoute = this.routePlanner.determineRoute(newTarget, context); currentScope = new ExecChain.Scope( + currentScope.exchangeId, currentRoute, currentScope.originalRequest, currentScope.execRuntime, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RetryExec.java index cd80c54e5..42167b171 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RetryExec.java @@ -34,7 +34,6 @@ import org.apache.hc.client5.http.NonRepeatableRequestException; import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; -import org.apache.hc.client5.http.impl.ExecSupport; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; @@ -106,7 +105,7 @@ public ClassicHttpResponse execute( throw new NonRepeatableRequestException("Cannot retry request " + "with a non-repeatable request entity", ex); } - currentRequest = ExecSupport.copy(scope.originalRequest); + currentRequest = ClassicRequestCopier.INSTANCE.copy(scope.originalRequest); if (this.log.isInfoEnabled()) { this.log.info("Retrying request to " + route); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ServiceUnavailableRetryExec.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ServiceUnavailableRetryExec.java index 970f96840..e36a02fce 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ServiceUnavailableRetryExec.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ServiceUnavailableRetryExec.java @@ -33,7 +33,6 @@ import org.apache.hc.client5.http.ServiceUnavailableRetryStrategy; import org.apache.hc.client5.http.classic.ExecChain; import org.apache.hc.client5.http.classic.ExecChainHandler; -import org.apache.hc.client5.http.impl.ExecSupport; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.annotation.Contract; import org.apache.hc.core5.annotation.ThreadingBehavior; @@ -101,7 +100,7 @@ public ClassicHttpResponse execute( throw new InterruptedIOException(); } } - currentRequest = ExecSupport.copy(scope.originalRequest); + currentRequest = ClassicRequestCopier.INSTANCE.copy(scope.originalRequest); } else { return response; } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java index 4f5d8bec2..20b1aa810 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java @@ -114,7 +114,7 @@ public void testExecAcquireConnection() throws Exception { Mockito.same(request), Mockito.same(response), Mockito.any())).thenReturn(false); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).acquireConnection(route, "Blah", context); Mockito.verify(execRuntime).connect(context); @@ -130,7 +130,7 @@ public void testEstablishDirectRoute() throws Exception { Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.any()); Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); @@ -147,7 +147,7 @@ public void testEstablishRouteDirectProxy() throws Exception { Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.any()); Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); @@ -168,7 +168,7 @@ public void testEstablishRouteViaProxyTunnel() throws Exception { Mockito.any(), Mockito.any())).thenReturn(response); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); @@ -197,7 +197,7 @@ public void testEstablishRouteViaProxyTunnelUnexpectedResponse() throws Exceptio Mockito.any(), Mockito.any())).thenReturn(response); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); } @@ -216,7 +216,7 @@ public void testEstablishRouteViaProxyTunnelFailure() throws Exception { Mockito.any(), Mockito.any())).thenReturn(response); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); try { exec.execute(request, scope, execChain); } catch (final TunnelRefusedException ex) { @@ -260,7 +260,7 @@ public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengePersistentConnec Mockito.>any(), Mockito.any())).thenReturn(Collections.singletonList(new BasicScheme())); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); @@ -300,7 +300,7 @@ public void testEstablishRouteViaProxyTunnelRetryOnAuthChallengeNonPersistentCon Mockito.>any(), Mockito.any())).thenReturn(Collections.singletonList(new BasicScheme())); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); @@ -321,7 +321,7 @@ public void testEstablishRouteViaProxyTunnelMultipleHops() throws Exception { Mockito.doAnswer(connectionState.connectAnswer()).when(execRuntime).connect(Mockito.any()); Mockito.when(execRuntime.isConnected()).thenAnswer(connectionState.isConnectedAnswer()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); exec.execute(request, scope, execChain); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java index 950b6fb3c..ff962013f 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestContentCompressionExec.java @@ -69,7 +69,7 @@ public class TestContentCompressionExec { public void setup() { host = new HttpHost("somehost", 80); context = HttpClientContext.create(); - scope = new ExecChain.Scope(new HttpRoute(host), originaRequest, execRuntime, context); + scope = new ExecChain.Scope("test", new HttpRoute(host), originaRequest, execRuntime, context); impl = new ContentCompressionExec(); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java index 10313d116..bef2fa037 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestMainClientExec.java @@ -96,7 +96,7 @@ public void testExecRequestNonPersistentConnection() throws Exception { Mockito.same(response), Mockito.any())).thenReturn(false); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null); Mockito.verify(endpoint).execute(request, context); Mockito.verify(endpoint, Mockito.times(1)).markConnectionNonReusable(); @@ -124,7 +124,7 @@ public void testExecRequestNonPersistentConnectionNoResponseEntity() throws Exce Mockito.same(response), Mockito.any())).thenReturn(false); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null); Mockito.verify(endpoint).execute(request, context); @@ -160,7 +160,7 @@ public void testExecRequestPersistentConnection() throws Exception { Mockito.same(response), Mockito.any())).thenReturn(TimeValue.ofMillis(678L)); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null); Mockito.verify(endpoint).execute(request, context); @@ -192,7 +192,7 @@ public void testExecRequestPersistentConnectionNoResponseEntity() throws Excepti Mockito.same(response), Mockito.any())).thenReturn(TimeValue.ofMillis(678L)); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null); Mockito.verify(endpoint).execute(request, context); @@ -224,7 +224,7 @@ public void testExecRequestConnectionRelease() throws Exception { Mockito.same(response), Mockito.any())).thenReturn(Boolean.FALSE); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = mainClientExec.execute(request, scope, null); Mockito.verify(endpoint, Mockito.times(1)).execute(request, context); Mockito.verify(endpoint, Mockito.never()).disconnect(); @@ -248,7 +248,7 @@ public void testExecConnectionShutDown() throws Exception { Mockito.same(request), Mockito.any())).thenThrow(new ConnectionShutdownException()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { mainClientExec.execute(request, scope, null); } catch (Exception ex) { @@ -267,7 +267,7 @@ public void testExecRuntimeException() throws Exception { Mockito.same(request), Mockito.any())).thenThrow(new RuntimeException("Ka-boom")); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { mainClientExec.execute(request, scope, null); } catch (final Exception ex) { @@ -286,7 +286,7 @@ public void testExecHttpException() throws Exception { Mockito.same(request), Mockito.any())).thenThrow(new HttpException("Ka-boom")); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { mainClientExec.execute(request, scope, null); } catch (final Exception ex) { @@ -305,7 +305,7 @@ public void testExecIOException() throws Exception { Mockito.same(request), Mockito.any())).thenThrow(new IOException("Ka-boom")); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { mainClientExec.execute(request, scope, null); } catch (final Exception ex) { diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java index 881af3452..ca498be93 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java @@ -111,7 +111,7 @@ public void testFundamentals() throws Exception { Mockito.any(), Mockito.any())).thenReturn(response); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); protocolExec.execute(request, scope, chain); Mockito.verify(httpProcessor).process(request, null, context); @@ -135,7 +135,7 @@ public void testUserInfoInRequestURI() throws Exception { Mockito.any(), Mockito.any())).thenReturn(response); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); protocolExec.execute(request, scope, chain); Assert.assertEquals(new URI("http://bar/test"), request.getUri()); final CredentialsProvider credentialsProvider = context.getCredentialsProvider(); @@ -157,7 +157,7 @@ public void testPostProcessHttpException() throws Exception { Mockito.any())).thenReturn(response); Mockito.doThrow(new HttpException("Ooopsie")).when(httpProcessor).process( Mockito.same(response), Mockito.isNull(), Mockito.any()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); try { protocolExec.execute(request, scope, chain); } catch (final Exception ex) { @@ -178,7 +178,7 @@ public void testPostProcessIOException() throws Exception { Mockito.any())).thenReturn(response); Mockito.doThrow(new IOException("Ooopsie")).when(httpProcessor).process( Mockito.same(response), Mockito.isNull(), Mockito.any()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); try { protocolExec.execute(request, scope, chain); } catch (final Exception ex) { @@ -199,7 +199,7 @@ public void testPostProcessRuntimeException() throws Exception { Mockito.any())).thenReturn(response); Mockito.doThrow(new RuntimeException("Ooopsie")).when(httpProcessor).process( Mockito.same(response), Mockito.isNull(), Mockito.any()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); try { protocolExec.execute(request, scope, chain); } catch (final Exception ex) { @@ -238,7 +238,7 @@ public void testExecRequestRetryOnAuthChallenge() throws Exception { Mockito.any())).thenReturn(Collections.singletonList(new BasicScheme())); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain); Mockito.verify(chain, Mockito.times(2)).proceed(request, scope); Mockito.verify(instream1).close(); @@ -284,7 +284,7 @@ public void testExecEntityEnclosingRequestRetryOnAuthChallenge() throws Exceptio Mockito.>any(), Mockito.any())).thenReturn(Collections.singletonList(new BasicScheme())); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain); Mockito.verify(chain, Mockito.times(2)).proceed(request, scope); Mockito.verify(execRuntime).disconnect(); @@ -334,7 +334,7 @@ public HttpResponse answer(final InvocationOnMock invocationOnMock) throws Throw Mockito.>any(), Mockito.any())).thenReturn(Collections.singletonList(new BasicScheme())); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, execRuntime, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); protocolExec.execute(request, scope, chain); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java index 0346ead34..2339a8912 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java @@ -122,7 +122,7 @@ public void testFundamentals() throws Exception { Mockito.eq(target), Mockito.any())).thenReturn(route); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); redirectExec.execute(request, scope, chain); final ArgumentCaptor reqCaptor = ArgumentCaptor.forClass( @@ -171,7 +171,7 @@ public void testMaxRedirect() throws Exception { Mockito.eq(target), Mockito.any())).thenReturn(route); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); redirectExec.execute(request, scope, chain); } @@ -202,7 +202,7 @@ public void testRelativeRedirect() throws Exception { Mockito.eq(target), Mockito.any())).thenReturn(route); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); redirectExec.execute(request, scope, chain); } @@ -248,7 +248,7 @@ public void testCrossSiteRedirect() throws Exception { Mockito.eq(otherHost), Mockito.any())).thenReturn(new HttpRoute(otherHost)); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); redirectExec.execute(request, scope, chain); final AuthExchange authExchange1 = context.getAuthExchange(target); @@ -280,7 +280,7 @@ public void testRedirectRuntimeException() throws Exception { Mockito.same(response1), Mockito.any())); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { redirectExec.execute(request, scope, chain); } catch (final Exception ex) { @@ -313,7 +313,7 @@ public void testRedirectProtocolException() throws Exception { Mockito.same(response1), Mockito.any()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { redirectExec.execute(request, scope, chain); } catch (final Exception ex) { diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRetryExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRetryExec.java index d21a022e7..030d1757d 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRetryExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRetryExec.java @@ -38,7 +38,6 @@ import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.entity.EntityBuilder; -import org.apache.hc.client5.http.impl.ExecSupport; import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.Header; @@ -104,8 +103,8 @@ public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { Mockito.any(), Mockito.eq(1), Mockito.any())).thenReturn(Boolean.TRUE); - final ExecChain.Scope scope = new ExecChain.Scope(route, originalRequest, endpoint, context); - final ClassicHttpRequest request = ExecSupport.copy(originalRequest); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context); + final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest); try { retryExec.execute(request, scope, chain); } catch (final IOException ex) { @@ -127,8 +126,8 @@ public void testAbortedRequest() throws Exception { Mockito.any())).thenThrow(new IOException("Ka-boom")); Mockito.when(endpoint.isExecutionAborted()).thenReturn(true); - final ExecChain.Scope scope = new ExecChain.Scope(route, originalRequest, endpoint, context); - final ClassicHttpRequest request = ExecSupport.copy(originalRequest); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context); + final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest); try { retryExec.execute(request, scope, chain); } catch (final IOException ex) { @@ -172,8 +171,8 @@ public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { Mockito.any(), Mockito.eq(1), Mockito.any())).thenReturn(Boolean.TRUE); - final ExecChain.Scope scope = new ExecChain.Scope(route, originalRequest, endpoint, context); - final ClassicHttpRequest request = ExecSupport.copy(originalRequest); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, originalRequest, endpoint, context); + final ClassicHttpRequest request = ClassicRequestCopier.INSTANCE.copy(originalRequest); try { retryExec.execute(request, scope, chain); } catch (final IOException ex) { diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestServiceUnavailableRetryExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestServiceUnavailableRetryExec.java index f6ab7b3c0..10371c8e3 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestServiceUnavailableRetryExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestServiceUnavailableRetryExec.java @@ -87,7 +87,7 @@ public void testFundamentals() throws Exception { Mockito.any(), Mockito.any())).thenReturn(0L); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); retryExec.execute(request, scope, chain); Mockito.verify(chain, Mockito.times(2)).proceed( @@ -110,7 +110,7 @@ public void testStrategyRuntimeException() throws Exception { Mockito.any(), Mockito.anyInt(), Mockito.any()); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); try { retryExec.execute(request, scope, chain); } catch (final Exception ex) { @@ -138,7 +138,7 @@ public void testNonRepeatableEntityResponseReturnedImmediately() throws Exceptio Mockito.anyInt(), Mockito.any())).thenReturn(Boolean.TRUE, Boolean.FALSE); - final ExecChain.Scope scope = new ExecChain.Scope(route, request, endpoint, context); + final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, endpoint, context); final ClassicHttpResponse finalResponse = retryExec.execute(request, scope, chain); Assert.assertSame(response, finalResponse);