aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-02-07 10:27:01 +0000
committerGerrit Code Review <gerrit@onap.org>2018-02-07 10:27:01 +0000
commite62930494cbc3ca8d66eeaf1ded32f838763bbf9 (patch)
tree2fc78797edb334ff9bc89cc7df885116ec593579
parentb5df7eca046a31b96b21413b4d83f472f4a08088 (diff)
parenteba2cbbff875173fdbab09b08870f01b8c24b66a (diff)
Merge "Sonar blocker issue - closeableHttpClient"
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/workflow/serviceTask/AbstractSdncOperationTask.java118
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;
}