Remove critical code smells for utils classes 70/87370/1
authoreconwar <conor.ward@est.tech>
Thu, 9 May 2019 15:15:46 +0000 (15:15 +0000)
committereconwar <conor.ward@est.tech>
Thu, 9 May 2019 15:15:46 +0000 (15:15 +0000)
Change-Id: I8b4012a055d34a54a58046edef7dc539428832be
Issue-ID: DMAAP-1195
Signed-off-by: econwar <conor.ward@est.tech>
12 files changed:
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java

index d29876f..7700a58 100644 (file)
@@ -84,7 +84,7 @@ public class DB {
                 HTTP_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");\r
                 Class.forName(DB_DRIVER);\r
             } catch (IOException e) {\r
-                intlogger.error("PROV9003 Opening properties: " + e.getMessage());\r
+                intlogger.error("PROV9003 Opening properties: " + e.getMessage(), e);\r
                 System.exit(1);\r
             } catch (ClassNotFoundException e) {\r
                 intlogger.error("PROV9004 cannot find the DB driver: " + e);\r
@@ -115,6 +115,7 @@ public class DB {
                 try {\r
                     connection = queue.remove();\r
                 } catch (NoSuchElementException nseEx) {\r
+                    intlogger.error("PROV9006 No connection on queue: " + nseEx.getMessage(), nseEx);\r
                     int n = 0;\r
                     do {\r
                         // Try up to 3 times to get a connection\r
@@ -194,8 +195,7 @@ public class DB {
                 runInitScript(connection, 1);\r
             }\r
         } catch (SQLException e) {\r
-            intlogger\r
-                .error("PROV9000: The database credentials are not working: " + e.getMessage());\r
+            intlogger.error("PROV9000: The database credentials are not working: " + e.getMessage(), e);\r
             return false;\r
         } finally {\r
             if (connection != null) {\r
@@ -223,7 +223,7 @@ public class DB {
                 rs.close();\r
             }\r
         } catch (SQLException e) {\r
-            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage());\r
+            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage(), e);\r
         }\r
         return tables;\r
     }\r
@@ -264,7 +264,7 @@ public class DB {
             lineReader.close();\r
             strBuilder.setLength(0);\r
         } catch (Exception e) {\r
-            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage());\r
+            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage(), e);\r
             System.exit(1);\r
         }\r
     }\r
index 46cfabe..d5521ba 100644 (file)
@@ -211,7 +211,7 @@ public class DRProvCadiFilter extends CadiFilter {
             }
 
         } catch (Exception e) {
-            intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: ", e.getMessage());
+            intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: " + e.getMessage(), e);
             return false;
         }
         return false;
@@ -241,7 +241,7 @@ public class DRProvCadiFilter extends CadiFilter {
                 intlogger.debug(message);
             }
         } catch (Exception e) {
-            intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: ", e.getMessage());
+            intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: " + e.getMessage(), e);
             return false;
         }
         return false;
index af8bd6d..a593c8a 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.IOException;\r
@@ -97,6 +99,7 @@ public class DRRouteCLI {
     public static final String ENV_VAR = "PROVSRVR";\r
     public static final String PROMPT = "dr-route> ";\r
     public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";\r
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
 \r
     private final String server;\r
     private int width = 120;        // screen width (for list)\r
@@ -130,12 +133,13 @@ public class DRRouteCLI {
             try {\r
                 trustStore.load(instream, truststore_pw.toCharArray());\r
             } catch (Exception x) {\r
-                System.err.println("Problem reading truststore: " + x);\r
+                intlogger.error("Problem reading truststore: " + x.getMessage(), x);\r
                 throw x;\r
             } finally {\r
                 try {\r
                     instream.close();\r
                 } catch (Exception ignore) {\r
+                    intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);\r
                 }\r
             }\r
         }\r
@@ -397,6 +401,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
+            intlogger.error("PROV0006 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
@@ -416,7 +421,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
-            System.err.println(e);\r
+            intlogger.error("PROV0005 doGet: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
@@ -438,6 +443,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
+            intlogger.error("PROV0009 doPost: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
index 3aa3bd2..d9f36de 100644 (file)
@@ -32,7 +32,7 @@ public class HttpServletUtils {
         try {
             response.sendError(errorCode, message);
         } catch (IOException ioe) {
-            intlogger.error("IOException" + ioe.getMessage());
+            intlogger.error("IOException" + ioe.getMessage(), ioe);
         }
     }
 }
index 915aa61..2d4e22b 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.util.Collection;\r
@@ -35,6 +37,8 @@ import java.util.Collection;
  * @version $Id: JSONUtilities.java,v 1.1 2013/04/26 21:00:26 eby Exp $\r
  */\r
 public class JSONUtilities {\r
+\r
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     /**\r
      * Does the String <i>v</i> represent a valid Internet address (with or without a\r
      * mask length appended).\r
@@ -56,6 +60,7 @@ public class JSONUtilities {
             }\r
             return true;\r
         } catch (UnknownHostException e) {\r
+            intlogger.error("PROV0001: " + e.getMessage(), e);\r
             return false;\r
         }\r
     }\r
index 1518859..f7e0874 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.dmaap.datarouter.provisioning.utils;
  * *
  ******************************************************************************/
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -104,6 +106,8 @@ public class LOGJSONObject {
      */
     private static Map<String, Object> keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
 
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+
     /**
      * JSONObject.NULL is equivalent to the value that JavaScript calls null,
      * whilst Java's null is equivalent to the value that JavaScript calls
@@ -202,7 +206,7 @@ public class LOGJSONObject {
      * Construct an empty JSONObject.
      */
     public LOGJSONObject() {
-        this.map = new LinkedHashMap<String, Object>();
+        this.map = new LinkedHashMap<>();
     }
 
 
@@ -213,8 +217,6 @@ public class LOGJSONObject {
      *
      * @param jo    A JSONObject.
      * @param names An array of strings.
-     * @throws JSONException
-     * @throws JSONException If a value is a non-finite number or if a name is duplicated.
      */
     public LOGJSONObject(LOGJSONObject jo, String[] names) {
         this();
@@ -222,6 +224,7 @@ public class LOGJSONObject {
             try {
                 this.putOnce(names[i], jo.opt(names[i]));
             } catch (Exception ignore) {
+                intlogger.error("PROV0001 LOGJSONObject: " + ignore.getMessage(), ignore);
             }
         }
     }
@@ -234,7 +237,7 @@ public class LOGJSONObject {
      * @throws JSONException If there is a syntax error in the source string
      *                       or a duplicated key.
      */
-    public LOGJSONObject(JSONTokener x) throws JSONException {
+    public LOGJSONObject(JSONTokener x) {
         this();
         char c;
         String key;
@@ -555,15 +558,15 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or
      *                       if the value is not a Number object and cannot be converted to a number.
      */
-    public double getDouble(String key) throws JSONException {
+    public double getDouble(String key) {
         Object object = this.get(key);
         try {
             return object instanceof Number
                     ? ((Number) object).doubleValue()
                     : Double.parseDouble((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not a number.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not a number.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
         }
     }
 
@@ -576,15 +579,15 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or if the value cannot
      *                       be converted to an integer.
      */
-    public int getInt(String key) throws JSONException {
+    public int getInt(String key) {
         Object object = this.get(key);
         try {
             return object instanceof Number
                     ? ((Number) object).intValue()
                     : Integer.parseInt((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not an int.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not an int.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
         }
     }
 
@@ -640,8 +643,8 @@ public class LOGJSONObject {
                     ? ((Number) object).longValue()
                     : Long.parseLong((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not a long.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not a long.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
         }
     }
 
@@ -697,7 +700,7 @@ public class LOGJSONObject {
      * @return A string which is the value.
      * @throws JSONException if there is no string value for the key.
      */
-    public String getString(String key) throws JSONException {
+    public String getString(String key) {
         Object object = this.get(key);
         if (object instanceof String) {
             return (String) object;
@@ -728,7 +731,7 @@ public class LOGJSONObject {
      * @throws JSONException If there is already a property with this name
      *                       that is not an Integer, Long, Double, or Float.
      */
-    public LOGJSONObject increment(String key) throws JSONException {
+    public LOGJSONObject increment(String key) {
         Object value = this.opt(key);
         if (value == null) {
             this.put(key, 1);
@@ -873,6 +876,7 @@ public class LOGJSONObject {
         try {
             return this.getBoolean(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -906,6 +910,7 @@ public class LOGJSONObject {
         try {
             return this.getDouble(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -939,6 +944,7 @@ public class LOGJSONObject {
         try {
             return this.getInt(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -1075,6 +1081,7 @@ public class LOGJSONObject {
                     }
                 }
             } catch (Exception ignore) {
+                intlogger.trace("populateMap: " + ignore.getMessage(), ignore);
             }
         }
     }
@@ -1256,8 +1263,8 @@ public class LOGJSONObject {
         synchronized (sw.getBuffer()) {
             try {
                 return quote(string, sw).toString();
-            } catch (IOException ignored) {
-                // will never happen - we are writing to a string writer
+            } catch (IOException e) {
+                intlogger.trace("Ignore Exception message: ", e);
                 return "";
             }
         }
@@ -1380,7 +1387,8 @@ public class LOGJSONObject {
                         return myLong;
                     }
                 }
-            } catch (Exception ignore) {
+            } catch (Exception e) {
+                intlogger.trace("Ignore Exception message: ", e);
             }
         }
         return string;
@@ -1393,7 +1401,7 @@ public class LOGJSONObject {
      * @param o The object to test.
      * @throws JSONException If o is a non-finite number.
      */
-    public static void testValidity(Object o) throws JSONException {
+    public static void testValidity(Object o) {
         if (o != null) {
             if (o instanceof Double) {
                 if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
@@ -1446,6 +1454,7 @@ public class LOGJSONObject {
         try {
             return this.toString(0);
         } catch (Exception e) {
+            intlogger.trace("Exception: ", e);
             return "";
         }
     }
@@ -1579,6 +1588,7 @@ public class LOGJSONObject {
             }
             return new LOGJSONObject(object);
         } catch (Exception exception) {
+            intlogger.trace("Exception: ", exception);
             return null;
         }
     }
index 8223188..3ba1a15 100644 (file)
@@ -416,7 +416,7 @@ public class LogfileLoader extends Thread {
                         }\r
                     } catch (SQLException e) {\r
                         logger.warn("PROV8003 Invalid value in record: " + line);\r
-                        logger.debug(e.toString());\r
+                        logger.debug(e.toString(), e);\r
                     } catch (NumberFormatException e) {\r
                         logger.warn("PROV8004 Invalid number in record: " + line);\r
                         logger.debug(e.toString());\r
@@ -425,7 +425,7 @@ public class LogfileLoader extends Thread {
                         logger.debug(e.toString());\r
                     } catch (Exception e) {\r
                         logger.warn("PROV8006 Invalid pattern in record: " + line);\r
-                        logger.debug(e.toString());\r
+                        logger.debug(e.toString(), e);\r
                     }\r
                     total++;\r
                 }\r
index f3e84b4..8c67e71 100644 (file)
@@ -51,7 +51,7 @@ public class PurgeLogDirTask extends TimerTask {
         logdir = p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");\r
         String s = p.getProperty("org.onap.dmaap.datarouter.provserver.logretention", "30");\r
 \r
-        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");;\r
+        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");\r
 \r
         long n = 30;\r
         try {\r
@@ -75,7 +75,7 @@ public class PurgeLogDirTask extends TimerTask {
                 }\r
             }\r
         } catch (Exception e) {\r
-            utilsLogger.error("Exception: " + e.getMessage());\r
+            utilsLogger.error("Exception: " + e.getMessage(), e);\r
         }\r
     }\r
 }\r
index c9fb5a1..5c1fd56 100644 (file)
@@ -138,7 +138,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
                     }\r
                 }\r
             } catch (ClassNotFoundException e) {\r
-                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.");\r
+                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.", e);\r
             }\r
         }\r
         logger.info("ThrottleFilter is DISABLED for /publish requests.");\r
@@ -275,7 +275,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
                     t = times.get(0);\r
                 }\r
             } catch (IndexOutOfBoundsException e) {\r
-                // ignore\r
+                logger.trace("Exception: " + e.getMessage(), e);\r
             }\r
             return times.size();\r
         }\r
index 0c6afdd..ffed1a1 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.util.Arrays;\r
@@ -37,7 +39,7 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet;
  * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $\r
  */\r
 public class URLUtilities {\r
-\r
+    private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");\r
     /**\r
      * Generate the URL used to access a feed.\r
      *\r
@@ -134,6 +136,7 @@ public class URLUtilities {
                 this_pod = InetAddress.getLocalHost().getHostName();\r
                 System.out.println("this_pod: " + this_pod);\r
             } catch (UnknownHostException e) {\r
+                utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);\r
                 this_pod = "";\r
             }\r
             System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));\r
index 315207e..e9a0bf9 100644 (file)
@@ -63,7 +63,7 @@ public class SampleSubscriberServlet extends HttpServlet {
     try {
       Files.createDirectory(Paths.get(outputDirectory));
     } catch (IOException e) {
-      logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage());
+      logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage(), e);
     }
     basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes());
   }
index 329c06a..f05ca5d 100644 (file)
@@ -45,7 +45,7 @@ public class SubscriberProps {
             try {
                 instance = new SubscriberProps(propsPath);
             } catch (IOException ioe) {
-                subLogger.error("IO Exception: " + ioe.getMessage());
+                subLogger.error("IO Exception: " + ioe.getMessage(), ioe);
             }
         }
         return instance;