Remove critical code smells for utils classes

Change-Id: I8b4012a055d34a54a58046edef7dc539428832be
Issue-ID: DMAAP-1195
Signed-off-by: econwar <conor.ward@est.tech>
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
index d29876f..7700a58 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
@@ -84,7 +84,7 @@
                 HTTP_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");

                 Class.forName(DB_DRIVER);

             } catch (IOException e) {

-                intlogger.error("PROV9003 Opening properties: " + e.getMessage());

+                intlogger.error("PROV9003 Opening properties: " + e.getMessage(), e);

                 System.exit(1);

             } catch (ClassNotFoundException e) {

                 intlogger.error("PROV9004 cannot find the DB driver: " + e);

@@ -115,6 +115,7 @@
                 try {

                     connection = queue.remove();

                 } catch (NoSuchElementException nseEx) {

+                    intlogger.error("PROV9006 No connection on queue: " + nseEx.getMessage(), nseEx);

                     int n = 0;

                     do {

                         // Try up to 3 times to get a connection

@@ -194,8 +195,7 @@
                 runInitScript(connection, 1);

             }

         } catch (SQLException e) {

-            intlogger

-                .error("PROV9000: The database credentials are not working: " + e.getMessage());

+            intlogger.error("PROV9000: The database credentials are not working: " + e.getMessage(), e);

             return false;

         } finally {

             if (connection != null) {

@@ -223,7 +223,7 @@
                 rs.close();

             }

         } catch (SQLException e) {

-            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage());

+            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage(), e);

         }

         return tables;

     }

@@ -264,7 +264,7 @@
             lineReader.close();

             strBuilder.setLength(0);

         } catch (Exception e) {

-            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage());

+            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage(), e);

             System.exit(1);

         }

     }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
index 46cfabe..d5521ba 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
@@ -211,7 +211,7 @@
             }
 
         } 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 @@
                 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;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
index af8bd6d..a593c8a 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
@@ -24,6 +24,8 @@
 

 package org.onap.dmaap.datarouter.provisioning.utils;

 

+import com.att.eelf.configuration.EELFLogger;

+import com.att.eelf.configuration.EELFManager;

 import java.io.File;

 import java.io.FileInputStream;

 import java.io.IOException;

@@ -97,6 +99,7 @@
     public static final String ENV_VAR = "PROVSRVR";

     public static final String PROMPT = "dr-route> ";

     public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";

+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");

 

     private final String server;

     private int width = 120;        // screen width (for list)

@@ -130,12 +133,13 @@
             try {

                 trustStore.load(instream, truststore_pw.toCharArray());

             } catch (Exception x) {

-                System.err.println("Problem reading truststore: " + x);

+                intlogger.error("Problem reading truststore: " + x.getMessage(), x);

                 throw x;

             } finally {

                 try {

                     instream.close();

                 } catch (Exception ignore) {

+                    intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);

                 }

             }

         }

@@ -397,6 +401,7 @@
                 printErrorText(entity);

             }

         } catch (Exception e) {

+            intlogger.error("PROV0006 doDelete: " + e.getMessage(), e);

         } finally {

             meth.releaseConnection();

         }

@@ -416,7 +421,7 @@
                 printErrorText(entity);

             }

         } catch (Exception e) {

-            System.err.println(e);

+            intlogger.error("PROV0005 doGet: " + e.getMessage(), e);

         } finally {

             meth.releaseConnection();

         }

@@ -438,6 +443,7 @@
                 printErrorText(entity);

             }

         } catch (Exception e) {

+            intlogger.error("PROV0009 doPost: " + e.getMessage(), e);

         } finally {

             meth.releaseConnection();

         }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
index 3aa3bd2..d9f36de 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
@@ -32,7 +32,7 @@
         try {
             response.sendError(errorCode, message);
         } catch (IOException ioe) {
-            intlogger.error("IOException" + ioe.getMessage());
+            intlogger.error("IOException" + ioe.getMessage(), ioe);
         }
     }
 }
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
index 915aa61..2d4e22b 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
@@ -24,6 +24,8 @@
 

 package org.onap.dmaap.datarouter.provisioning.utils;

 

+import com.att.eelf.configuration.EELFLogger;

+import com.att.eelf.configuration.EELFManager;

 import java.net.InetAddress;

 import java.net.UnknownHostException;

 import java.util.Collection;

@@ -35,6 +37,8 @@
  * @version $Id: JSONUtilities.java,v 1.1 2013/04/26 21:00:26 eby Exp $

  */

 public class JSONUtilities {

+

+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");

     /**

      * Does the String <i>v</i> represent a valid Internet address (with or without a

      * mask length appended).

@@ -56,6 +60,7 @@
             }

             return true;

         } catch (UnknownHostException e) {

+            intlogger.error("PROV0001: " + e.getMessage(), e);

             return false;

         }

     }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
index 1518859..f7e0874 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
@@ -23,6 +23,8 @@
  * *
  ******************************************************************************/
 
+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 @@
      */
     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 @@
      * Construct an empty JSONObject.
      */
     public LOGJSONObject() {
-        this.map = new LinkedHashMap<String, Object>();
+        this.map = new LinkedHashMap<>();
     }
 
 
@@ -213,8 +217,6 @@
      *
      * @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 @@
             try {
                 this.putOnce(names[i], jo.opt(names[i]));
             } catch (Exception ignore) {
+                intlogger.error("PROV0001 LOGJSONObject: " + ignore.getMessage(), ignore);
             }
         }
     }
@@ -234,7 +237,7 @@
      * @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 @@
      * @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 @@
      * @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 @@
                     ? ((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 @@
      * @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 @@
      * @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 @@
         try {
             return this.getBoolean(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -906,6 +910,7 @@
         try {
             return this.getDouble(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -939,6 +944,7 @@
         try {
             return this.getInt(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
@@ -1075,6 +1081,7 @@
                     }
                 }
             } catch (Exception ignore) {
+                intlogger.trace("populateMap: " + ignore.getMessage(), ignore);
             }
         }
     }
@@ -1256,8 +1263,8 @@
         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 @@
                         return myLong;
                     }
                 }
-            } catch (Exception ignore) {
+            } catch (Exception e) {
+                intlogger.trace("Ignore Exception message: ", e);
             }
         }
         return string;
@@ -1393,7 +1401,7 @@
      * @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 @@
         try {
             return this.toString(0);
         } catch (Exception e) {
+            intlogger.trace("Exception: ", e);
             return "";
         }
     }
@@ -1579,6 +1588,7 @@
             }
             return new LOGJSONObject(object);
         } catch (Exception exception) {
+            intlogger.trace("Exception: ", exception);
             return null;
         }
     }
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
index 8223188..3ba1a15 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
@@ -416,7 +416,7 @@
                         }

                     } catch (SQLException e) {

                         logger.warn("PROV8003 Invalid value in record: " + line);

-                        logger.debug(e.toString());

+                        logger.debug(e.toString(), e);

                     } catch (NumberFormatException e) {

                         logger.warn("PROV8004 Invalid number in record: " + line);

                         logger.debug(e.toString());

@@ -425,7 +425,7 @@
                         logger.debug(e.toString());

                     } catch (Exception e) {

                         logger.warn("PROV8006 Invalid pattern in record: " + line);

-                        logger.debug(e.toString());

+                        logger.debug(e.toString(), e);

                     }

                     total++;

                 }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
index f3e84b4..8c67e71 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
@@ -51,7 +51,7 @@
         logdir = p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");

         String s = p.getProperty("org.onap.dmaap.datarouter.provserver.logretention", "30");

 

-        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");;

+        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");

 

         long n = 30;

         try {

@@ -75,7 +75,7 @@
                 }

             }

         } catch (Exception e) {

-            utilsLogger.error("Exception: " + e.getMessage());

+            utilsLogger.error("Exception: " + e.getMessage(), e);

         }

     }

 }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
index c9fb5a1..5c1fd56 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
@@ -138,7 +138,7 @@
                     }

                 }

             } catch (ClassNotFoundException e) {

-                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.");

+                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.", e);

             }

         }

         logger.info("ThrottleFilter is DISABLED for /publish requests.");

@@ -275,7 +275,7 @@
                     t = times.get(0);

                 }

             } catch (IndexOutOfBoundsException e) {

-                // ignore

+                logger.trace("Exception: " + e.getMessage(), e);

             }

             return times.size();

         }

diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
index 0c6afdd..ffed1a1 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
@@ -24,6 +24,8 @@
 

 package org.onap.dmaap.datarouter.provisioning.utils;

 

+import com.att.eelf.configuration.EELFLogger;

+import com.att.eelf.configuration.EELFManager;

 import java.net.InetAddress;

 import java.net.UnknownHostException;

 import java.util.Arrays;

@@ -37,7 +39,7 @@
  * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $

  */

 public class URLUtilities {

-

+    private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");

     /**

      * Generate the URL used to access a feed.

      *

@@ -134,6 +136,7 @@
                 this_pod = InetAddress.getLocalHost().getHostName();

                 System.out.println("this_pod: " + this_pod);

             } catch (UnknownHostException e) {

+                utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);

                 this_pod = "";

             }

             System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));

diff --git a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
index 315207e..e9a0bf9 100644
--- a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
+++ b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
@@ -63,7 +63,7 @@
     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());
   }
diff --git a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java
index 329c06a..f05ca5d 100644
--- a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java
+++ b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java
@@ -45,7 +45,7 @@
             try {
                 instance = new SubscriberProps(propsPath);
             } catch (IOException ioe) {
-                subLogger.error("IO Exception: " + ioe.getMessage());
+                subLogger.error("IO Exception: " + ioe.getMessage(), ioe);
             }
         }
         return instance;