We are trying to upgrade the httpclient from 4 to 5. As a part of the upgrade, we have changed the imports accordingly. But, the code uses Httpclientbuilder and sets the sslcontext. As per the documentation from apache, they have removed the setsslcontext from the Httpclientbuilder methods and I have not found any alternative.
The error says The method setSSLContext(sslcontext) is undefined for the type HttpClientBuilder.
The code is as follows:
@Autowired
public AdministrativoClient(RestTemplate restTemplate, @Value("${administrativo.service.url}") String pathUrl) {
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext;
try {
sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
this.restTemplate = restTemplate;
restTemplate.setRequestFactory(requestFactory);
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
e.printStackTrace();
}
this.pathUrl = pathUrl;
}