I have create a custom keystore file xyz.jsk, When I tried to using this file I am getting exception
org.springframework.web.client.ResourceAccessException: I/O error on POST request for : sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
String keyStorePassword = "NEWPASSWORD";
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
ClassLoader classLoader = getClass().getClassLoader();
// File file = new
File(classLoader.getResource(keyStoreFile).getFile());
File file = new File(dir, "xyz.jks");;
keyStore.load(new FileInputStream(file),
keyStorePassword.toCharArray());
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.loadKeyMaterial(keyStore, keyStorePassword.toCharArray())
.build(),
NoopHostnameVerifier.INSTANCE);
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
restTemplate.setRequestFactory(httpRequestFactory);
((HttpComponentsClientHttpRequestFactory) restTemplate.getRequestFactory())
.setConnectTimeout(Integer.parseInt(strTimeOut));
ResponseEntity<String> responseEntity = restTemplate.exchange(urlPath, HttpMethod.POST, entity, clazz);