From 7a4ce221f2c67235604f7986ea77fccb64f6764f Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Tue, 19 Apr 2022 08:12:11 +0200 Subject: feat(http): add request interceptor configuration into Apache HTTP Client factory --- .../gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java | 10 +++++++++- .../java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'eaaf_core_utils/src') 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 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)); } -- cgit v1.2.3