diff options
Diffstat (limited to 'cps-ncmp-service')
3 files changed, 13 insertions, 13 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java index aaa4f1e5bb..729930e65e 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/HttpClientConfiguration.java @@ -29,7 +29,7 @@ import org.springframework.boot.convert.DurationUnit; @Getter @Setter -@ConfigurationProperties(prefix = "httpclient5", ignoreUnknownFields = true) +@ConfigurationProperties(prefix = "ncmp.dmi.httpclient", ignoreUnknownFields = true) public class HttpClientConfiguration { /** diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java index 4460094f54..c6ff116a7f 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/config/NcmpConfiguration.java @@ -72,33 +72,33 @@ public class NcmpConfiguration { */ @Bean @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON) - public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder, + public static RestTemplate restTemplate(final RestTemplateBuilder restTemplateBuilder, final HttpClientConfiguration httpClientConfiguration) { - + final ConnectionConfig connectionConfig = ConnectionConfig.copy(ConnectionConfig.DEFAULT) .setConnectTimeout(Timeout.of(httpClientConfiguration.getConnectionTimeoutInSeconds())) .build(); - + final PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create() .setDefaultConnectionConfig(connectionConfig) .setMaxConnTotal(httpClientConfiguration.getMaximumConnectionsTotal()) .setMaxConnPerRoute(httpClientConfiguration.getMaximumConnectionsPerRoute()) .build(); - + final CloseableHttpClient httpClient = HttpClients.custom() .setConnectionManager(connectionManager) .evictExpiredConnections() .evictIdleConnections( TimeValue.of(httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds())) .build(); - + final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); - + final RestTemplate restTemplate = restTemplateBuilder .requestFactory(() -> requestFactory) .setConnectTimeout(httpClientConfiguration.getConnectionTimeoutInSeconds()) .build(); - + setRestTemplateMessageConverters(restTemplate); return restTemplate; } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy index 941c8b8a70..2c76b5bb44 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/config/HttpClientConfigurationSpec.groovy @@ -31,7 +31,7 @@ import spock.lang.Specification @SpringBootTest @ContextConfiguration(classes = [HttpClientConfiguration]) @EnableConfigurationProperties(HttpClientConfiguration.class) -@TestPropertySource(properties = ["httpclient5.connectionTimeoutInSeconds=1", "httpclient5.maximumConnectionsTotal=200"]) +@TestPropertySource(properties = ["ncmp.dmi.httpclient.connectionTimeoutInSeconds=1", "ncmp.dmi.httpclient.maximumConnectionsTotal=200"]) class HttpClientConfigurationSpec extends Specification { @Autowired @@ -39,10 +39,10 @@ class HttpClientConfigurationSpec extends Specification { def 'Test HttpClientConfiguration properties with custom and default values'() { expect: 'custom property values' - httpClientConfiguration.getConnectionTimeoutInSeconds() == Duration.ofSeconds(1) - httpClientConfiguration.getMaximumConnectionsTotal() == 200 + assert httpClientConfiguration.getConnectionTimeoutInSeconds() == Duration.ofSeconds(1) + assert httpClientConfiguration.getMaximumConnectionsTotal() == 200 and: 'default property values' - httpClientConfiguration.getMaximumConnectionsPerRoute() == 50 - httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds() == Duration.ofSeconds(5) + assert httpClientConfiguration.getMaximumConnectionsPerRoute() == 50 + assert httpClientConfiguration.getIdleConnectionEvictionThresholdInSeconds() == Duration.ofSeconds(5) } } |