From bfebc0599832ee03bfa74117d56cc66bb063ce00 Mon Sep 17 00:00:00 2001 From: Skip Wonnell Date: Fri, 21 Jul 2017 08:03:48 -0400 Subject: Fix resource leak in ChefAdapterImpl.java Convert to Closeable versions of HttpClient and HttpResponse and instantiate both inside a TWR. Change-Id: I37ac34bab545592f51fb054068065fa1c00f7224 Signed-off-by: Skip Wonnell Issue: APPC-94 --- .../org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'appc-adapters/appc-chef-adapter') diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java index ac0a78b0e..9dc50e516 100644 --- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java +++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/openecomp/appc/adapter/chef/impl/ChefAdapterImpl.java @@ -594,11 +594,10 @@ public class ChefAdapterImpl implements ChefAdapter { RequestContext rc = new RequestContext(ctx); rc.isAlive(); - try { - HttpGet httpGet = new HttpGet(tVmIp); - HttpClient httpClient = HttpClients.createDefault(); - HttpResponse response = null; - response = httpClient.execute(httpGet); + HttpGet httpGet = new HttpGet(tVmIp); + try ( CloseableHttpClient httpClient = HttpClients.createDefault(); + CloseableHttpResponse response = httpClient.execute(httpGet); ) + { int responseCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); String responseOutput = EntityUtils.toString(entity); -- cgit 1.2.3-korg