From c422f1f3439b2dabb8edc55cff70ab53caaafdd4 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Mon, 11 Mar 2024 09:03:00 +0000 Subject: [PATCH] feat : polish connectionalive code --- .../template/config/RestTemplateConfiguration.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/httpClients/boot-rest-template/src/main/java/com/example/rest/template/config/RestTemplateConfiguration.java b/httpClients/boot-rest-template/src/main/java/com/example/rest/template/config/RestTemplateConfiguration.java index c7ed6ba78..bf12fb230 100644 --- a/httpClients/boot-rest-template/src/main/java/com/example/rest/template/config/RestTemplateConfiguration.java +++ b/httpClients/boot-rest-template/src/main/java/com/example/rest/template/config/RestTemplateConfiguration.java @@ -16,7 +16,6 @@ import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; import org.apache.hc.core5.http.Header; -import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.HttpHost; import org.apache.hc.core5.http.config.Registry; import org.apache.hc.core5.http.config.RegistryBuilder; @@ -50,9 +49,11 @@ PoolingHttpClientConnectionManager poolingConnectionManager() { new PoolingHttpClientConnectionManager(registry); poolingConnectionManager.setDefaultSocketConfig( - SocketConfig.custom().setSoTimeout(Timeout.ofSeconds(2)).build()); + SocketConfig.custom().setSoTimeout(Timeout.ofSeconds(REQUEST_TIMEOUT)).build()); poolingConnectionManager.setDefaultConnectionConfig( - ConnectionConfig.custom().setConnectTimeout(Timeout.ofSeconds(2)).build()); + ConnectionConfig.custom() + .setConnectTimeout(Timeout.ofSeconds(CONNECTION_TIMEOUT)) + .build()); // set a total amount of connections across all HTTP routes poolingConnectionManager.setMaxTotal(MAX_TOTAL_CONNECTIONS); @@ -87,12 +88,12 @@ CloseableHttpClient httpClient( @Bean ConnectionKeepAliveStrategy connectionKeepAliveStrategy() { return (httpResponse, httpContext) -> { - Iterator
headerIterator = httpResponse.headerIterator(HttpHeaders.KEEP_ALIVE); + Iterator
headerIterator = httpResponse.headerIterator("keep-alive"); while (headerIterator.hasNext()) { Header element = headerIterator.next(); String param = element.getName(); String value = element.getValue(); - if (value != null && param.equalsIgnoreCase(HttpHeaders.TIMEOUT)) { + if (value != null && param.equalsIgnoreCase("timeout")) { return TimeValue.ofSeconds(Long.parseLong(value)); } }