DMAAP-1714 - DR Making TLS Configurable
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / URLUtilities.java
index 2e00002..988b576 100644 (file)
@@ -28,8 +28,8 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
-\r
 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
+import org.onap.dmaap.datarouter.provisioning.ProvRunner;\r
 \r
 /**\r
  * Utility functions used to generate the different URLs used by the Data Router.\r
@@ -39,9 +39,7 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet;
  */\r
 public class URLUtilities {\r
 \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
@@ -54,7 +52,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedURL(int feedid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/feed/" + feedid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feed/" + feedid;\r
     }\r
 \r
     /**\r
@@ -64,7 +62,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePublishURL(int feedid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/publish/" + feedid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/publish/" + feedid;\r
     }\r
 \r
     /**\r
@@ -74,7 +72,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscribeURL(int feedid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/subscribe/" + feedid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subscribe/" + feedid;\r
     }\r
 \r
     /**\r
@@ -84,7 +82,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedLogURL(int feedid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/feedlog/" + feedid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feedlog/" + feedid;\r
     }\r
 \r
     /**\r
@@ -94,7 +92,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscriptionURL(int subid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/subs/" + subid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subs/" + subid;\r
     }\r
 \r
     /**\r
@@ -104,7 +102,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubLogURL(int subid) {\r
-        return HTTPS + BaseServlet.getProvName() + "/sublog/" + subid;\r
+        return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/sublog/" + subid;\r
     }\r
 \r
     /**\r
@@ -113,7 +111,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePeerProvURL() {\r
-        return HTTPS + getPeerPodName() + "/internal/prov";\r
+        return getUrlSecurityOption() + getPeerPodName() + getAppropriateUrlPort() + "/internal/prov";\r
     }\r
 \r
     /**\r
@@ -128,7 +126,7 @@ public class URLUtilities {
             return "";\r
         }\r
 \r
-        return HTTPS + peerPodUrl + "/internal/drlogs/";\r
+        return getUrlSecurityOption() + peerPodUrl + getAppropriateUrlPort() + "/internal/drlogs/";\r
     }\r
 \r
     /**\r
@@ -154,4 +152,21 @@ public class URLUtilities {
         return otherPod;\r
     }\r
 \r
+    public static String getUrlSecurityOption() {\r
+        if (Boolean.parseBoolean(ProvRunner.getProvProperties()\r
+            .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true"))) {\r
+            return "https://";\r
+        }\r
+        return "http://";\r
+    }\r
+\r
+    private static String getAppropriateUrlPort() {\r
+        if (Boolean.parseBoolean(ProvRunner.getProvProperties()\r
+            .getProperty("org.onap.dmaap.datarouter.provserver.tlsenabled", "true")))\r
+                return "";\r
+\r
+        return ":" + ProvRunner.getProvProperties()\r
+            .getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080");\r
+\r
+    }\r
 }\r