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/12/26 16:03:14 UTC

[httpcomponents-client] branch master updated: Deprecated execute methods that return an open response object in favor of execute methods with a response handler and automatic resource deallocation

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


The following commit(s) were added to refs/heads/master by this push:
     new e6ad081  Deprecated execute methods that return an open response object in favor of execute methods with a response handler and automatic resource deallocation
e6ad081 is described below

commit e6ad081b3c1612a538f0108813cd7c10870d26f9
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sun Dec 26 12:35:47 2021 +0100

    Deprecated execute methods that return an open response object in favor of execute methods with a response handler and automatic resource deallocation
---
 .../org/apache/hc/client5/http/fluent/Request.java |  2 +-
 .../CachingHttpClientCompatibilityTest.java        | 10 ++--
 .../external/HttpClientCompatibilityTest.java      | 12 ++--
 .../testing/sync/TestBasicConnectionManager.java   |  6 +-
 .../apache/hc/client5/http/classic/HttpClient.java | 69 ++++++++++++++++++++++
 .../http/impl/classic/CloseableHttpClient.java     | 67 +++++++++++++++++----
 .../http/impl/classic/TestCloseableHttpClient.java | 19 ++----
 .../http/impl/classic/TestInternalHttpClient.java  | 26 ++++++--
 8 files changed, 167 insertions(+), 44 deletions(-)

diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
index 8e2bbf1..8c06c62 100644
--- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
+++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java
@@ -198,7 +198,7 @@ public class Request {
         }
         final RequestConfig config = builder.build();
         localContext.setRequestConfig(config);
-        return client.execute(this.request, localContext);
+        return client.executeOpen(null, this.request, localContext);
     }
 
     public Response execute() throws IOException {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/CachingHttpClientCompatibilityTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/CachingHttpClientCompatibilityTest.java
index 29357a3..b49ab26 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/CachingHttpClientCompatibilityTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/CachingHttpClientCompatibilityTest.java
@@ -118,7 +118,7 @@ public class CachingHttpClientCompatibilityTest {
         {
             final HttpCacheContext context = HttpCacheContext.create();
             final HttpOptions options = new HttpOptions("*");
-            try (final ClassicHttpResponse response = client.execute(target, options, context)) {
+            try (final ClassicHttpResponse response = client.executeOpen(target, options, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_OK) {
@@ -137,7 +137,7 @@ public class CachingHttpClientCompatibilityTest {
             final Pattern linkPattern = Pattern.compile("^<(.*)>;rel=preload$");
             final List<String> links = new ArrayList<>();
             final HttpGet getRoot1 = new HttpGet("/");
-            try (ClassicHttpResponse response = client.execute(target, getRoot1, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, getRoot1, context)) {
                 final int code = response.getCode();
                 final CacheResponseStatus cacheResponseStatus = context.getCacheResponseStatus();
                 EntityUtils.consume(response.getEntity());
@@ -158,7 +158,7 @@ public class CachingHttpClientCompatibilityTest {
 
             for (final String link: links) {
                 final HttpGet getLink = new HttpGet(link);
-                try (ClassicHttpResponse response = client.execute(target, getLink, context)) {
+                try (ClassicHttpResponse response = client.executeOpen(target, getLink, context)) {
                     final int code = response.getCode();
                     final CacheResponseStatus cacheResponseStatus = context.getCacheResponseStatus();
                     EntityUtils.consume(response.getEntity());
@@ -172,7 +172,7 @@ public class CachingHttpClientCompatibilityTest {
                 }
             }
             final HttpGet getRoot2 = new HttpGet("/");
-            try (ClassicHttpResponse response = client.execute(target, getRoot2, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, getRoot2, context)) {
                 final int code = response.getCode();
                 final CacheResponseStatus cacheResponseStatus = context.getCacheResponseStatus();
                 EntityUtils.consume(response.getEntity());
@@ -186,7 +186,7 @@ public class CachingHttpClientCompatibilityTest {
             }
             for (final String link: links) {
                 final HttpGet getLink = new HttpGet(link);
-                try (ClassicHttpResponse response = client.execute(target, getLink, context)) {
+                try (ClassicHttpResponse response = client.executeOpen(target, getLink, context)) {
                     final int code = response.getCode();
                     final CacheResponseStatus cacheResponseStatus = context.getCacheResponseStatus();
                     EntityUtils.consume(response.getEntity());
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpClientCompatibilityTest.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpClientCompatibilityTest.java
index a44efed..d8fd4f7 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpClientCompatibilityTest.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/external/HttpClientCompatibilityTest.java
@@ -142,7 +142,7 @@ public class HttpClientCompatibilityTest {
             final HttpClientContext context = HttpClientContext.create();
             context.setCredentialsProvider(credentialsProvider);
             final HttpOptions options = new HttpOptions("*");
-            try (ClassicHttpResponse response = client.execute(target, options, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, options, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_OK) {
@@ -162,7 +162,7 @@ public class HttpClientCompatibilityTest {
             final String[] requestUris = new String[] {"/", "/news.html", "/status.html"};
             for (final String requestUri: requestUris) {
                 final HttpGet httpGet = new HttpGet(requestUri);
-                try (ClassicHttpResponse response = client.execute(target, httpGet, context)) {
+                try (ClassicHttpResponse response = client.executeOpen(target, httpGet, context)) {
                     final int code = response.getCode();
                     EntityUtils.consume(response.getEntity());
                     if (code == HttpStatus.SC_OK) {
@@ -185,7 +185,7 @@ public class HttpClientCompatibilityTest {
             context.setCredentialsProvider(credentialsProvider);
 
             final HttpGet httpGetSecret = new HttpGet("/private/big-secret.txt");
-            try (ClassicHttpResponse response = client.execute(target, httpGetSecret, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, httpGetSecret, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_UNAUTHORIZED) {
@@ -207,7 +207,7 @@ public class HttpClientCompatibilityTest {
             context.setCredentialsProvider(credentialsProvider);
 
             final HttpGet httpGetSecret = new HttpGet("/private/big-secret.txt");
-            try (ClassicHttpResponse response = client.execute(target, httpGetSecret, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, httpGetSecret, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_UNAUTHORIZED) {
@@ -229,7 +229,7 @@ public class HttpClientCompatibilityTest {
             context.setCredentialsProvider(credentialsProvider);
 
             final HttpGet httpGetSecret = new HttpGet("/private/big-secret.txt");
-            try (ClassicHttpResponse response = client.execute(target, httpGetSecret, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, httpGetSecret, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_OK) {
@@ -252,7 +252,7 @@ public class HttpClientCompatibilityTest {
 
             final HttpGet httpGetSecret = new HttpGet("/private/big-secret.txt");
             httpGetSecret.setHeader(HttpHeaders.CONNECTION, HeaderElements.CLOSE);
-            try (ClassicHttpResponse response = client.execute(target, httpGetSecret, context)) {
+            try (ClassicHttpResponse response = client.executeOpen(target, httpGetSecret, context)) {
                 final int code = response.getCode();
                 EntityUtils.consume(response.getEntity());
                 if (code == HttpStatus.SC_OK) {
diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
index b523ab3..9c4ca28 100644
--- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
+++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestBasicConnectionManager.java
@@ -30,8 +30,8 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.io.entity.EntityUtils;
-import org.junit.jupiter.api.Assertions;
 import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
 
 public class TestBasicConnectionManager extends LocalServerTestBase {
 
@@ -54,10 +54,10 @@ public class TestBasicConnectionManager extends LocalServerTestBase {
 
         final HttpHost target = start();
         final HttpGet get1 = new HttpGet("/random/1024");
-        this.httpclient.execute(target, get1);
+        this.httpclient.executeOpen(target, get1, null);
         final HttpGet get2 = new HttpGet("/random/1024");
         Assertions.assertThrows(IllegalStateException.class, () ->
-                this.httpclient.execute(target, get2));
+                this.httpclient.executeOpen(target, get2, null));
     }
 
 }
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
index 7dcda65..9ddf4a1 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/classic/HttpClient.java
@@ -27,6 +27,7 @@
 
 package org.apache.hc.client5.http.classic;
 
+import java.io.Closeable;
 import java.io.IOException;
 
 import org.apache.hc.core5.http.ClassicHttpRequest;
@@ -57,7 +58,17 @@ public interface HttpClient {
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
      * @throws IOException in case of a problem or the connection was aborted
+     *
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(ClassicHttpRequest, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(ClassicHttpRequest, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
      */
+    @Deprecated
     HttpResponse execute(ClassicHttpRequest request) throws IOException;
 
     /**
@@ -73,7 +84,17 @@ public interface HttpClient {
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
      * @throws IOException in case of a problem or the connection was aborted
+     *
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
      */
+    @Deprecated
     HttpResponse execute(ClassicHttpRequest request, HttpContext context) throws IOException;
 
     /**
@@ -91,7 +112,17 @@ public interface HttpClient {
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
      * @throws IOException in case of a problem or the connection was aborted
+     *
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
      */
+     @Deprecated
      ClassicHttpResponse execute(HttpHost target, ClassicHttpRequest request) throws IOException;
 
     /**
@@ -111,10 +142,48 @@ public interface HttpClient {
      *          or handled automatically depends on the implementation and
      *          configuration of this client.
      * @throws IOException in case of a problem or the connection was aborted
+     *
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
      */
+    @Deprecated
     HttpResponse execute(HttpHost target, ClassicHttpRequest request, HttpContext context) throws IOException;
 
     /**
+     * Executes the request and opens the response stream using the given context.
+     *
+     * @param target    the target host for the request.
+     *                  Implementations may accept {@code null}
+     *                  if they can still determine a route, for example
+     *                  to a default target or by inspecting the request.
+     * @param request   the request to execute
+     * @param context   the context to use for the execution, or
+     *                  {@code null} to use the default context
+     *
+     * @return  the response to the request. This is always a final response,
+     *          never an intermediate response with an 1xx status code.
+     *          Whether redirects or authentication challenges will be returned
+     *          or handled automatically depends on the implementation and
+     *          configuration of this client.
+     *          The response returned by this method must be closed with
+     *          {@link Closeable#close()} in order ensure deallocation
+     *          of system resources.
+     * @throws IOException in case of a problem or the connection was aborted
+     *
+     * @since 5.2
+     */
+    @SuppressWarnings("deprecation")
+    default ClassicHttpResponse executeOpen(HttpHost target, ClassicHttpRequest request, HttpContext context) throws IOException {
+        return (ClassicHttpResponse) execute(target, request, context);
+    }
+
+    /**
      * Executes HTTP request using the default context and processes the
      * response using the given response handler.
      * <p>
diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpClient.java
index 1cd8dd5..1434cd4 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpClient.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpClient.java
@@ -35,6 +35,7 @@ import org.apache.hc.client5.http.routing.RoutingSupport;
 import org.apache.hc.core5.annotation.Contract;
 import org.apache.hc.core5.annotation.ThreadingBehavior;
 import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
 import org.apache.hc.core5.http.HttpEntity;
 import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
@@ -57,8 +58,27 @@ public abstract class CloseableHttpClient implements HttpClient, ModalCloseable
     private static final Logger LOG = LoggerFactory.getLogger(CloseableHttpClient.class);
 
     protected abstract CloseableHttpResponse doExecute(HttpHost target, ClassicHttpRequest request,
-                                                     HttpContext context) throws IOException;
+                                                       HttpContext context) throws IOException;
 
+    private static HttpHost determineTarget(final ClassicHttpRequest request) throws ClientProtocolException {
+        try {
+            return RoutingSupport.determineHost(request);
+        } catch (final HttpException ex) {
+            throw new ClientProtocolException(ex);
+        }
+    }
+
+    /**
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(HttpHost, ClassicHttpRequest, HttpContext, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
+     */
+    @Deprecated
     @Override
     public CloseableHttpResponse execute(
             final HttpHost target,
@@ -67,6 +87,17 @@ public abstract class CloseableHttpClient implements HttpClient, ModalCloseable
         return doExecute(target, request, context);
     }
 
+    /**
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(ClassicHttpRequest, HttpContext, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
+     */
+    @Deprecated
     @Override
     public CloseableHttpResponse execute(
             final ClassicHttpRequest request,
@@ -75,20 +106,34 @@ public abstract class CloseableHttpClient implements HttpClient, ModalCloseable
         return doExecute(determineTarget(request), request, context);
     }
 
-    private static HttpHost determineTarget(final ClassicHttpRequest request) throws ClientProtocolException {
-        try {
-            return RoutingSupport.determineHost(request);
-        } catch (final HttpException ex) {
-            throw new ClientProtocolException(ex);
-        }
-    }
-
+    /**
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(ClassicHttpRequest, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(ClassicHttpRequest, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
+     */
+    @Deprecated
     @Override
     public CloseableHttpResponse execute(
             final ClassicHttpRequest request) throws IOException {
-        return execute(request, (HttpContext) null);
+        return doExecute(determineTarget(request), request, null);
     }
 
+    /**
+     * @deprecated It is strongly recommended to use execute methods with {@link HttpClientResponseHandler}
+     * such as {@link #execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler)} in order
+     * to ensure automatic resource deallocation by the client.
+     * For special cases one can still use {@link #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)}
+     * to keep the response object open after the request execution.
+     *
+     * @see #execute(HttpHost, ClassicHttpRequest, HttpClientResponseHandler)
+     * @see #executeOpen(HttpHost, ClassicHttpRequest, HttpContext)
+     */
+    @Deprecated
     @Override
     public CloseableHttpResponse execute(
             final HttpHost target,
@@ -197,7 +242,7 @@ public abstract class CloseableHttpClient implements HttpClient, ModalCloseable
             final HttpClientResponseHandler<? extends T> responseHandler) throws IOException {
         Args.notNull(responseHandler, "Response handler");
 
-        try (final CloseableHttpResponse response = execute(target, request, context)) {
+        try (final ClassicHttpResponse response = doExecute(target, request, context)) {
             try {
                 final T result = responseHandler.handleResponse(response);
                 final HttpEntity entity = response.getEntity();
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
index bdf9ded..d2d0da8 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestCloseableHttpClient.java
@@ -81,7 +81,9 @@ public class TestCloseableHttpClient {
     @Test
     public void testExecuteRequestAbsoluteURI() throws Exception {
         final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-        client.execute(httpget);
+        Mockito.when(client.doExecute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(response);
+        client.execute(httpget, response -> null);
 
         Mockito.verify(client).doExecute(
                 Mockito.eq(new HttpHost("https", "somehost", 444)),
@@ -92,7 +94,9 @@ public class TestCloseableHttpClient {
     @Test
     public void testExecuteRequestRelativeURI() throws Exception {
         final HttpGet httpget = new HttpGet("/stuff");
-        client.execute(httpget);
+        Mockito.when(client.doExecute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(response);
+        client.execute(httpget, response -> null);
 
         Mockito.verify(client).doExecute(
                 (HttpHost) Mockito.isNull(),
@@ -101,17 +105,6 @@ public class TestCloseableHttpClient {
     }
 
     @Test
-    public void testExecuteRequest() throws Exception {
-        final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
-
-        Mockito.when(client.doExecute(
-                new HttpHost("https", "somehost", 444), httpget, null)).thenReturn(response);
-
-        final CloseableHttpResponse result = client.execute(httpget);
-        Assertions.assertSame(response, result);
-    }
-
-    @Test
     public void testExecuteRequestHandleResponse() throws Exception {
         final HttpGet httpget = new HttpGet("https://somehost:444/stuff");
 
diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
index c19ae65..dd5ea77 100644
--- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
+++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestInternalHttpClient.java
@@ -46,6 +46,7 @@ import org.apache.hc.core5.http.HttpException;
 import org.apache.hc.core5.http.HttpHost;
 import org.apache.hc.core5.http.config.Lookup;
 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor;
+import org.apache.hc.core5.http.message.BasicClassicHttpResponse;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -101,8 +102,11 @@ public class TestInternalHttpClient {
         Mockito.when(routePlanner.determineRoute(
                 Mockito.eq(new HttpHost("somehost")),
                 Mockito.<HttpClientContext>any())).thenReturn(route);
+        Mockito.when(execChain.execute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(
+                CloseableHttpResponse.adapt(new BasicClassicHttpResponse(200)));
 
-        client.execute(httpget);
+        client.execute(httpget, response -> null);
 
         Mockito.verify(execChain).execute(
                 Mockito.any(),
@@ -119,12 +123,15 @@ public class TestInternalHttpClient {
                 Mockito.eq(new HttpHost("somehost")),
                 Mockito.<HttpClientContext>any())).thenReturn(route);
         Mockito.when(execChain.execute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(
+                CloseableHttpResponse.adapt(new BasicClassicHttpResponse(200)));
+        Mockito.when(execChain.execute(
                 Mockito.any(),
                 Mockito.any(),
                 Mockito.any())).thenThrow(new HttpException());
 
         Assertions.assertThrows(ClientProtocolException.class, () ->
-                client.execute(httpget));
+                client.execute(httpget, response -> null));
     }
 
     @Test
@@ -135,9 +142,12 @@ public class TestInternalHttpClient {
         Mockito.when(routePlanner.determineRoute(
                 Mockito.eq(new HttpHost("somehost")),
                 Mockito.<HttpClientContext>any())).thenReturn(route);
+        Mockito.when(execChain.execute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(
+                CloseableHttpResponse.adapt(new BasicClassicHttpResponse(200)));
 
         final HttpClientContext context = HttpClientContext.create();
-        client.execute(httpget, context);
+        client.execute(httpget, context, response -> null);
 
         Assertions.assertSame(cookieSpecRegistry, context.getCookieSpecRegistry());
         Assertions.assertSame(authSchemeRegistry, context.getAuthSchemeRegistry());
@@ -154,11 +164,14 @@ public class TestInternalHttpClient {
         Mockito.when(routePlanner.determineRoute(
                 Mockito.eq(new HttpHost("somehost")),
                 Mockito.<HttpClientContext>any())).thenReturn(route);
+        Mockito.when(execChain.execute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(
+                CloseableHttpResponse.adapt(new BasicClassicHttpResponse(200)));
 
         final RequestConfig config = RequestConfig.custom().build();
         httpget.setConfig(config);
         final HttpClientContext context = HttpClientContext.create();
-        client.execute(httpget, context);
+        client.execute(httpget, context, response -> null);
 
         Assertions.assertSame(config, context.getRequestConfig());
     }
@@ -171,6 +184,9 @@ public class TestInternalHttpClient {
         Mockito.when(routePlanner.determineRoute(
                 Mockito.eq(new HttpHost("somehost")),
                 Mockito.<HttpClientContext>any())).thenReturn(route);
+        Mockito.when(execChain.execute(
+                Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(
+                CloseableHttpResponse.adapt(new BasicClassicHttpResponse(200)));
 
         final HttpClientContext context = HttpClientContext.create();
 
@@ -186,7 +202,7 @@ public class TestInternalHttpClient {
         context.setCredentialsProvider(localCredentialsProvider);
         context.setRequestConfig(localConfig);
 
-        client.execute(httpget, context);
+        client.execute(httpget, context, response -> null);
 
         Assertions.assertSame(localCookieSpecRegistry, context.getCookieSpecRegistry());
         Assertions.assertSame(localAuthSchemeRegistry, context.getAuthSchemeRegistry());