diff options
author | 2018-07-17 13:05:22 +0900 | |
---|---|---|
committer | 2018-09-12 16:15:01 +0000 | |
commit | a203ce0d45caf8e103c3edaa4647268237d96306 (patch) | |
tree | 3ec53d2c1af928076c19fa9dd0fe99ac52b7509b /ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful | |
parent | b55ec83f6513a3e9fe22ea94e91d47af04296fdd (diff) |
sonar issue fix (updated readme)
Issue-ID: PORTAL-338
Change-Id: Ie338e4707271859bfcbc30dfd04585dba206fe6f
Signed-off-by: Arindam Mondal <arind.mondal@samsung.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful')
-rw-r--r-- | ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java index 3bc6677b..5b22b75f 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/restful/client/PortalRestClientBase.java @@ -99,16 +99,13 @@ public class PortalRestClientBase { throw new IllegalArgumentException( "getRestWithCredentials: Missing one or more required properties and/or database entries"); String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword()); - CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("uebkey", uebKey); httpGet.setHeader("username", app.getUsername()); httpGet.setHeader("password", decryptedPassword); String responseJson = null; - CloseableHttpResponse response = null; logger.info(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: URL {}", uri); - try { - response = httpClient.execute(httpGet); + try (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpGet)){ logger.debug(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: status " + response.getStatusLine()); HttpEntity entity = response.getEntity(); if (entity == null) { @@ -120,12 +117,10 @@ public class PortalRestClientBase { logger.debug(EELFLoggerDelegate.debugLogger, "getRestWithCredentials: JSON {}", responseJson); EntityUtils.consume(entity); } - } finally { - if (response != null) - response.close(); + + return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson); } - httpClient.close(); - return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson); + } /** @@ -151,7 +146,6 @@ public class PortalRestClientBase { throw new IllegalArgumentException( "postRestWithCredentials: missing one or more required properties and/or database entries"); String decryptedPassword = CipherUtil.decryptPKC(app.getAppPassword()); - CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(uri); httpPost.setHeader("uebkey", uebKey); httpPost.setHeader("username", app.getUsername()); @@ -159,10 +153,8 @@ public class PortalRestClientBase { StringEntity postEntity = new StringEntity(json, ContentType.create("application/json", Consts.UTF_8)); httpPost.setEntity(postEntity); String responseJson = null; - CloseableHttpResponse response = null; - try { + try (CloseableHttpClient httpClient = HttpClients.createDefault();CloseableHttpResponse response = httpClient.execute(httpPost)){ logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: POST to {}", uri); - response = httpClient.execute(httpPost); logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: status {} ", response.getStatusLine()); HttpEntity entity = response.getEntity(); @@ -175,12 +167,11 @@ public class PortalRestClientBase { logger.debug(EELFLoggerDelegate.debugLogger, "postRestWithCredentials: JSON {}", responseJson); EntityUtils.consume(entity); } - } finally { - if (response != null) - response.close(); - } - httpClient.close(); - return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson); + + return new HttpStatusAndResponse(response.getStatusLine().getStatusCode(), responseJson); + } + + } } |