+ 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 {
+ try (InputStream inputStream = new FileInputStream(ResourceUtils.getFile("/opt/onap/sdnc/data/properties/https-props.properties"))) {
+ Properties properties = new Properties();
+ properties.load(inputStream);
+ final String keyPassword = properties.getProperty("key-password");
+ final String keystorePassword = properties.getProperty("keystore-password");
+ final String truststorePassword = properties.getProperty("truststore-password");
+ final boolean isTrustStoreUsed = Boolean.parseBoolean(properties.getProperty("isTrustStoreUsed"));
+ SSLContextBuilder builder = SSLContexts.custom()
+ .loadKeyMaterial(ResourceUtils.getFile(properties.getProperty("key-store")),
+ keystorePassword.toCharArray(), keyPassword.toCharArray());
+ if (isTrustStoreUsed) {
+ builder.loadTrustMaterial(ResourceUtils.getFile(properties.getProperty("trust-store")),
+ truststorePassword.toCharArray());
+ } else {
+ builder.loadTrustMaterial(null, new TrustAllStrategy());
+ }
+ SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
+ HttpClient client = HttpClients.custom().setSSLSocketFactory(scsf).build();
+ HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
+ requestFactory.setHttpClient(client);
+ return new RestTemplate(requestFactory);
+ }