From ac601e0a3093360e6e9765f6f2538ecbf863b1dd Mon Sep 17 00:00:00 2001 From: burdziak Date: Fri, 19 Apr 2019 12:02:07 +0200 Subject: Fix sonar issues in ErrorHandler Change-Id: I7824b6bb52b4e3f8b205cdfa3a56281bf5423b50 Issue-ID: PORTAL-523 Signed-off-by: burdziak --- .../portalsdk/analytics/controller/ErrorHandler.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'ecomp-sdk/epsdk-analytics/src/main/java') diff --git a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java index 403c6b6b..1a31e604 100644 --- a/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java +++ b/ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java @@ -68,13 +68,12 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject { } public void processError(HttpServletRequest request, String errorMsg) { - //Log.write(errorMsg, 2); logger.error(EELFLoggerDelegate.debugLogger, (errorMsg)); - ArrayList error_list = (ArrayList) request.getAttribute(AppConstants.RI_ERROR_LIST); - if (error_list == null) - error_list = new ArrayList(1); - error_list.add(errorMsg); - request.setAttribute(AppConstants.RI_ERROR_LIST, error_list); + ArrayList errorList = (ArrayList) request.getAttribute(AppConstants.RI_ERROR_LIST); + if (errorList == null) + errorList = new ArrayList(1); + errorList.add(errorMsg); + request.setAttribute(AppConstants.RI_ERROR_LIST, errorList); } // processError public void processError(HttpServletRequest request, RaptorException e) { @@ -83,7 +82,7 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject { private String getSessionLog(HttpServletRequest request) { String[] sessionVariablesToLog = Globals.getLogVariablesInSession().split(","); - StringBuffer sessionLogStrBuf = new StringBuffer("\n"); + StringBuilder sessionLogStrBuf = new StringBuilder("\n"); sessionLogStrBuf.append("***** ADDITIONAL INFORMATION ******"); HttpSession session = request.getSession(); ReportRuntime rr = (ReportRuntime) session.getAttribute(AppConstants.SI_REPORT_RUNTIME); @@ -106,7 +105,6 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject { return sessionLogStrBuf.toString(); } public String processFatalError(HttpServletRequest request, RaptorException e) { - //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1); logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR); if (e instanceof ReportSQLException) { String errorSQL = ((ReportSQLException) e).getReportSQL(); @@ -120,28 +118,25 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject { } // processFatalError public String processFatalErrorJSON(HttpServletRequest request, RaptorException e) { - //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1); logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR); if (e instanceof ReportSQLException) { String errorSQL = ((ReportSQLException) e).getReportSQL(); if (nvl(errorSQL).length() > 0) request.setAttribute("c_error_sql", errorSQL); } // if - //AppUtils.processErrorNotification(request, e); request.setAttribute(AppConstants.RI_EXCEPTION, e); ErrorJSONRuntime errorJSONRuntime = new ErrorJSONRuntime(); errorJSONRuntime.setErrormessage(e.toString()); errorJSONRuntime.setStacktrace(getStackTrace(e)); ObjectMapper mapper = new ObjectMapper(); - //mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY); - //mapper.setVisibilityChecker(mapper.getVisibilityChecker().with(JsonAutoDetect.Visibility.NONE)); mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String jsonInString = ""; try { jsonInString = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(errorJSONRuntime); } catch (Exception ex) { + logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + ex.getClass().getName() + "]: " + nvl(ex.getMessage())+" "+ getSessionLog(request) + ex.getMessage()),AlarmSeverityEnum.MAJOR); ex.printStackTrace(); } @@ -155,7 +150,6 @@ public class ErrorHandler extends org.onap.portalsdk.analytics.RaptorObject { return result.toString(); } public String processFatalErrorWMenu(HttpServletRequest request, RaptorException e) { - //Log.write("Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage()), 1); logger.error(EELFLoggerDelegate.debugLogger, ("[EXCEPTION ENCOUNTERED IN RAPTOR] Fatal error [" + e.getClass().getName() + "]: " + nvl(e.getMessage())+" "+ getSessionLog(request) + e.getMessage()),AlarmSeverityEnum.MAJOR); if (e instanceof ReportSQLException) { String errorSQL = ((ReportSQLException) e).getReportSQL(); -- cgit 1.2.3-korg