From 81f26b4c1837c9f8ff49619782fe01d99f4f0683 Mon Sep 17 00:00:00 2001 From: "k.kazak" Date: Wed, 14 Aug 2019 10:18:31 +0200 Subject: Close input streams via try-with-resources DefaultDmaapPropertiesImpl: close FileInputStream after loading ServicePluginFactory: close HttpClient if processing fails close application.properties InputStream after loading remove redundant catch block if behavior is the same add logging of exception in finally block BpmnInstaller: close csarFile if processing fails Change-Id: Ic6f942c401277c5150c5cc1297aba27ccd40694c Coverity-scan: CID-203903, CID-211476, CID-211615, CID-219308 Issue-ID: SO-2211 Signed-off-by: k.kazak --- .../workflow/service/ServicePluginFactory.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'bpmn/so-bpmn-infrastructure-common/src') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java index 2f05eb5f2d..29dca19820 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java @@ -50,6 +50,7 @@ import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; @@ -98,8 +99,7 @@ public class ServicePluginFactory { new String[] {VS_MONITORED, VS_UNMONITORED, TS_MONITORED, TS_UNMONITORED}; static { - try { - InputStream is = ClassLoader.class.getResourceAsStream("/application.properties"); + try (InputStream is = ClassLoader.class.getResourceAsStream("/application.properties")) { if (null != is) { Properties prop = new Properties(); prop.load(is); @@ -855,14 +855,12 @@ public class ServicePluginFactory { HttpRequestBase method = null; HttpResponse httpResponse = null; - try { + try (CloseableHttpClient client = HttpClientBuilder.create().build()) { int timeout = DEFAULT_TIME_OUT; RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) .setConnectionRequestTimeout(timeout).build(); - HttpClient client = HttpClientBuilder.create().build(); - if ("POST".equalsIgnoreCase(methodType)) { HttpPost httpPost = new HttpPost(msbUrl); httpPost.setConfig(requestConfig); @@ -902,9 +900,6 @@ public class ServicePluginFactory { method = null; return responseContent; - } catch (SocketTimeoutException | ConnectTimeoutException e) { - return null; - } catch (Exception e) { return null; @@ -913,13 +908,14 @@ public class ServicePluginFactory { try { EntityUtils.consume(httpResponse.getEntity()); } catch (Exception e) { + logger.debug("Exception while executing finally block", e); } } if (method != null) { try { method.reset(); } catch (Exception e) { - + logger.debug("Exception while executing finally block", e); } } } -- cgit 1.2.3-korg