X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Futils%2FURLUtilities.java;h=89403488eb84c0bcce759a2fe11619bbbd8e58fc;hb=bda6aeaa60607ab4fe5af508156019d7bd5c0ce4;hp=c3661ba0ecec15096c5444cf17a4f2cfbf6418eb;hpb=4261823d84c2b911b68cdf4cb4dc3be429ebe285;p=dmaap%2Fdatarouter.git 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 c3661ba0..89403488 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,11 +24,12 @@ 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; - import org.onap.dmaap.datarouter.provisioning.BaseServlet; +import org.onap.dmaap.datarouter.provisioning.ProvRunner; /** * Utility functions used to generate the different URLs used by the Data Router. @@ -37,6 +38,13 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet; * @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"); + private static String otherPod; + + private URLUtilities() { + } + /** * Generate the URL used to access a feed. * @@ -44,7 +52,7 @@ public class URLUtilities { * @return the URL */ public static String generateFeedURL(int feedid) { - return "https://" + BaseServlet.prov_name + "/feed/" + feedid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feed/" + feedid; } /** @@ -54,7 +62,7 @@ public class URLUtilities { * @return the URL */ public static String generatePublishURL(int feedid) { - return "https://" + BaseServlet.prov_name + "/publish/" + feedid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/publish/" + feedid; } /** @@ -64,7 +72,7 @@ public class URLUtilities { * @return the URL */ public static String generateSubscribeURL(int feedid) { - return "https://" + BaseServlet.prov_name + "/subscribe/" + feedid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subscribe/" + feedid; } /** @@ -74,7 +82,7 @@ public class URLUtilities { * @return the URL */ public static String generateFeedLogURL(int feedid) { - return "https://" + BaseServlet.prov_name + "/feedlog/" + feedid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feedlog/" + feedid; } /** @@ -84,7 +92,7 @@ public class URLUtilities { * @return the URL */ public static String generateSubscriptionURL(int subid) { - return "https://" + BaseServlet.prov_name + "/subs/" + subid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subs/" + subid; } /** @@ -94,7 +102,7 @@ public class URLUtilities { * @return the URL */ public static String generateSubLogURL(int subid) { - return "https://" + BaseServlet.prov_name + "/sublog/" + subid; + return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/sublog/" + subid; } /** @@ -103,7 +111,7 @@ public class URLUtilities { * @return the URL */ public static String generatePeerProvURL() { - return "https://" + getPeerPodName() + "/internal/prov"; + return getUrlSecurityOption() + getPeerPodName() + getAppropriateUrlPort() + "/internal/prov"; } /** @@ -114,11 +122,11 @@ public class URLUtilities { public static String generatePeerLogsURL() { //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs. String peerPodUrl = getPeerPodName(); - if (peerPodUrl.equals("") || peerPodUrl.equals(null)) { + if (peerPodUrl == null || "".equals(peerPodUrl)) { return ""; } - return "https://" + peerPodUrl + "/internal/drlogs/"; + return getUrlSecurityOption() + peerPodUrl + getAppropriateUrlPort() + "/internal/drlogs/"; } /** @@ -127,22 +135,35 @@ public class URLUtilities { * @return the name */ public static String getPeerPodName() { - if (other_pod == null) { - String this_pod = ""; + if (otherPod == null) { + String thisPod; try { - this_pod = InetAddress.getLocalHost().getHostName(); - System.out.println("this_pod: " + this_pod); + thisPod = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { - this_pod = ""; + utilsLogger.trace("UnkownHostException: " + e.getMessage(), e); + thisPod = ""; } - System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods())); for (String pod : BaseServlet.getPods()) { - if (!pod.equals(this_pod)) - other_pod = pod; + if (!pod.equals(thisPod)) { + otherPod = pod; + } } } - return other_pod; + return otherPod; } - private static String other_pod; + public static String getUrlSecurityOption() { + if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) { + return "https://"; + } + return "http://"; + } + + private static String getAppropriateUrlPort() { + if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) { + return ""; + } + return ":" + ProvRunner.getProvProperties() + .getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080"); + } }