diff options
author | Krishnajinka <kris.jinka@samsung.com> | 2018-07-06 11:40:55 +0900 |
---|---|---|
committer | Krishnajinka <kris.jinka@samsung.com> | 2018-07-09 10:08:05 +0900 |
commit | da8d16cb974f9b203a59fb350e2179bf19ac3bce (patch) | |
tree | f48a34880dabe8fe14aa5cf3a1a47089c320daad /appc-adapters/appc-ansible-adapter | |
parent | f5d3fa206b636a7e235b57b43a7812c92258208a (diff) |
use try with resources
Issue-ID: APPC-1046
Change-Id: I28ca35b8a888875f91afda05c4dedee3ed301dde
Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'appc-adapters/appc-ansible-adapter')
-rw-r--r-- | appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/ConnectionBuilder.java | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/ConnectionBuilder.java b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/ConnectionBuilder.java index c01fad75f..2272dd26b 100644 --- a/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/ConnectionBuilder.java +++ b/appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/ConnectionBuilder.java @@ -78,22 +78,23 @@ public class ConnectionBuilder { KeyManagementException, NoSuchAlgorithmException, APPCException { /* Point to the certificate */ - FileInputStream fs = new FileInputStream(certFile); + try(FileInputStream fs = new FileInputStream(certFile)) { - /* Generate a certificate from the X509 */ - CertificateFactory cf = CertificateFactory.getInstance("X.509"); - X509Certificate cert = (X509Certificate) cf.generateCertificate(fs); + /* Generate a certificate from the X509 */ + CertificateFactory cf = CertificateFactory.getInstance("X.509"); + X509Certificate cert = (X509Certificate) cf.generateCertificate(fs); - /* Create a keystore object and load the certificate there */ - KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); - keystore.load(null, null); - keystore.setCertificateEntry("cacert", cert); + /* Create a keystore object and load the certificate there */ + KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); + keystore.load(null, null); + keystore.setCertificateEntry("cacert", cert); - SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); - SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, - SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); + SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(keystore).build(); + SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslcontext, + SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); - httpClient = HttpClients.custom().setSSLSocketFactory(factory).build(); + httpClient = HttpClients.custom().setSSLSocketFactory(factory).build(); + } } /** |