diff options
author | Thomas <> | 2023-07-12 10:13:07 +0200 |
---|---|---|
committer | Thomas <> | 2023-07-12 10:13:07 +0200 |
commit | 25ae045ff811ed39638e5366f7d53f3776f0d436 (patch) | |
tree | 2d3f3ead133ecf746e998ecb71c57292dadf8fd6 /eaaf_core_utils/src | |
parent | 663667a6a7df13305674636b169bd7a295472e2e (diff) | |
download | EAAF-Components-25ae045ff811ed39638e5366f7d53f3776f0d436.tar.gz EAAF-Components-25ae045ff811ed39638e5366f7d53f3776f0d436.tar.bz2 EAAF-Components-25ae045ff811ed39638e5366f7d53f3776f0d436.zip |
feat(http): Add connection timeout parameters to HTTP client-configuration
Diffstat (limited to 'eaaf_core_utils/src')
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java | 11 | ||||
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java | 27 |
2 files changed, 27 insertions, 11 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java index 5e873fe8..7033a052 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java @@ -51,7 +51,7 @@ public class HttpClientConfiguration { @Setter boolean disableTlsHostCertificateValidation = false; - + @Setter private KeyStoreConfiguration keyStoreConfig; @Setter @@ -70,6 +70,15 @@ public class HttpClientConfiguration { private boolean httpErrorRetryPost = false; @Setter + private int connectTimeout = -1; + + @Setter + private int connectionRequestTimeout = -1; + + @Setter + private int socketTimeout = -1; + + @Setter private ServiceUnavailableRetryStrategy serviceUnavailStrategy = null; /** diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java index ac5905ac..f2955482 100644 --- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java +++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java @@ -146,7 +146,7 @@ public class HttpClientFactory implements IHttpClientFactory { builder = HttpClients.custom(); // inject request configuration - builder.setDefaultRequestConfig(buildDefaultRequestConfig()); + builder.setDefaultRequestConfig(buildDefaultRequestConfig(config)); injectInternalRetryHandler(builder, config); // inject basic authentication infos @@ -226,7 +226,7 @@ public class HttpClientFactory implements IHttpClientFactory { final HttpClientBuilder defaultHttpClientBuilder = HttpClients.custom(); // set default request configuration - defaultHttpClientBuilder.setDefaultRequestConfig(buildDefaultRequestConfig()); + defaultHttpClientBuilder.setDefaultRequestConfig(buildDefaultRequestConfig(defaultHttpClientConfig)); injectInternalRetryHandler(defaultHttpClientBuilder, defaultHttpClientConfig); // inject http basic authentication @@ -388,25 +388,32 @@ public class HttpClientFactory implements IHttpClientFactory { } - private RequestConfig buildDefaultRequestConfig() { + private RequestConfig buildDefaultRequestConfig(HttpClientConfiguration config) { final RequestConfig requestConfig = RequestConfig.custom() - .setConnectTimeout( + .setConnectTimeout(selectTimeoutFromConfig(config.getConnectTimeout(), Integer.parseInt(basicConfig.getBasicConfiguration( PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION, - DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION)) * 1000) - .setConnectionRequestTimeout(Integer.parseInt(basicConfig.getBasicConfiguration( + DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION)) * 1000)) + .setConnectionRequestTimeout(selectTimeoutFromConfig(config.getConnectionRequestTimeout(), + Integer.parseInt(basicConfig.getBasicConfiguration( PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_REQUEST, - DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_REQUEST)) * 1000) - .setSocketTimeout(Integer.parseInt( - basicConfig.getBasicConfiguration(PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET, + DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_REQUEST)) * 1000)) + .setSocketTimeout(selectTimeoutFromConfig(config.getSocketTimeout(), + Integer.parseInt(basicConfig.getBasicConfiguration( + PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET, DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET)) - * 1000) + * 1000)) .build(); return requestConfig; } + private int selectTimeoutFromConfig(int timeout, int defaultTimeout) { + return timeout > 0 ? timeout : defaultTimeout; + + } + private static RedirectStrategy buildRedirectStrategy(final boolean followRedirects) { RedirectStrategy redirectStrategy = new DefaultRedirectStrategy(); if (!followRedirects) { |