Fixed Sonar issues 41/62141/1
authorAmaresh Kumar <kamaresh@in.ibm.com>
Thu, 23 Aug 2018 14:44:27 +0000 (20:14 +0530)
committerAmaresh Kumar <kamaresh@in.ibm.com>
Thu, 23 Aug 2018 14:44:37 +0000 (20:14 +0530)
Fixed Sonar issues in 3 files.

Issue-ID: DMAAP-636
Change-Id: I2d53361e61f838ff5ba379a21bdfcedbd3fc5df3
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java

index 8aaa577..006dc88 100644 (file)
@@ -39,7 +39,7 @@ public class NodeMain {
     private NodeMain() {
     }
 
-    private static Logger LOGGER = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
+    private static Logger nodeMainLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
 
     private static class WaitForConfig implements Runnable {
 
@@ -56,15 +56,15 @@ public class NodeMain {
         synchronized void waitForConfig() {
             localNodeConfigManager.registerConfigTask(this);
             while (!localNodeConfigManager.isConfigured()) {
-                LOGGER.info("NODE0003 Waiting for Node Configuration");
+                nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
                 try {
                     wait();
-                } catch (Exception e) {
-                    LOGGER.debug("NodeMain: waitForConfig exception. Exception Message:- " +e.getMessage());
+                } catch (Exception exception) {
+                    nodeMainLogger.debug("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(), exception);
                 }
             }
             localNodeConfigManager.deregisterConfigTask(this);
-            LOGGER.info("NODE0004 Node Configuration Data Received");
+            nodeMainLogger.info("NODE0004 Node Configuration Data Received");
         }
     }
 
@@ -85,10 +85,10 @@ public class NodeMain {
      * property.  By default, it is "etc/node.properties".
      */
     public static void main(String[] args) throws Exception {
-        LOGGER.info("NODE0001 Data Router Node Starting");
+        nodeMainLogger.info("NODE0001 Data Router Node Starting");
         IsFrom.setDNSCache();
         nodeConfigManager = NodeConfigManager.getInstance();
-        LOGGER.info("NODE0002 I am " + nodeConfigManager.getMyName());
+        nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName());
         (new WaitForConfig(nodeConfigManager)).waitForConfig();
         delivery = new Delivery(nodeConfigManager);
         Server server = new Server();
@@ -111,7 +111,7 @@ public class NodeMain {
             sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
             /* Skip SSLv3 Fixes */
             sslContextFactory.addExcludeProtocols("SSLv3");
-            LOGGER.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
+            nodeMainLogger.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
             /* End of SSLv3 Fixes */
 
             HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
@@ -136,7 +136,7 @@ public class NodeMain {
         ctxt.setContextPath("/");
         server.setHandler(ctxt);
         ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
-        LOGGER.info("NODE0005 Data Router Node Activating Service");
+        nodeMainLogger.info("NODE0005 Data Router Node Activating Service");
         server.start();
         server.join();
     }
index ea2ce34..230afd4 100644 (file)
@@ -47,13 +47,13 @@ import com.att.eelf.configuration.EELFManager;
  * Utility functions for the data router node
  */
 public class NodeUtils {
-    private static EELFLogger EELFLOGGER = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
-    private static Logger LOGGER = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
-    private static SimpleDateFormat LOGDATE;
+    private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
+    private static Logger nodeUtilsLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
+    private static SimpleDateFormat logDate;
 
     static {
-        LOGDATE = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
-        LOGDATE.setTimeZone(TimeZone.getTimeZone("GMT"));
+        logDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+        logDate.setTimeZone(TimeZone.getTimeZone("GMT"));
     }
 
     private NodeUtils() {
@@ -95,8 +95,8 @@ public class NodeUtils {
             md.update(node.getBytes());
             md.update(key.getBytes());
             return (getAuthHdr(node, base64Encode(md.digest())));
-        } catch (Exception e) {
-            LOGGER.error("Exception in generating Credentials for given node name:= " + e.getMessage());
+        } catch (Exception exception) {
+            nodeUtilsLogger.error("Exception in generating Credentials for given node name:= " + exception.toString(), exception);
             return (null);
         }
     }
@@ -117,12 +117,12 @@ public class NodeUtils {
                 ks.load(fileInputStream, kspass.toCharArray());
             }
         } catch(IOException ioException) {
-            LOGGER.error("Exception occurred while opening FileInputStream",ioException);
+            nodeUtilsLogger.error("Exception occurred while opening FileInputStream",ioException);
             return (null);
         } catch (Exception e) {
             setIpAndFqdnForEelf("getCanonicalName");
-            EELFLOGGER.error(EelfMsgs.MESSAGE_KEYSTORE_LOAD_ERROR, ksfile, e.toString());
-            LOGGER.error("NODE0401 Error loading my keystore file + " + ksfile + " " + e.toString(), e);
+            eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_LOAD_ERROR, ksfile, e.toString());
+            nodeUtilsLogger.error("NODE0401 Error loading my keystore file + " + ksfile + " " + e.toString(), e);
             return (null);
         }
         return (getCanonicalName(ks));
@@ -157,7 +157,7 @@ public class NodeUtils {
                 }
             }
         } catch (Exception e) {
-            LOGGER.error("NODE0402 Error extracting my name from my keystore file " + e.toString(), e);
+            nodeUtilsLogger.error("NODE0402 Error extracting my name from my keystore file " + e.toString(), e);
         }
         return (null);
     }
@@ -171,8 +171,8 @@ public class NodeUtils {
     public static byte[] getInetAddress(String ip) {
         try {
             return (InetAddress.getByName(ip).getAddress());
-        } catch (Exception e) {
-            LOGGER.error("Exception in generating byte array for given IP address := " + e.getMessage());
+        } catch (Exception exception) {
+            nodeUtilsLogger.error("Exception in generating byte array for given IP address := " + exception.toString(), exception);
         }
         return (null);
     }
@@ -232,7 +232,7 @@ public class NodeUtils {
      * Format a logging timestamp as yyyy-mm-ddThh:mm:ss.mmmZ
      */
     public static synchronized String logts(Date when) {
-        return (LOGDATE.format(when));
+        return (logDate.format(when));
     }
 
     /* Method prints method name, server FQDN and IP Address of the machine in EELF logs
@@ -245,8 +245,8 @@ public class NodeUtils {
         try {
             MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
             MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
-        } catch (Exception e) {
-            LOGGER.error("Exception in generating byte array for given IP address := " + e.getMessage());
+        } catch (Exception exception) {
+            nodeUtilsLogger.error("Exception in generating byte array for given IP address := " + exception.toString(), exception);
         }
 
     }
index 48a2392..8614a6e 100644 (file)
@@ -39,6 +39,7 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import org.apache.log4j.Logger;\r
 import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;\r
 import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;\r
 import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;\r
@@ -63,17 +64,16 @@ import com.att.eelf.configuration.EELFManager;
 public class LogServlet extends BaseServlet {\r
     //Adding EELF Logger Rally:US664892\r
     private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.LogServlet");\r
-\r
     private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);\r
     private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
     private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
 \r
-    private boolean isfeedlog;\r
+    private static  boolean isfeedlog;\r
 \r
     public abstract class RowHandler {\r
         private final ServletOutputStream out;\r
         private final String[] fields;\r
-        public boolean firstrow;\r
+        private boolean firstrow;\r
 \r
         public RowHandler(ServletOutputStream out, String fieldparam, boolean b) {\r
             this.out = out;\r
@@ -98,8 +98,8 @@ public class LogServlet extends BaseServlet {
                 t += jo.toString();\r
                 out.print(t);\r
                 firstrow = false;\r
-            } catch (Exception e) {\r
-                // ignore\r
+            } catch (Exception exception) {\r
+                intlogger.info("Failed to handle row. Exception = " + exception.getMessage(),exception);\r
             }\r
         }\r
         public abstract LOGJSONable buildJSONable(ResultSet rs) throws SQLException;\r
@@ -345,13 +345,15 @@ public class LogServlet extends BaseServlet {
             SimpleDateFormat sdf = new SimpleDateFormat(fmt);\r
             Date d = sdf.parse(s);\r
             return d.getTime();\r
-        } catch (ParseException e) {\r
+        } catch (ParseException parseException) {\r
+            intlogger.error("Exception in getting Time :- "+parseException.getMessage(),parseException);\r
         }\r
         try {\r
             // Also allow a long (in ms); useful for testing\r
             long n = Long.parseLong(s);\r
             return n;\r
-        } catch (NumberFormatException e) {\r
+        } catch (NumberFormatException numberFormatException) {\r
+            intlogger.error("Exception in getting Time :- "+numberFormatException.getMessage(),numberFormatException);\r
         }\r
         intlogger.info("Error parsing time="+s);\r
         return -1;\r
@@ -422,8 +424,8 @@ public class LogServlet extends BaseServlet {
             }\r
             rs.close();\r
             stmt.close();\r
-        } catch (SQLException e) {\r
-            e.printStackTrace();\r
+        } catch (SQLException sqlException) {\r
+            intlogger.info("Failed to get Records. Exception = " +sqlException.getMessage(),sqlException);\r
         } finally {\r
             if (conn != null)\r
                 db.release(conn);\r