diff --git a/spring-web-modules/spring-resttemplate-3/pom.xml b/spring-web-modules/spring-resttemplate-3/pom.xml index 5ce7d348a2..7353ed38d7 100644 --- a/spring-web-modules/spring-resttemplate-3/pom.xml +++ b/spring-web-modules/spring-resttemplate-3/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -24,6 +24,16 @@ org.springframework.boot spring-boot-starter-test + + org.apache.httpcomponents.client5 + httpclient5 + ${httpclient5.version} + + + com.baeldung.resttemplate.methods.RestTemplateMethodsApplication + 5.2.1 + + diff --git a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/custom/CustomRestTemplateConfiguration.java b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/custom/CustomRestTemplateConfiguration.java index 9383b584c4..d29960789e 100644 --- a/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/custom/CustomRestTemplateConfiguration.java +++ b/spring-web-modules/spring-resttemplate-3/src/main/java/com/baeldung/resttemplate/custom/CustomRestTemplateConfiguration.java @@ -9,10 +9,12 @@ import java.security.cert.CertificateException; import javax.net.ssl.SSLContext; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.ssl.SSLContextBuilder; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder; +import org.apache.hc.client5.http.io.HttpClientConnectionManager; +import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory; +import org.apache.hc.core5.ssl.SSLContextBuilder; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -38,7 +40,11 @@ public class CustomRestTemplateConfiguration { .loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build(); SSLConnectionSocketFactory sslConFactory = new SSLConnectionSocketFactory(sslContext); - CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslConFactory).build(); + final HttpClientConnectionManager cm = PoolingHttpClientConnectionManagerBuilder.create() + .setSSLSocketFactory(sslConFactory) + .build(); + + CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build(); ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); return new RestTemplate(requestFactory); }