|
3 | 3 | import org.apache.hc.client5.http.config.RequestConfig;
|
4 | 4 | import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
5 | 5 | import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
6 |
| -import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; |
7 | 6 | import org.apache.hc.core5.http.ClassicHttpRequest;
|
8 | 7 | import org.apache.hc.core5.http.ContentType;
|
| 8 | +import org.apache.hc.core5.http.HttpEntity; |
9 | 9 | import org.apache.hc.core5.http.io.entity.EntityUtils;
|
10 | 10 | import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
|
11 | 11 | import org.apache.hc.core5.util.Timeout;
|
@@ -36,21 +36,17 @@ public enum DEFAULTS {
|
36 | 36 | // client configuration options like timeouts, forwarding ..
|
37 | 37 | private RequestConfig.Builder clientConfigBuilder;
|
38 | 38 |
|
39 |
| - private final PoolingHttpClientConnectionManager connectionManager; |
40 |
| - |
41 | 39 | private boolean secureConnection = true;
|
42 | 40 |
|
43 | 41 | public HttpClient(Map<String,Object> headers, int connectTimeoutSeconds, int readTimeoutSeconds) {
|
44 | 42 | this.headers = headers;
|
45 | 43 | this.clientConfigBuilder = RequestConfig
|
46 | 44 | .custom()
|
47 | 45 | .setConnectTimeout(Timeout.ofSeconds(connectTimeoutSeconds))
|
| 46 | + .setConnectionRequestTimeout(Timeout.ofSeconds(connectTimeoutSeconds)) |
| 47 | + .setConnectionKeepAlive(Timeout.ofSeconds(connectTimeoutSeconds)) |
48 | 48 | .setResponseTimeout(Timeout.ofSeconds(readTimeoutSeconds));
|
49 | 49 |
|
50 |
| - this.connectionManager = new PoolingHttpClientConnectionManager(); |
51 |
| - connectionManager.setMaxTotal(100); |
52 |
| - connectionManager.setDefaultMaxPerRoute(25); |
53 |
| - |
54 | 50 | this.client = buildClient();
|
55 | 51 | }
|
56 | 52 |
|
@@ -89,7 +85,14 @@ public ClientResponse execute(REQUEST_TYPES requestType, String url, String data
|
89 | 85 |
|
90 | 86 | return client.execute(
|
91 | 87 | request,
|
92 |
| - response -> new ClientResponse(response.getCode(), EntityUtils.toString(response.getEntity()))); |
| 88 | + response -> { |
| 89 | + final HttpEntity entity = response.getEntity(); |
| 90 | + int code = response.getCode(); |
| 91 | + String body = EntityUtils.toString(response.getEntity()); |
| 92 | + EntityUtils.consume(entity); |
| 93 | + |
| 94 | + return new ClientResponse(code, body); |
| 95 | + }); |
93 | 96 | }
|
94 | 97 |
|
95 | 98 | /**
|
@@ -154,7 +157,6 @@ private CloseableHttpClient buildClient() {
|
154 | 157 | return HttpClientBuilder
|
155 | 158 | .create()
|
156 | 159 | .setDefaultRequestConfig(clientConfigBuilder.build())
|
157 |
| - .setConnectionManager(connectionManager) |
158 | 160 | .build();
|
159 | 161 | }
|
160 | 162 |
|
|
0 commit comments