Fix sonar issues in ErrorHandler 89/85789/1
authorburdziak <olaf.burdziakowski@nokia.com>
Fri, 19 Apr 2019 10:02:07 +0000 (12:02 +0200)
committerburdziak <olaf.burdziakowski@nokia.com>
Fri, 19 Apr 2019 10:02:07 +0000 (12:02 +0200)
Change-Id: I7824b6bb52b4e3f8b205cdfa3a56281bf5423b50
Issue-ID: PORTAL-523
Signed-off-by: burdziak <olaf.burdziakowski@nokia.com>
ecomp-sdk/epsdk-analytics/src/main/java/org/onap/portalsdk/analytics/controller/ErrorHandler.java

index 403c6b6..1a31e60 100644 (file)
@@ -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();