From dd403753bf22b4292e3ee513dc3391b6dbb5a8d2 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Thu, 6 Feb 2020 12:03:41 +0900 Subject: [PATCH] Fix minor issues Either log or rethrow this exception This block of commented-out lines of code should be removed Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$' Issue-ID: PORTAL-562 Change-Id: I72a7651070462de9bd1e0abb1e83c175d03aa1f3 Signed-off-by: Parshad Patel --- .../portal/scheduler/client/HttpsBasicClient.java | 41 ++++++++-------------- .../service/ApplicationsRestClientServiceImpl.java | 14 ++------ .../portal/service/MicroserviceServiceImpl.java | 1 - 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java index d618a6ee..c79d6c05 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java @@ -77,8 +77,7 @@ public class HttpsBasicClient{ public static Client getClient() throws Exception { String methodName = "getClient"; ClientConfig config = new ClientConfig(); - //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - //config.getClasses().add(org.onap.aai.util.CustomJacksonJaxBJsonProvider.class); + SSLContext ctx = null; @@ -87,17 +86,17 @@ public class HttpsBasicClient{ SimpleDateFormat dateFormat = DateUtil.getDateFormat(); config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); - String truststore_path = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME); + String truststorePath = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " " + "truststore_path=" + - truststore_path); - String truststore_password = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X); + truststorePath); + String truststorePassword = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X); - String decrypted_truststore_password = Password.deobfuscate(truststore_password); + String decryptedTruststorePassword = Password.deobfuscate(truststorePassword); //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password); - File tr = new File (truststore_path); + File tr = new File (truststorePath); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute " + "truststore path=" + tr.getAbsolutePath()); @@ -105,8 +104,8 @@ public class HttpsBasicClient{ //String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X); //String decrypted_keystore_password = EncryptedPropValue.decryptTriple(keystore_password); - System.setProperty("javax.net.ssl.trustStore", truststore_path); - System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password); + System.setProperty("javax.net.ssl.trustStore", truststorePath); + System.setProperty("javax.net.ssl.trustStorePassword", decryptedTruststorePassword); HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){ public boolean verify(String string,SSLSession ssls) { return true; @@ -134,9 +133,7 @@ public class HttpsBasicClient{ ctx.init(kmf.getKeyManagers(), null, null); */ ctx.init(null, null, null); - //config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, - // new HTTPSProperties( , ctx)); - + return ClientBuilder.newBuilder() .sslContext(ctx) .hostnameVerifier(new HostnameVerifier() { @@ -148,17 +145,9 @@ public class HttpsBasicClient{ .build() .register(CustomJacksonJaxBJsonProvider.class); - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting"); - //System.out.println("Error setting up config: exiting"); - e.printStackTrace(); - return null; - } - - //Client client = ClientBuilder.newClient(config); - // uncomment this line to get more logging for the request/response - // client.addFilter(new LoggingFilter(System.out)); - - //return client; - } -} + } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting", e); + return null; + } + } +} diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java index 18dabfb5..09d78046 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java @@ -133,7 +133,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient logger.debug(EELFLoggerDelegate.debugLogger, "http response status=" + status); MDC.put(EPCommonSystemProperties.EXTERNAL_API_RESPONSE_CODE, Integer.toString(status)); if (!isHttpSuccess(status)) { - String errMsg = "Failed. Status=" + status + restPath +"; [" + ((ResponseImpl)response).getStatusInfo().getReasonPhrase().toString() + String errMsg = "Failed. Status=" + status + restPath +"; [" + ((ResponseImpl)response).getStatusInfo().getReasonPhrase() + "]"; URL url = null; try { @@ -255,7 +255,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient Response response = getResponse(appId, restPath); if (response != null) { - //verifyResponse(response); verifyResponse(response,restPath); /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code, but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which @@ -278,13 +277,11 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient Response response = getResponse(appId, restPath); if (response != null) { - //verifyResponse(response); verifyResponse(response,restPath); /* It is not recommendable to use the implementation class org.apache.cxf.jaxrs.impl.ResponseImpl in the code, but had to force this in-order to prevent conflict with the ResponseImpl class of Jersey Client which doesn't work as expected. Created Portal-253 for tracking */ - String incomingJson = ((ResponseImpl)response).readEntity(String.class); - return incomingJson; + return ((ResponseImpl)response).readEntity(String.class); } return ""; @@ -308,7 +305,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient Response response = getResponse(appId, restPath); if (response != null) { - //verifyResponse(response); verifyResponse(response,restPath); String str = ((ResponseImpl)response).readEntity(String.class); EcompPortalUtils.logAndSerializeObject(logger, restPath, "GET result =", str); @@ -316,7 +312,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient try { t = mapper.readValue(str, clazz); } catch (Exception e) { - e.printStackTrace(); EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e); } } @@ -373,16 +368,12 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient } if (response != null) { - //verifyResponse(response); verifyResponse(response,restPath); - // String contentType = response.getHeaderString("Content-Type"); if (clazz != null) { String str = ((ResponseImpl)response).readEntity(String.class); EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST result =", str); try { t = (T) gson.fromJson(str, clazz); - - //t = gson.fromJson(str, clazz); } catch (Exception e) { EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeInvalidJsonInput, e); } @@ -430,7 +421,6 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient } if (response != null) { - //verifyResponse(response); verifyResponse(response,restPath); String str = ((ResponseImpl)response).readEntity(String.class); EcompPortalUtils.logAndSerializeObject(logger, restPath, "PUT result =", str); diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java index b41d898a..451500d6 100644 --- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/MicroserviceServiceImpl.java @@ -136,7 +136,6 @@ public class MicroserviceServiceImpl implements MicroserviceService { dataAccessService.executeNamedQuery("deleteMicroservice", params, null); } catch (Exception e) { - e.printStackTrace(); logger.error(EELFLoggerDelegate.errorLogger, "deleteMicroservice failed", e); throw e; } -- 2.16.6