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 | |
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')
3 files changed, 15 insertions, 41 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java index 28bd39d9..2e8875c0 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/conf/HibernateConfiguration.java @@ -97,15 +97,9 @@ public class HibernateConfiguration { @SuppressWarnings("rawtypes") @Bean public Map dataSourceMap() throws Exception { - Connection conn = null; - Statement stmt = null; - ResultSet rs = null; - Map<String, ComboPooledDataSource> dataSourceMap = new HashMap<String, ComboPooledDataSource>(); - try { - conn = dataSource.getConnection(); - stmt = conn.createStatement(); - String sql = "SELECT schema_id,datasource_type,connection_url,user_name,password,driver_class,min_pool_size,max_pool_size,idle_connection_test_period FROM schema_info"; - rs = stmt.executeQuery(sql); + Map<String, ComboPooledDataSource> dataSourceMap = new HashMap<>(); + String sql = "SELECT schema_id,datasource_type,connection_url,user_name,password,driver_class,min_pool_size,max_pool_size,idle_connection_test_period FROM schema_info"; + try (Connection conn = dataSource.getConnection();Statement stmt = conn.createStatement();ResultSet rs = stmt.executeQuery(sql)){ while (rs.next()) { ComboPooledDataSource pool = new ComboPooledDataSource(); pool.setDriverClass(rs.getString("driver_class")); @@ -121,18 +115,7 @@ public class HibernateConfiguration { logger.error(EELFLoggerDelegate.errorLogger, "dataSourceMap failed", e); dataSourceMap = null; throw e; - } finally { - try { - if (rs != null) - rs.close(); - if (stmt != null) - stmt.close(); - if (conn != null) - conn.close(); - } catch (SQLException se2) { - logger.warn(EELFLoggerDelegate.errorLogger, "dataSourceMap failed to close", se2); - } - } + } return dataSourceMap; } 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); + } + + } } diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java index 95e1c501..ca96a360 100644 --- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java +++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/service/LoginServiceImpl.java @@ -79,7 +79,7 @@ public class LoginServiceImpl extends FusionService implements LoginService { boolean matchPassword) { User user; - if (bean.getUserid() != null && bean.getUserid() != null) { + if (bean.getUserid() != null) { user = findUser(bean); } else { if (matchPassword) |