From 5963a990413c48f90329caf145a37a4e0970d935 Mon Sep 17 00:00:00 2001 From: urviljoshi Date: Fri, 16 Sep 2022 17:09:21 +0530 Subject: [PATCH] MOSIP-23945 bean defination modified for websub and authcode proxy flow --- .../api/config/AuthCodeProxyConfig.java | 17 +++++++++++- .../WebSubPublisherClientConfig.java | 26 ++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/kernel/kernel-authcodeflowproxy-api/src/main/java/io/mosip/kernel/authcodeflowproxy/api/config/AuthCodeProxyConfig.java b/kernel/kernel-authcodeflowproxy-api/src/main/java/io/mosip/kernel/authcodeflowproxy/api/config/AuthCodeProxyConfig.java index 278e037f6ca..3381eff9f14 100644 --- a/kernel/kernel-authcodeflowproxy-api/src/main/java/io/mosip/kernel/authcodeflowproxy/api/config/AuthCodeProxyConfig.java +++ b/kernel/kernel-authcodeflowproxy-api/src/main/java/io/mosip/kernel/authcodeflowproxy/api/config/AuthCodeProxyConfig.java @@ -1,16 +1,31 @@ package io.mosip.kernel.authcodeflowproxy.api.config; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; @Configuration public class AuthCodeProxyConfig { + + @Value("${authcodeproxyflow.httpclient.connections.max.per.host:20}") + private int maxConnectionPerRoute; + + @Value("${authcodeproxyflow.httpclient.connections.max:100}") + private int totalMaxConnection; @ConditionalOnMissingBean(RestTemplate.class) @Bean RestTemplate restTemplate() { - return new RestTemplate(); + HttpClientBuilder httpClientBuilder = HttpClients.custom() + .setMaxConnPerRoute(maxConnectionPerRoute) + .setMaxConnTotal(totalMaxConnection).disableCookieManagement(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClientBuilder.build()); + return new RestTemplate(requestFactory); } } diff --git a/kernel/kernel-websubclient-api/src/main/java/io/mosip/kernel/websub/api/config/publisher/WebSubPublisherClientConfig.java b/kernel/kernel-websubclient-api/src/main/java/io/mosip/kernel/websub/api/config/publisher/WebSubPublisherClientConfig.java index f447da781ca..b6e8b251285 100644 --- a/kernel/kernel-websubclient-api/src/main/java/io/mosip/kernel/websub/api/config/publisher/WebSubPublisherClientConfig.java +++ b/kernel/kernel-websubclient-api/src/main/java/io/mosip/kernel/websub/api/config/publisher/WebSubPublisherClientConfig.java @@ -1,8 +1,17 @@ package io.mosip.kernel.websub.api.config.publisher; +import java.util.Collections; + +import javax.net.ssl.SSLSession; + +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; import io.mosip.kernel.core.websub.spi.PublisherClient; @@ -17,16 +26,25 @@ @Configuration public class WebSubPublisherClientConfig { + @Value("${websub.httpclient.connections.max.per.host:20}") + private int maxConnectionPerRoute; + + @Value("${websub.httpclient.connections.max:100}") + private int totalMaxConnection; @Bean(name = "websubRestTemplate") public RestTemplate restTemplate() { - return new RestTemplate(); + HttpClientBuilder httpClientBuilder = HttpClients.custom() + .setMaxConnPerRoute(maxConnectionPerRoute) + .setMaxConnTotal(totalMaxConnection).disableCookieManagement(); + HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(); + requestFactory.setHttpClient(httpClientBuilder.build()); + return new RestTemplate(requestFactory); } - @Bean - public

PublisherClient publisherClient(){ + public

PublisherClient publisherClient() { return new PublisherClientImpl<>(); - } + } }