+ restTemplateHttp = new RestTemplate();
+ try {
+ restTemplateHttps = createRestTemplateForHttps();
+ } catch (IOException | UnrecoverableKeyException | KeyManagementException | CertificateException
+ | NoSuchAlgorithmException | KeyStoreException ex) {
+ log.error("Caught exception when trying to create restTemplateHttps: {}", ex.getMessage());
+ }
+ }
+
+ private RestTemplate createRestTemplateForHttps() throws IOException, UnrecoverableKeyException, CertificateException,
+ NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
+ InputStream inputStream = RestAdapterImpl.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE);
+ if (inputStream == null) {
+ throw new FileNotFoundException("properties file not found in classpath");
+ } else {
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ final String keystorePassword = properties.getProperty("key-store-password");
+ SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(
+ SSLContexts.custom()
+ .loadKeyMaterial(ResourceUtils.getFile(properties.getProperty("key-store")),
+ keystorePassword.toCharArray(), keystorePassword.toCharArray())
+ .loadTrustMaterial(null, new TrustSelfSignedStrategy())
+ .build(),
+ NoopHostnameVerifier.INSTANCE);
+ HttpClient client = HttpClients.custom().setSSLSocketFactory(scsf).build();
+ HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
+ requestFactory.setHttpClient(client);
+ inputStream.close();
+ return new RestTemplate(requestFactory);
+ }