From 226aadd94fbb08f484476dee54cbb9da02a2a4ff Mon Sep 17 00:00:00 2001 From: "A.Alimohammadi" Date: Tue, 14 Nov 2023 11:45:54 +0330 Subject: [PATCH] [feature]add standard cookie specifications config in connection config default value for cookieSpecPolicy is ignore --- README.md | 63 ++++++++++--------- .../http/core/HttpClientProperties.java | 11 ++++ .../ConfigurableApacheHttpClientFactory.java | 1 + 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 2decb80..6746cd4 100644 --- a/README.md +++ b/README.md @@ -226,37 +226,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 | `ignore` | `relaxed`,`strict`,`ignore` | +| 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..20b8b97 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.hc.client5.http.cookie.StandardCookieSpec; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.validation.annotation.Validated; @@ -308,6 +309,8 @@ public static class ConnectionConfiguration { private int socketTimeout = DEFAULT_SOCKET_TIMEOUT; + private String cookieSpecPolicy = StandardCookieSpec.IGNORE; + public int getMaxConnections() { return maxConnections; @@ -372,6 +375,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 e17db0d..4cf723c 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 @@ -64,6 +64,7 @@ private void configureTimeouts(HttpClientBuilder builder) { .setConnectTimeout(httpClientProperties.getConnection().getConnectionTimeout(), TimeUnit.MILLISECONDS) .setConnectionRequestTimeout(httpClientProperties.getConnection().getSocketTimeout(), TimeUnit.MILLISECONDS) .setRedirectsEnabled(httpClientProperties.getConnection().isFollowRedirects()) + .setCookieSpec(httpClientProperties.getConnection().getCookieSpecPolicy()) .build()); }