summaryrefslogtreecommitdiff
path: root/eaaf_core_utils
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java11
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java27
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) {