From 6441b69bd31a3deb7104958e37044ceaafb0d5ca Mon Sep 17 00:00:00 2001 From: Tomek Kaminski Date: Tue, 2 Jan 2018 15:28:57 +0100 Subject: Fix for sonar blocker Add missing close operation on ClosableHttpClient instance in executeHttpRequest method of RestAdapterImpl.java Resolve sonar blocker using try-with-resources clause. Change-Id: Ibaf5eba70abd4a042708eb686da073e673d547fb Issue-ID: APPC-364 Signed-off-by: Tomek Kaminski --- .../main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'appc-adapters/appc-rest-adapter') diff --git a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java index bbb37f4cf..b45a5da5c 100644 --- a/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java +++ b/appc-adapters/appc-rest-adapter/appc-rest-adapter-bundle/src/main/java/org/onap/appc/adapter/rest/impl/RestAdapterImpl.java @@ -35,6 +35,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.glassfish.grizzly.http.util.HttpStatus; @@ -177,8 +178,7 @@ public class RestAdapterImpl implements RestAdapter { } public void executeHttpRequest(HttpRequestBase httpRequest, RequestContext rc){ - try { - HttpClient httpClient = HttpClients.createDefault(); + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpResponse response = httpClient.execute(httpRequest); int responseCode = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); -- cgit 1.2.3-korg