RestTemplate restTemplate = new RestTemplate();
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient closableHttpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient((HttpClient) closableHttpClient);
restTemplate = new RestTemplate(requestFactory);
In the above code, I am trying to skip the SSL validation. When I am trying to upgrade from Spring Boot 2.7 to 3.3 accordingly HttpClient4 to HttpClinet5 where HttpComponentsClientHttpRequestFactory got deprecated.
New contributor
Vasa kirankumar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.