summaryrefslogtreecommitdiff
path: root/eaaf_core_utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'eaaf_core_utils/src')
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java6
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafHttpRequestRetryHandler.java37
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslContextBuilder.java12
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslKeySelectionStrategy.java9
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientConfiguration.java9
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpClientFactory.java204
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java43
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/IHttpClientFactory.java2
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/interceptor/PreemptiveAuthInterceptor.java57
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java29
-rw-r--r--eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ServletUtils.java2
-rw-r--r--eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryProdHostTest.java17
-rw-r--r--eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java61
13 files changed, 224 insertions, 264 deletions
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
index 0ecdcc92..673a373d 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/credential/EaafKeyStoreFactory.java
@@ -23,9 +23,6 @@ import java.security.cert.X509Certificate;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-import javax.annotation.PostConstruct;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
@@ -46,6 +43,9 @@ import at.gv.egiz.eaaf.core.impl.credential.inline.InlineKeyStoreParser;
import at.gv.egiz.eaaf.core.impl.data.Pair;
import at.gv.egiz.eaaf.core.impl.utils.FileUtils;
import at.gv.egiz.eaaf.core.impl.utils.KeyStoreUtils;
+import jakarta.annotation.Nonnull;
+import jakarta.annotation.Nullable;
+import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
@Slf4j
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafHttpRequestRetryHandler.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafHttpRequestRetryHandler.java
index 3aa908e8..026b76c4 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafHttpRequestRetryHandler.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafHttpRequestRetryHandler.java
@@ -5,12 +5,13 @@ import java.util.Arrays;
import javax.net.ssl.SSLException;
-import org.apache.http.client.HttpRequestRetryHandler;
-import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
+import org.apache.hc.client5.http.HttpRequestRetryStrategy;
+import org.apache.hc.client5.http.impl.DefaultHttpRequestRetryStrategy;
+import org.apache.hc.core5.util.TimeValue;
+
+public class EaafHttpRequestRetryHandler extends DefaultHttpRequestRetryStrategy implements
+ HttpRequestRetryStrategy {
-public class EaafHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler implements
- HttpRequestRetryHandler {
-
/**
* Create the request retry handler using the following list of non-retriable.
* IOException classes: <br>
@@ -18,16 +19,22 @@ public class EaafHttpRequestRetryHandler extends DefaultHttpRequestRetryHandler
* <li>UnknownHostException</li>
* <li>SSLException</li>
* </ul>
- *
- * @param retryCount how many times to retry; 0 means no retries
- * @param requestSentRetryEnabled true if it's OK to retry non-idempotent
- * requests that have been sent
+ * HTTP StatusCodes:
+ * <ul>
+ * <li>429</li>
+ * <li>502</li>
+ * </ul>
+ * After two seconds if no {@code Retry-After} header was set.
+ *
+ * @param retryCount how many times to retry; 0 means no retries
*/
- public EaafHttpRequestRetryHandler(final int retryCount, final boolean requestSentRetryEnabled) {
- super(retryCount, requestSentRetryEnabled, Arrays.asList(
- UnknownHostException.class,
- SSLException.class));
-
+ public EaafHttpRequestRetryHandler(final int retryCount) {
+ super(retryCount, TimeValue.ofSeconds(2),
+ Arrays.asList(
+ UnknownHostException.class,
+ SSLException.class),
+ Arrays.asList(429, 502));
+
}
-
+
}
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslContextBuilder.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslContextBuilder.java
index 1cd739de..d311982a 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslContextBuilder.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslContextBuilder.java
@@ -29,10 +29,10 @@ import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509ExtendedKeyManager;
import javax.net.ssl.X509TrustManager;
-import org.apache.http.ssl.PrivateKeyDetails;
-import org.apache.http.ssl.PrivateKeyStrategy;
-import org.apache.http.ssl.SSLContextBuilder;
-import org.apache.http.ssl.TrustStrategy;
+import org.apache.hc.core5.ssl.PrivateKeyDetails;
+import org.apache.hc.core5.ssl.PrivateKeyStrategy;
+import org.apache.hc.core5.ssl.SSLContextBuilder;
+import org.apache.hc.core5.ssl.TrustStrategy;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
/**
@@ -380,7 +380,7 @@ public class EaafSslContextBuilder {
public String chooseClientAlias(
final String[] keyTypes, final Principal[] issuers, final Socket socket) {
final Map<String, PrivateKeyDetails> validAliases = getClientAliasMap(keyTypes, issuers);
- return this.aliasStrategy.chooseAlias(validAliases, socket);
+ return this.aliasStrategy.chooseAlias(validAliases, null);
}
@Override
@@ -393,7 +393,7 @@ public class EaafSslContextBuilder {
public String chooseServerAlias(
final String keyType, final Principal[] issuers, final Socket socket) {
final Map<String, PrivateKeyDetails> validAliases = getServerAliasMap(keyType, issuers);
- return this.aliasStrategy.chooseAlias(validAliases, socket);
+ return this.aliasStrategy.chooseAlias(validAliases, null);
}
@Override
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslKeySelectionStrategy.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslKeySelectionStrategy.java
index 3918c94e..f9f2f43d 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslKeySelectionStrategy.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/EaafSslKeySelectionStrategy.java
@@ -1,11 +1,12 @@
package at.gv.egiz.eaaf.core.impl.http;
-import java.net.Socket;
import java.util.Map;
+import javax.net.ssl.SSLParameters;
+
import org.apache.commons.lang3.StringUtils;
-import org.apache.http.ssl.PrivateKeyDetails;
-import org.apache.http.ssl.PrivateKeyStrategy;
+import org.apache.hc.core5.ssl.PrivateKeyDetails;
+import org.apache.hc.core5.ssl.PrivateKeyStrategy;
import lombok.extern.slf4j.Slf4j;
@@ -31,7 +32,7 @@ public class EaafSslKeySelectionStrategy implements PrivateKeyStrategy {
}
@Override
- public String chooseAlias(Map<String, PrivateKeyDetails> aliases, Socket socket) {
+ public String chooseAlias(Map<String, PrivateKeyDetails> aliases, SSLParameters sslParameters) {
log.trace("Selection SSL client-auth key for alias: {}", keyAlias);
if (aliases.keySet().isEmpty()) {
log.debug("No Key with Alias: {} in empty KeyStore", keyAlias);
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 c189ff74..4d808f2b 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
@@ -7,8 +7,8 @@ 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 org.apache.hc.client5.http.HttpRequestRetryStrategy;
+import org.apache.hc.core5.http.HttpRequestInterceptor;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.impl.credential.KeyStoreConfiguration;
@@ -67,9 +67,6 @@ public class HttpClientConfiguration {
private int httpErrorRetryCount = 3;
@Setter
- private boolean httpErrorRetryPost = false;
-
- @Setter
private int connectTimeout = -1;
@Setter
@@ -79,7 +76,7 @@ public class HttpClientConfiguration {
private int socketTimeout = -1;
@Setter
- private ServiceUnavailableRetryStrategy serviceUnavailStrategy = null;
+ private HttpRequestRetryStrategy serviceUnavailStrategy = null;
/**
* List of {@link HttpRequestInterceptor} that are added first to HTTP client.
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 f2955482..715b0c96 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
@@ -1,10 +1,10 @@
package at.gv.egiz.eaaf.core.impl.http;
+import java.net.URI;
import java.security.KeyStore;
import java.security.Provider;
import java.util.HashMap;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
@@ -13,35 +13,34 @@ import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.ProtocolException;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.RedirectStrategy;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.config.Registry;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.config.SocketConfig;
-import org.apache.http.conn.HttpClientConnectionManager;
-import org.apache.http.conn.socket.ConnectionSocketFactory;
-import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
-import org.apache.http.conn.socket.PlainConnectionSocketFactory;
-import org.apache.http.conn.ssl.NoopHostnameVerifier;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.DefaultRedirectStrategy;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.ssl.SSLContexts;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.config.ConnectionConfig;
+import org.apache.hc.client5.http.config.RequestConfig;
+import org.apache.hc.client5.http.impl.DefaultRedirectStrategy;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.io.HttpClientConnectionManager;
+import org.apache.hc.client5.http.protocol.RedirectStrategy;
+import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
+import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
+import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
+import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
+import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpResponse;
+import org.apache.hc.core5.http.config.Registry;
+import org.apache.hc.core5.http.config.RegistryBuilder;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.http.protocol.HttpContext;
+import org.apache.hc.core5.ssl.SSLContexts;
+import org.apache.hc.core5.util.TimeValue;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Scheduled;
import at.gv.egiz.eaaf.core.api.idp.IConfiguration;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
@@ -74,8 +73,6 @@ public class HttpClientFactory implements IHttpClientFactory {
"client.http.connection.timeout.request";
public static final String PROP_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_COUNT =
"client.http.connection.retry.count";
- public static final String PROP_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_POST =
- "client.http.connection.retry.post";
public static final String PROP_CONFIG_CLIENT_HTTP_SSL_HOSTNAMEVERIFIER_TRUSTALL =
"client.http.ssl.hostnameverifier.trustall";
@@ -102,15 +99,13 @@ public class HttpClientFactory implements IHttpClientFactory {
public static final String DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXTOTAL = "500";
public static final String DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXPERROUTE = "100";
public static final String DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_COUNT = "3";
- public static final String DEFAUTL_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_POST = String.valueOf(false);
public static final int DEFAULT_CLEANUP_RUNNER_TIME = 30000;
public static final int DEFAULT_CLEANUP_IDLE_TIME = 60;
-
-
+
private String defaultConfigurationId = null;
- private final Map<String, Pair<HttpClientBuilder, HttpClientConnectionManager>>
- availableBuilders = new HashMap<>();
+ private final Map<String, Pair<HttpClientBuilder, HttpClientConnectionManager>> availableBuilders =
+ new HashMap<>();
/*
* (non-Javadoc)
@@ -156,17 +151,21 @@ public class HttpClientFactory implements IHttpClientFactory {
final LayeredConnectionSocketFactory sslConnectionFactory = getSslContext(config);
// set pool connection if required
- HttpClientConnectionManager connectionManager
- = injectConnectionManager(builder, sslConnectionFactory);
+ final HttpClientConnectionManager connectionManager = injectConnectionManager(builder,
+ sslConnectionFactory);
+
+ // set evication for connection pool
+ builder.evictExpiredConnections();
+ builder.evictIdleConnections(TimeValue.ofSeconds(DEFAULT_CLEANUP_IDLE_TIME));
- // set interceptor
+ // set interceptor
if (config.getMessageInterceptors() != null) {
for (int i = config.getMessageInterceptors().size() - 1; i >= 0; i--) {
- builder.addInterceptorFirst(config.getMessageInterceptors().get(i));
-
- }
+ builder.addRequestInterceptorFirst(config.getMessageInterceptors().get(i));
+
+ }
}
-
+
availableBuilders.put(config.getUuid(), Pair.newInstance(builder, connectionManager));
}
@@ -176,38 +175,17 @@ public class HttpClientFactory implements IHttpClientFactory {
}
- /**
- * Worker that closes expired connections or connections that in idle
- * for more than DEFAULT_CLEANUP_IDLE_TIME seconds.
- *
- */
- @Scheduled(fixedDelay = DEFAULT_CLEANUP_RUNNER_TIME)
- private void httpConnectionPoolCleaner() {
- log.trace("Starting http connection-pool eviction policy ... ");
- for (final Entry<String, Pair<HttpClientBuilder, HttpClientConnectionManager>> el
- : availableBuilders.entrySet()) {
- log.trace("Checking connections of http-client: {}", el.getKey());
- el.getValue().getSecond().closeExpiredConnections();
- el.getValue().getSecond().closeIdleConnections(DEFAULT_CLEANUP_IDLE_TIME, TimeUnit.SECONDS);
-
- }
-
- }
-
private void injectInternalRetryHandler(HttpClientBuilder builder, HttpClientConfiguration config) {
- if (config.getHttpErrorRetryCount() > 0) {
+ if (config.getServiceUnavailStrategy() != null) {
+ log.debug("HttpClient configuration: {} set custom ServiceUnavailableRetryStrategy: {}",
+ config.getFriendlyName(), config.getServiceUnavailStrategy().getClass().getName());
+ builder.setRetryStrategy(config.getServiceUnavailStrategy());
+
+ } else if (config.getHttpErrorRetryCount() > 0) {
log.info("Set HTTP error-retry to {} for http-client: {}",
config.getHttpErrorRetryCount(), config.getFriendlyName());
- builder.setRetryHandler(new EaafHttpRequestRetryHandler(
- config.getHttpErrorRetryCount(),
- config.isHttpErrorRetryPost()));
-
- if (config.getServiceUnavailStrategy() != null) {
- log.debug("HttpClient configuration: {} set custom ServiceUnavailableRetryStrategy: {}",
- config.getFriendlyName(), config.getServiceUnavailStrategy().getClass().getName());
- builder.setServiceUnavailableRetryStrategy(config.getServiceUnavailStrategy());
-
- }
+ builder.setRetryStrategy(new EaafHttpRequestRetryHandler(
+ config.getHttpErrorRetryCount()));
} else {
log.info("Disable HTTP error-retry for http-client: {}", config.getFriendlyName());
@@ -237,12 +215,12 @@ public class HttpClientFactory implements IHttpClientFactory {
getSslContext(defaultHttpClientConfig);
// set pool connection if required
- HttpClientConnectionManager connectionManager
- = injectConnectionManager(defaultHttpClientBuilder, sslConnectionFactory);
+ final HttpClientConnectionManager connectionManager = injectConnectionManager(defaultHttpClientBuilder,
+ sslConnectionFactory);
// set default http client builder
defaultConfigurationId = defaultHttpClientConfig.getUuid();
- availableBuilders.put(defaultConfigurationId,
+ availableBuilders.put(defaultConfigurationId,
Pair.newInstance(defaultHttpClientBuilder, connectionManager));
}
@@ -281,9 +259,6 @@ public class HttpClientFactory implements IHttpClientFactory {
config.setHttpErrorRetryCount(Integer.parseInt(basicConfig.getBasicConfiguration(
PROP_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_COUNT,
DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_COUNT)));
- config.setHttpErrorRetryPost(Boolean.parseBoolean(basicConfig.getBasicConfiguration(
- PROP_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_POST,
- DEFAUTL_CONFIG_CLIENT_HTTP_CONNECTION_RETRY_POST)));
// validate configuration object
config.validate();
@@ -294,25 +269,29 @@ public class HttpClientFactory implements IHttpClientFactory {
private void injectBasicAuthenticationIfRequired(HttpClientBuilder builder,
final HttpClientConfiguration httpClientConfig) {
if (httpClientConfig.getAuthMode().equals(HttpClientConfiguration.ClientAuthMode.PASSWORD)) {
- final CredentialsProvider provider = new BasicCredentialsProvider();
+ final BasicCredentialsProvider provider = new BasicCredentialsProvider();
log.trace("Injecting basic authentication with username: {} and password: {}",
httpClientConfig.getUsername(), httpClientConfig.getPassword());
+
final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
- httpClientConfig.getUsername(), httpClientConfig.getPassword());
+ httpClientConfig.getUsername(),
+ httpClientConfig.getPassword() != null
+ ? httpClientConfig.getPassword().toCharArray()
+ : "".toCharArray());
- final AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM);
+ final AuthScope scope = new AuthScope(null, null, -1, null, null);
provider.setCredentials(scope, credentials);
builder.setDefaultCredentialsProvider(provider);
log.info("Basic http authentication was injected with username: {}",
httpClientConfig.getUsername());
if (httpClientConfig.isEnablePreEmptiveHttpBasicAuth()) {
- log.info("Inject pre-emptive HTTP Basic-Auth interceptor for client: {}",
+ log.info("Inject pre-emptive HTTP Basic-Auth interceptor for client: {}",
httpClientConfig.getFriendlyName());
- builder.addInterceptorFirst(new PreemptiveAuthInterceptor());
-
+ builder.addRequestInterceptorFirst(new PreemptiveAuthInterceptor());
+
}
-
+
} else {
log.trace("Injection of Http Basic authentication was skipped");
@@ -360,50 +339,49 @@ public class HttpClientFactory implements IHttpClientFactory {
HttpClientBuilder builder, final LayeredConnectionSocketFactory sslConnectionFactory) {
if (basicConfig.getBasicConfigurationBoolean(PROP_CONFIG_CLIENT_HTTP_CONNECTION_POOL_USE,
true)) {
- PoolingHttpClientConnectionManager connectionPool
- = new PoolingHttpClientConnectionManager(getDefaultRegistry(sslConnectionFactory));
+ final PoolingHttpClientConnectionManager connectionPool = new PoolingHttpClientConnectionManager(
+ getDefaultRegistry(sslConnectionFactory));
connectionPool.setDefaultMaxPerRoute(Integer.parseInt(
basicConfig.getBasicConfiguration(PROP_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXPERROUTE,
DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXPERROUTE)));
connectionPool.setMaxTotal(Integer.parseInt(
basicConfig.getBasicConfiguration(PROP_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXTOTAL,
DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_POOL_MAXTOTAL)));
- connectionPool.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(Integer.parseInt(
- basicConfig.getBasicConfiguration(PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET,
- DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET))
- * 1000).build());
+ connectionPool.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(
+ Integer.parseInt(
+ basicConfig.getBasicConfiguration(
+ PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET,
+ DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET)), TimeUnit.SECONDS).build());
+ connectionPool.setDefaultConnectionConfig(ConnectionConfig.custom()
+ .setConnectTimeout(
+ Long.parseLong(basicConfig.getBasicConfiguration(
+ PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION,
+ DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION)), TimeUnit.SECONDS)
+ .build());
+
builder.setConnectionManager(connectionPool);
- log.debug("Initalize http-client pool with, maxTotal: {} maxPerRoute: {}",
+ log.debug("Initalize http-client pool with, maxTotal: {} maxPerRoute: {}",
connectionPool.getMaxTotal(), connectionPool.getDefaultMaxPerRoute());
return connectionPool;
-
+
} else {
log.debug("Building http-client without Connection-Pool ... ");
final BasicHttpClientConnectionManager basicPool = new BasicHttpClientConnectionManager(
- getDefaultRegistry(sslConnectionFactory));
- builder.setConnectionManager(basicPool);
+ getDefaultRegistry(sslConnectionFactory));
+ builder.setConnectionManager(basicPool);
return basicPool;
-
+
}
-
+
}
private RequestConfig buildDefaultRequestConfig(HttpClientConfiguration config) {
final RequestConfig requestConfig =
RequestConfig.custom()
- .setConnectTimeout(selectTimeoutFromConfig(config.getConnectTimeout(),
- Integer.parseInt(basicConfig.getBasicConfiguration(
- PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_CONNECTION,
- 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(selectTimeoutFromConfig(config.getSocketTimeout(),
- Integer.parseInt(basicConfig.getBasicConfiguration(
- PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET,
- DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_SOCKET))
- * 1000))
+ PROP_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_REQUEST,
+ DEFAULT_CONFIG_CLIENT_HTTP_CONNECTION_TIMEOUT_REQUEST))), TimeUnit.SECONDS)
.build();
return requestConfig;
@@ -420,14 +398,14 @@ public class HttpClientFactory implements IHttpClientFactory {
redirectStrategy = new RedirectStrategy() {
@Override
- public boolean isRedirected(final HttpRequest request, final HttpResponse response,
- final HttpContext context) throws ProtocolException {
+ public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)
+ throws HttpException {
return false;
}
@Override
- public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response,
- final HttpContext context) throws ProtocolException {
+ public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context)
+ throws HttpException {
return null;
}
};
@@ -435,7 +413,7 @@ public class HttpClientFactory implements IHttpClientFactory {
return redirectStrategy;
}
-
+
private static Registry<ConnectionSocketFactory> getDefaultRegistry(
final LayeredConnectionSocketFactory sslConnectionFactory) {
final RegistryBuilder<ConnectionSocketFactory> builder =
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
index dd6f69ee..caa73e04 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/HttpUtils.java
@@ -31,24 +31,25 @@ import java.security.UnrecoverableKeyException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.net.ssl.SSLContext;
-import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.conn.ssl.TrustAllStrategy;
-import org.apache.http.entity.ContentType;
-import org.apache.http.ssl.TrustStrategy;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.ClientProtocolException;
+import org.apache.hc.client5.http.ssl.TrustAllStrategy;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.io.HttpClientResponseHandler;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
+import org.apache.hc.core5.http.message.StatusLine;
+import org.apache.hc.core5.ssl.TrustStrategy;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import at.gv.egiz.eaaf.core.exceptions.EaafConfigurationException;
import at.gv.egiz.eaaf.core.exceptions.EaafFactoryException;
import at.gv.egiz.eaaf.core.impl.data.Pair;
import at.gv.egiz.eaaf.core.impl.data.Triple;
+import jakarta.servlet.http.HttpServletRequest;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
@@ -62,13 +63,13 @@ public class HttpUtils {
*
* @return Status-Code of http response
*/
- public static ResponseHandler<StatusLine> simpleStatusCodeResponseHandler() {
- return new ResponseHandler<StatusLine>() {
+ public static HttpClientResponseHandler<StatusLine> simpleStatusCodeResponseHandler() {
+ return new HttpClientResponseHandler<StatusLine>() {
+
@Override
- public StatusLine handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
+ public StatusLine handleResponse(ClassicHttpResponse response) throws HttpException, IOException {
EntityUtils.consumeQuietly(response.getEntity());
- return response.getStatusLine();
-
+ return new StatusLine(response);
}
};
}
@@ -80,15 +81,17 @@ public class HttpUtils {
* @return {@link Triple} of http response {@link StatusLine}, http body as {@link InputStream},
* and {@link ContentType}
*/
- public static ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>
+ public static HttpClientResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>
bodyStatusCodeResponseHandler() {
- return new ResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>() {
+ return new HttpClientResponseHandler<Triple<StatusLine, ByteArrayInputStream, ContentType>>() {
@Override
- public Triple<StatusLine, ByteArrayInputStream, ContentType> handleResponse(HttpResponse response)
+ public Triple<StatusLine, ByteArrayInputStream, ContentType> handleResponse(
+ ClassicHttpResponse response)
throws ClientProtocolException, IOException {
byte[] bodyBytes = EntityUtils.toByteArray(response.getEntity());
- return Triple.newInstance(response.getStatusLine(), new ByteArrayInputStream(bodyBytes),
- ContentType.getOrDefault(response.getEntity()));
+
+ return Triple.newInstance(new StatusLine(response), new ByteArrayInputStream(bodyBytes),
+ ContentType.parse(response.getEntity().getContentType()));
}
};
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/IHttpClientFactory.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/IHttpClientFactory.java
index 4e8374e1..232006d8 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/IHttpClientFactory.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/IHttpClientFactory.java
@@ -2,7 +2,7 @@ package at.gv.egiz.eaaf.core.impl.http;
import javax.annotation.Nonnull;
-import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import at.gv.egiz.eaaf.core.exceptions.EaafException;
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/interceptor/PreemptiveAuthInterceptor.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/interceptor/PreemptiveAuthInterceptor.java
index 5edc8cac..ac8c2312 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/interceptor/PreemptiveAuthInterceptor.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/http/interceptor/PreemptiveAuthInterceptor.java
@@ -2,18 +2,19 @@ package at.gv.egiz.eaaf.core.impl.http.interceptor;
import java.io.IOException;
-import org.apache.http.HttpException;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.HttpRequestInterceptor;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.AuthState;
-import org.apache.http.auth.Credentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.protocol.HttpContext;
-import org.apache.http.protocol.HttpCoreContext;
+import org.apache.hc.client5.http.auth.AuthExchange;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.Credentials;
+import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.EntityDetails;
+import org.apache.hc.core5.http.HttpException;
+import org.apache.hc.core5.http.HttpHeaders;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.HttpRequest;
+import org.apache.hc.core5.http.HttpRequestInterceptor;
+import org.apache.hc.core5.http.protocol.HttpContext;
import lombok.extern.slf4j.Slf4j;
@@ -27,29 +28,35 @@ import lombok.extern.slf4j.Slf4j;
public class PreemptiveAuthInterceptor implements HttpRequestInterceptor {
@Override
- public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
- final AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
+ public void process(HttpRequest request, EntityDetails entity, HttpContext context) throws HttpException,
+ IOException {
+ log.trace("Executing {}", PreemptiveAuthInterceptor.class.getSimpleName());
+ // final AuthState authState = (AuthState)
+ // context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
+
+ HttpHost targetHost = ((HttpClientContext) context).getHttpRoute().getTargetHost();
+ AuthExchange authState = ((HttpClientContext) context).getAuthExchange(targetHost);
// If no auth scheme available yet, try to initialize it
// preemptively
if (authState.getAuthScheme() == null) {
- final CredentialsProvider credentialsProvider =
- (CredentialsProvider) context.getAttribute(HttpClientContext.CREDS_PROVIDER);
- final HttpHost targetHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
-
+ final CredentialsProvider credentialsProvider = ((HttpClientContext) context).getCredentialsProvider();
+
final Credentials credentials = credentialsProvider.getCredentials(
- new AuthScope(targetHost.getHostName(), targetHost.getPort()));
+ new AuthScope(targetHost.getHostName(), targetHost.getPort()),
+ context);
if (credentials == null) {
log.warn("Find HTTP credential-provider but not credential matches. "
+ "Use it as it is and looking what happend");
-
+
} else {
log.trace("Updating HTTP basic-auth state to pre-emptive credentials ... ");
- authState.update(new BasicScheme(), credentials);
-
- }
+ BasicScheme basicAuthSchema = new BasicScheme();
+ basicAuthSchema.initPreemptive(credentials);
+ request.setHeader(HttpHeaders.AUTHORIZATION,
+ basicAuthSchema.generateAuthResponse(targetHost, request, context));
+
+ }
}
-
}
-
}
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java
index aedbbb7f..6c0a288f 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/Random.java
@@ -19,16 +19,16 @@
package at.gv.egiz.eaaf.core.impl.utils;
-import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
-import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.hc.client5.http.utils.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -83,19 +83,14 @@ public class Random {
// generate ID
String returnValue;
- try {
- returnValue = preFix + new String(Hex.encodeHex(ArrayUtils.addAll(now.getBytes("UTF-8"), randValue)));
-
- // 20 bytes = 160 bits
- if (returnValue.length() > 40) {
- return returnValue.substring(0, 40);
- } else {
- return returnValue;
- }
-
- } catch (final UnsupportedEncodingException e) {
- throw new RuntimeException(e);
-
+ returnValue = preFix + new String(Hex.encodeHexString(
+ ArrayUtils.addAll(now.getBytes(StandardCharsets.UTF_8), randValue)));
+
+ // 20 bytes = 160 bits
+ if (returnValue.length() > 40) {
+ return returnValue.substring(0, 40);
+ } else {
+ return returnValue;
}
}
@@ -106,7 +101,7 @@ public class Random {
* @return random hex encoded value [256bit]
*/
public static String nextHexRandom32() {
- return new String(Hex.encodeHex(nextByteRandom(32))); // 32 bytes = 256 bits
+ return new String(Hex.encodeHexString(nextByteRandom(32))); // 32 bytes = 256 bits
}
@@ -116,7 +111,7 @@ public class Random {
* @return random hex encoded value [128bit]
*/
public static String nextHexRandom16() {
- return new String(Hex.encodeHex(nextByteRandom(16))); // 16 bytes = 128 bits
+ return new String(Hex.encodeHexString(nextByteRandom(16))); // 16 bytes = 128 bits
}
diff --git a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ServletUtils.java b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ServletUtils.java
index c8865465..cf044d43 100644
--- a/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ServletUtils.java
+++ b/eaaf_core_utils/src/main/java/at/gv/egiz/eaaf/core/impl/utils/ServletUtils.java
@@ -19,7 +19,7 @@
package at.gv.egiz.eaaf.core.impl.utils;
-import javax.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletRequest;
public class ServletUtils {
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryProdHostTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryProdHostTest.java
index 3d7ede90..170ddff9 100644
--- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryProdHostTest.java
+++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryProdHostTest.java
@@ -11,12 +11,13 @@ import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateEncodingException;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.util.EntityUtils;
+import org.apache.hc.client5.http.ClientProtocolException;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.core5.http.ParseException;
+import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import org.junit.Assert;
import org.junit.Before;
@@ -73,7 +74,7 @@ public class HttpClientFactoryProdHostTest {
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
public void getCustomClientX509AuthWithHsmFacadeTrustStore() throws EaafException, ClientProtocolException,
IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException,
- CertificateEncodingException {
+ CertificateEncodingException, ParseException {
System.setProperty("javax.net.debug", "ssl:handshake");
final HttpClientConfiguration clientConfig = new HttpClientConfiguration(
@@ -89,7 +90,7 @@ public class HttpClientFactoryProdHostTest {
//perform test request
final HttpUriRequest httpGet3 = new HttpGet("https://vollmachten.egiz.gv.at/mms-eid-test/services/GetMandatesService?wsdl");
final CloseableHttpResponse httpResp3 = client.execute(httpGet3);
- Assert.assertEquals("http statusCode", 200, httpResp3.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp3.getCode());
String body = EntityUtils.toString(httpResp3.getEntity());
assertFalse("no http body", body.isEmpty());
assertTrue("no WSDL", body.contains("name=\"GetMandatesOperation\""));
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
index 7f3982be..269c516e 100644
--- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
+++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java
@@ -18,14 +18,14 @@ import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import org.apache.commons.lang3.RandomStringUtils;
-import org.apache.http.StatusLine;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.entity.ContentType;
-import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.hc.client5.http.ClientProtocolException;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.message.StatusLine;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -148,7 +148,7 @@ public class HttpClientFactoryTest {
//request webservice
final HttpUriRequest httpGet1 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp1 = client.execute(httpGet1);
- Assert.assertEquals("http statusCode", 200, httpResp1.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp1.getCode());
}
@@ -202,7 +202,7 @@ public class HttpClientFactoryTest {
//request webservice
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
//check request contains basic authentication after authentication was requested
final RecordedRequest httpReq1 = mockWebServer.takeRequest();
@@ -233,7 +233,7 @@ public class HttpClientFactoryTest {
//request webservice
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
//check request contains basic authentication after authentication was requested
final RecordedRequest httpReq1 = mockWebServer.takeRequest();
@@ -262,7 +262,6 @@ public class HttpClientFactoryTest {
final HttpClientConfiguration config =
new HttpClientConfiguration("jUnit_retry_" + RandomStringUtils.randomAlphabetic(3));
config.setHttpErrorRetryCount(2);
- config.setHttpErrorRetryPost(false);
final CloseableHttpClient client = httpClientFactory.getHttpClient(config);
Assert.assertNotNull("No httpClient", client);
@@ -290,34 +289,6 @@ public class HttpClientFactoryTest {
}
@Test
- public void httpPostRetryOneTime() throws EaafException, InterruptedException,
- ClientProtocolException, IOException {
- final HttpClientConfiguration config =
- new HttpClientConfiguration("jUnit_retry_" + RandomStringUtils.randomAlphabetic(3));
- config.setHttpErrorRetryCount(2);
- config.setHttpErrorRetryPost(true);
-
- final CloseableHttpClient client = httpClientFactory.getHttpClient(config);
- Assert.assertNotNull("No httpClient", client);
-
-
- mockWebServer = new MockWebServer();
- mockServerUrl = mockWebServer.url("/sp/junit");
- mockWebServer.enqueue(new MockResponse()
- .setSocketPolicy(SocketPolicy.NO_RESPONSE)
- .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT));
- mockWebServer.enqueue(new MockResponse().setResponseCode(200)
- .setBody("GetData"));
-
- //request webservice
- final HttpUriRequest httpGet1 = new HttpPost(mockServerUrl.url().toString());
- final StatusLine httpResp1 = client.execute(httpGet1,
- HttpUtils.simpleStatusCodeResponseHandler());
- Assert.assertEquals("http statusCode", 200, httpResp1.getStatusCode());
-
- }
-
- @Test
public void testHttpClientRetryOneTime() throws EaafException, InterruptedException,
ClientProtocolException, IOException {
final HttpClientConfiguration config =
@@ -373,7 +344,7 @@ public class HttpClientFactoryTest {
//request webservice
final HttpUriRequest httpGet1 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp1 = client.execute(httpGet1);
- Assert.assertEquals("http statusCode", 200, httpResp1.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp1.getCode());
}
@@ -543,7 +514,7 @@ public class HttpClientFactoryTest {
//perform test request
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
}
@@ -612,7 +583,7 @@ public class HttpClientFactoryTest {
//perform test request
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
}
@@ -658,7 +629,7 @@ public class HttpClientFactoryTest {
//perform test request
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
}
@@ -721,7 +692,7 @@ public class HttpClientFactoryTest {
//perform test request
final HttpUriRequest httpGet2 = new HttpGet(mockServerUrl.url().toString());
final CloseableHttpResponse httpResp2 = client.execute(httpGet2);
- Assert.assertEquals("http statusCode", 200, httpResp2.getStatusLine().getStatusCode());
+ Assert.assertEquals("http statusCode", 200, httpResp2.getCode());
}