We can use below method to call Api with Bypassing SSL Certificate.
public <T> ResponseEntity<T> performRestIntegrationToTargetServer(HttpEntity<?> httpEntity, String endPointUrl, HttpMethod httpMethod, Class<T> clazz) {
try {
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
.loadTrustMaterial(null, (chain, authType) -> true).build();
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
clientBuilder.setSSLContext(sslContext);
clientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = clientBuilder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate.exchange(endPointUrl, httpMethod, httpEntity, clazz);
} catch (HttpServerErrorException | HttpClientErrorException e) {
log.error("Error Response Body " + e.getResponseBodyAsString());
log.error("Error Status " + e.getStatusText());
log.error("Error in REST INTEGRATION ", e);
}
catch (Exception e) {
log.error("Error in REST INTEGRATION ", e);
}
return null;
}