diff options
author | liboNet <libo.zhu@intel.com> | 2018-02-06 05:29:12 +0800 |
---|---|---|
committer | liboNet <libo.zhu@intel.com> | 2018-02-08 08:23:13 +0800 |
commit | eba2cbbff875173fdbab09b08870f01b8c24b66a (patch) | |
tree | 227346ce891037a84dfaeaa0e937c5a2cb67f29e /bpmn/MSOInfrastructureBPMN/src/main/java/org | |
parent | 1b9f60bf292b24a33df33cedacad83bb868b450c (diff) |
Sonar blocker issue - closeableHttpClient
user the try-with-resource method to fix issue
https://sonar.onap.org/issues/search#issues=AV-B6Uh2-08if2a6r-Va
and https://sonar.onap.org/issues/search#issues=AV-B6Uh2-08if2a6r-Vb
Change-Id: I70a6424307e88c28a7290ed23d13888ef55c3aa3
Issue-ID: SO-165
Signed-off-by: Zhu Libo <libo.zhu@intel.com>
Diffstat (limited to 'bpmn/MSOInfrastructureBPMN/src/main/java/org')
-rw-r--r-- | bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java | 118 |
1 files changed, 18 insertions, 100 deletions
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java index 823223fbd8..dfa390c296 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java @@ -115,14 +115,11 @@ public abstract class AbstractSdncOperationTask extends BaseTask { protected String httpPost(String url, HttpPost httpPost) throws RouteException { logger.info("AbstractSdncOperationTask.httpPost begin!"); - CloseableHttpClient httpClient = HttpClients.createDefault(); String result = null; - boolean var15 = false; String errorMsg; label91: { - try { - var15 = true; + try(CloseableHttpClient httpClient = HttpClients.createDefault()) { CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost); result = EntityUtils.toString(closeableHttpResponse.getEntity()); logger.info("result = {}", result); @@ -133,42 +130,14 @@ public abstract class AbstractSdncOperationTask extends BaseTask { } closeableHttpResponse.close(); - var15 = false; break label91; - } catch (IOException var19) { + } catch (IOException e) { errorMsg = url + ":httpPostWithJSON connect faild"; logger.info("exception: POST_CONNECT_FAILD : {}", errorMsg); - throwsRouteException(errorMsg, var19, "POST_CONNECT_FAILD"); - var15 = false; - } finally { - if(var15) { - try { - httpClient.close(); - } catch (IOException var16) { - String errorMsg1 = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg1); - throwsRouteException(errorMsg1, var16, "CLOSE_CONNECT_FAILD"); - } - - } - } - - try { - httpClient.close(); - } catch (IOException var17) { - errorMsg = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg); - throwsRouteException(errorMsg, var17, "CLOSE_CONNECT_FAILD"); + throwsRouteException(errorMsg, e, "POST_CONNECT_FAILD"); } } - try { - httpClient.close(); - } catch (IOException var18) { - errorMsg = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD : {}", errorMsg); - throwsRouteException(errorMsg, var18, "CLOSE_CONNECT_FAILD"); - } logger.info("AbstractSdncOperationTask.httpPost end!"); return result; } @@ -223,78 +192,27 @@ public abstract class AbstractSdncOperationTask extends BaseTask { private String httpGet(String url, HttpGet httpGet) throws RouteException { logger.info("AbstractSdncOperationTask.httpGet begin!"); - boolean var16 = false; - CloseableHttpClient httpClient = HttpClients.createDefault(); String result = ""; String errorMsg; - label109: - { - label110: - { - try { - var16 = true; - CloseableHttpResponse e = httpClient.execute(httpGet); - result = EntityUtils.toString(e.getEntity()); - logger.info("result = {}", result); - if (e.getStatusLine().getStatusCode() != 200) { - logger.info("exception: fail for status code = {}", e.getStatusLine().getStatusCode()); + try(CloseableHttpClient httpClient = HttpClients.createDefault()) { + CloseableHttpResponse e = httpClient.execute(httpGet); + result = EntityUtils.toString(e.getEntity()); + logger.info("result = {}", result); + if (e.getStatusLine().getStatusCode() != 200) { + logger.info("exception: fail for status code = {}", e.getStatusLine().getStatusCode()); throw new RouteException(result, "SERVICE_GET_ERR"); } - e.close(); - var16 = false; - break label110; - } catch (ClientProtocolException var21) { - errorMsg = url + ":httpGetWithJSON connect faild"; - logger.info("exception: GET_CONNECT_FAILD {}", errorMsg); - throwsRouteException(errorMsg, var21, "GET_CONNECT_FAILD"); - var16 = false; - } catch (IOException var22) { - errorMsg = url + ":httpGetWithJSON connect faild"; - logger.info("exception: GET_CONNECT_FAILD {}", errorMsg); - throwsRouteException(errorMsg, var22, "GET_CONNECT_FAILD"); - var16 = false; - break label109; - } finally { - if (var16) { - try { - httpClient.close(); - } catch (IOException var17) { - String errorMsg1 = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg1); - throwsRouteException(errorMsg1, var17, "CLOSE_CONNECT_FAILD"); - } - - } - } + } catch (ClientProtocolException e) { + errorMsg = url + ":httpGetWithJSON connect faild"; + logger.info("exception: GET_CONNECT_FAILD {}", errorMsg); + throwsRouteException(errorMsg, e, "GET_CONNECT_FAILD"); + } catch (IOException e) { + errorMsg = url + ":httpGetWithJSON connect faild"; + logger.info("exception: GET_CONNECT_FAILD {}", errorMsg); + throwsRouteException(errorMsg, e, "GET_CONNECT_FAILD"); + } - try { - httpClient.close(); - } catch (IOException var19) { - errorMsg = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg); - throwsRouteException(errorMsg, var19, "CLOSE_CONNECT_FAILD"); - } - - } - - try { - httpClient.close(); - } catch (IOException var20) { - errorMsg = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg); - throwsRouteException(errorMsg, var20, "CLOSE_CONNECT_FAILD"); - } - - } - - try { - httpClient.close(); - } catch (IOException var18) { - errorMsg = url + ":close httpClient faild"; - logger.info("exception: CLOSE_CONNECT_FAILD {}", errorMsg); - throwsRouteException(errorMsg, var18, "CLOSE_CONNECT_FAILD"); - } logger.info("AbstractSdncOperationTask.httpGet end!"); return result; } |