More unit test coverage and code cleanup
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / URLUtilities.java
index ffed1a1..5813024 100644 (file)
@@ -28,7 +28,6 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
-import java.util.Arrays;\r
 \r
 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
 \r
@@ -39,7 +38,14 @@ 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
+    private static final String HTTPS = "https://";\r
+    private static String otherPod;\r
+\r
+    private URLUtilities() {\r
+    }\r
+\r
     /**\r
      * Generate the URL used to access a feed.\r
      *\r
@@ -47,7 +53,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/feed/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/feed/" + feedid;\r
     }\r
 \r
     /**\r
@@ -57,7 +63,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePublishURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/publish/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/publish/" + feedid;\r
     }\r
 \r
     /**\r
@@ -67,7 +73,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscribeURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/subscribe/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/subscribe/" + feedid;\r
     }\r
 \r
     /**\r
@@ -77,7 +83,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedLogURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/feedlog/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/feedlog/" + feedid;\r
     }\r
 \r
     /**\r
@@ -87,7 +93,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscriptionURL(int subid) {\r
-        return "https://" + BaseServlet.getProvName() + "/subs/" + subid;\r
+        return HTTPS + BaseServlet.getProvName() + "/subs/" + subid;\r
     }\r
 \r
     /**\r
@@ -97,7 +103,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubLogURL(int subid) {\r
-        return "https://" + BaseServlet.getProvName() + "/sublog/" + subid;\r
+        return HTTPS + BaseServlet.getProvName() + "/sublog/" + subid;\r
     }\r
 \r
     /**\r
@@ -106,7 +112,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePeerProvURL() {\r
-        return "https://" + getPeerPodName() + "/internal/prov";\r
+        return HTTPS + getPeerPodName() + "/internal/prov";\r
     }\r
 \r
     /**\r
@@ -117,11 +123,11 @@ public class URLUtilities {
     public static String generatePeerLogsURL() {\r
         //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.\r
         String peerPodUrl = getPeerPodName();\r
-        if (peerPodUrl == null || peerPodUrl.equals("")) {\r
+        if (peerPodUrl == null || "".equals(peerPodUrl)) {\r
             return "";\r
         }\r
 \r
-        return "https://" + peerPodUrl + "/internal/drlogs/";\r
+        return HTTPS + peerPodUrl + "/internal/drlogs/";\r
     }\r
 \r
     /**\r
@@ -130,24 +136,21 @@ public class URLUtilities {
      * @return the name\r
      */\r
     public static String getPeerPodName() {\r
-        if (other_pod == null) {\r
-            String this_pod = "";\r
+        if (otherPod == null) {\r
+            String thisPod;\r
             try {\r
-                this_pod = InetAddress.getLocalHost().getHostName();\r
-                System.out.println("this_pod: " + this_pod);\r
+                thisPod = InetAddress.getLocalHost().getHostName();\r
             } catch (UnknownHostException e) {\r
                 utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);\r
-                this_pod = "";\r
+                thisPod = "";\r
             }\r
-            System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));\r
             for (String pod : BaseServlet.getPods()) {\r
-                if (!pod.equals(this_pod)) {\r
-                    other_pod = pod;\r
+                if (!pod.equals(thisPod)) {\r
+                    otherPod = pod;\r
                 }\r
             }\r
         }\r
-        return other_pod;\r
+        return otherPod;\r
     }\r
 \r
-    private static String other_pod;\r
 }\r