From a2490e9093636f9c9ff02102ab69d570882e4685 Mon Sep 17 00:00:00 2001 From: "A.Alimohammadi" Date: Tue, 14 Nov 2023 11:39:47 +0330 Subject: [PATCH] [feature]add standard cookie specifications config in connection config default value for cookieSpecPolicy is ignoreCookies --- README.md | 63 ++++++++++--------- .../http/core/HttpClientProperties.java | 11 +++- .../ConfigurableApacheHttpClientFactory.java | 1 + 3 files changed, 43 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 017acea..f4a6bd3 100644 --- a/README.md +++ b/README.md @@ -221,37 +221,38 @@ You can define client config class custom prefix for setting that inherit HttpCl All configuration values are prefixed by your defined prefix. (e.g. prefix=custom-service.client `custom-service.client.connection.connectionTimeout`). -| Config | Description | Default | Example | -|----------------------------------------------|--------------------------------------|---|---| -| baseServiceUrl | Base service url (required) | | `localhost:8080/example` | -| sslContext | SSL Version (optional) | `TLSv1.2` | `TLSv1.1` | -| connection.connectionTimeout (optional) | Connection Timeout in ms | 5000 | `2000` | -| connection.socketTimeout (optional) | Socket Timeout in ms | 10000 | `5000` | -| connection.maxConnections (optional) | max number of connections | 200 | `100` | -| connection.maxConnectionsPerRoute (optional) | max number of connections per route | 50 | `10` | -| connection.timeToLive (optional) | time to live | 900 | `300` | -| connection.timeToLiveUnit (optional) | time to live unit | SECONDS | `MINUTES` | -| connection.followRedirects (optional) | following redirects | true | `true` or `false` | -| connection.connectionTimerRepeat (optional) | connection timer repeat | 3000 | `1000` | -| proxy (optional) | Configuration for used proxy servers | | | -| proxy.enable | Proxy enable (optional) | false | `true` or `false` | -| proxy.host | Hostname or IP of the Proxy | | `192.168.7.130` or `corp-proxy.domain` | -| proxy.port | Port of the Proxy (optional) | | `100` | -| proxy.user | Proxy user name (optional) | | `testUser`| -| proxy.password | Proxy password (optional) | | `testPassword` | -| ssl (optional) | Configuration for ssl | | | -| ssl.enable | SSL Enable (optional) | false | `true` or `false` | -| ssl.context | SSL Version (optional) | `TLSv1.2` | `TLSv1.1` | -| ssl.check-validity | Check SSL validity (optional) | false | `true` or `false` | -| ssl.keystore.path | Keystore file path | | `classpath:keystore.jks` | -| ssl.keystore.password | Keystore password | | `changeit` | -| ssl.keystore.type | Keystore type (optional) | `JKS` | `PKCS12` | -| ssl.truststore.path | Truststore file path | | `classpath:truststore.jks` | -| ssl.truststore.password | Truststore password | | `changeit` | -| ssl.truststore.type | Truststore type (optional) | `JKS` | `PKCS12` | -| authorization.enable | Authorization enable (optional) | false | `true` or `false` | -| authorization.username | Authorization user name (optional) | | `testUser`| -| authorization.password | Authorization password (optional) | | `testPassword` | +| Config | Description | Default | Example | +|----------------------------------------------|--------------------------------------|-----------------|-------------------------------------------------------------------------------------------------------| +| baseServiceUrl | Base service url (required) | | `localhost:8080/example` | +| sslContext | SSL Version (optional) | `TLSv1.2` | `TLSv1.1` | +| connection.connectionTimeout (optional) | Connection Timeout in ms | 5000 | `2000` | +| connection.socketTimeout (optional) | Socket Timeout in ms | 10000 | `5000` | +| connection.maxConnections (optional) | max number of connections | 200 | `100` | +| connection.maxConnectionsPerRoute (optional) | max number of connections per route | 50 | `10` | +| connection.timeToLive (optional) | time to live | 900 | `300` | +| connection.timeToLiveUnit (optional) | time to live unit | SECONDS | `MINUTES` | +| connection.followRedirects (optional) | following redirects | true | `true` or `false` | +| connection.connectionTimerRepeat (optional) | connection timer repeat | 3000 | `1000` | +| connection.cookieSpecPolicy (optional) | Standard cookie specifications | `ignoreCookies` | `compatibility`,`netscape`,`standard-strict`,`standard-strict`,`best-match`,`default`,`ignoreCookies` | +| proxy (optional) | Configuration for used proxy servers | | | +| proxy.enable | Proxy enable (optional) | false | `true` or `false` | +| proxy.host | Hostname or IP of the Proxy | | `192.168.7.130` or `corp-proxy.domain` | +| proxy.port | Port of the Proxy (optional) | | `100` | +| proxy.user | Proxy user name (optional) | | `testUser` | +| proxy.password | Proxy password (optional) | | `testPassword` | +| ssl (optional) | Configuration for ssl | | | +| ssl.enable | SSL Enable (optional) | false | `true` or `false` | +| ssl.context | SSL Version (optional) | `TLSv1.2` | `TLSv1.1` | +| ssl.check-validity | Check SSL validity (optional) | false | `true` or `false` | +| ssl.keystore.path | Keystore file path | | `classpath:keystore.jks` | +| ssl.keystore.password | Keystore password | | `changeit` | +| ssl.keystore.type | Keystore type (optional) | `JKS` | `PKCS12` | +| ssl.truststore.path | Truststore file path | | `classpath:truststore.jks` | +| ssl.truststore.password | Truststore password | | `changeit` | +| ssl.truststore.type | Truststore type (optional) | `JKS` | `PKCS12` | +| authorization.enable | Authorization enable (optional) | false | `true` or `false` | +| authorization.username | Authorization user name (optional) | | `testUser` | +| authorization.password | Authorization password (optional) | | `testPassword` | Example: diff --git a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/HttpClientProperties.java b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/HttpClientProperties.java index a8a1ec2..3f68075 100644 --- a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/HttpClientProperties.java +++ b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/HttpClientProperties.java @@ -1,5 +1,6 @@ package com.tosan.client.http.core; +import org.apache.http.client.config.CookieSpecs; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.validation.annotation.Validated; @@ -307,7 +308,7 @@ public static class ConnectionConfiguration { private int connectionTimerRepeat = DEFAULT_CONNECTION_TIMER_REPEAT; private int socketTimeout = DEFAULT_SOCKET_TIMEOUT; - + private String cookieSpecPolicy = CookieSpecs.IGNORE_COOKIES; public int getMaxConnections() { return maxConnections; @@ -372,6 +373,14 @@ public int getSocketTimeout() { public void setSocketTimeout(int socketTimeout) { this.socketTimeout = socketTimeout; } + + public String getCookieSpecPolicy() { + return cookieSpecPolicy; + } + + public void setCookieSpecPolicy(String cookieSpecPolicy) { + this.cookieSpecPolicy = cookieSpecPolicy; + } } public static class AuthorizationConfiguration { diff --git a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/factory/ConfigurableApacheHttpClientFactory.java b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/factory/ConfigurableApacheHttpClientFactory.java index 35adc6e..b3fbfc9 100644 --- a/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/factory/ConfigurableApacheHttpClientFactory.java +++ b/tosan-httpclient-spring-boot-core/src/main/java/com/tosan/client/http/core/factory/ConfigurableApacheHttpClientFactory.java @@ -69,6 +69,7 @@ private void configureTimeouts(HttpClientBuilder builder) { .setConnectTimeout(httpClientProperties.getConnection().getConnectionTimeout()) .setSocketTimeout(httpClientProperties.getConnection().getSocketTimeout()) .setRedirectsEnabled(httpClientProperties.getConnection().isFollowRedirects()) + .setCookieSpec(httpClientProperties.getConnection().getCookieSpecPolicy()) .build()); }