diff options
author | Thomas <> | 2022-04-19 08:12:11 +0200 |
---|---|---|
committer | Thomas <> | 2022-04-19 08:14:02 +0200 |
commit | 7a4ce221f2c67235604f7986ea77fccb64f6764f (patch) | |
tree | cb7cb6b6530eeecf71bc3b50ee3ade4f03cb038d | |
parent | c0ae73a8446b25b6e9ba1a96c084047603464d2b (diff) | |
download | EAAF-Components-7a4ce221f2c67235604f7986ea77fccb64f6764f.tar.gz EAAF-Components-7a4ce221f2c67235604f7986ea77fccb64f6764f.tar.bz2 EAAF-Components-7a4ce221f2c67235604f7986ea77fccb64f6764f.zip |
feat(http): add request interceptor configuration into Apache HTTP Client factory
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java | 10 | ||||
-rw-r--r-- | eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java | 8 |
2 files changed, 17 insertions, 1 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 2fea1e85..40d22205 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 @@ -1,11 +1,13 @@ package at.gv.egiz.eaaf.core.impl.http; import java.text.MessageFormat; +import java.util.List; import java.util.UUID; import javax.annotation.Nonnull; import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpRequestInterceptor; import org.apache.http.client.ServiceUnavailableRetryStrategy; import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException; @@ -67,6 +69,12 @@ public class HttpClientConfiguration { @Setter private ServiceUnavailableRetryStrategy serviceUnavailStrategy = null; + /** + * List of {@link HttpRequestInterceptor} that are added first to HTTP client. + */ + @Setter + private List<HttpRequestInterceptor> messageInterceptors; + /** * Get a new HTTP-client configuration object. @@ -198,6 +206,6 @@ public class HttpClientConfiguration { return getMode(); } - } + } 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 07522b56..784dbe0e 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 @@ -158,6 +158,14 @@ public class HttpClientFactory implements IHttpClientFactory { HttpClientConnectionManager connectionManager = injectConnectionManager(builder, sslConnectionFactory); + // set interceptor + if (config.getMessageInterceptors() != null) { + for (int i = config.getMessageInterceptors().size() - 1; i >= 0; i--) { + builder.addInterceptorFirst(config.getMessageInterceptors().get(i)); + + } + } + availableBuilders.put(config.getUuid(), Pair.newInstance(builder, connectionManager)); } |