[DMAAP-DR] Remove AAF/TLS phase 1
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / URLUtilities.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * *\r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * *\r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package org.onap.dmaap.datarouter.provisioning.utils;\r
26 \r
27 import com.att.eelf.configuration.EELFLogger;\r
28 import com.att.eelf.configuration.EELFManager;\r
29 import java.net.InetAddress;\r
30 import java.net.UnknownHostException;\r
31 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
32 import org.onap.dmaap.datarouter.provisioning.ProvRunner;\r
33 \r
34 /**\r
35  * Utility functions used to generate the different URLs used by the Data Router.\r
36  *\r
37  * @author Robert Eby\r
38  * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $\r
39  */\r
40 public class URLUtilities {\r
41 \r
42     private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");\r
43     private static String otherPod;\r
44 \r
45     private URLUtilities() {\r
46     }\r
47 \r
48     /**\r
49      * Generate the URL used to access a feed.\r
50      *\r
51      * @param feedid the feed id\r
52      * @return the URL\r
53      */\r
54     public static String generateFeedURL(int feedid) {\r
55         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feed/" + feedid;\r
56     }\r
57 \r
58     /**\r
59      * Generate the URL used to publish to a feed.\r
60      *\r
61      * @param feedid the feed id\r
62      * @return the URL\r
63      */\r
64     public static String generatePublishURL(int feedid) {\r
65         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/publish/" + feedid;\r
66     }\r
67 \r
68     /**\r
69      * Generate the URL used to subscribe to a feed.\r
70      *\r
71      * @param feedid the feed id\r
72      * @return the URL\r
73      */\r
74     public static String generateSubscribeURL(int feedid) {\r
75         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subscribe/" + feedid;\r
76     }\r
77 \r
78     /**\r
79      * Generate the URL used to access a feed's logs.\r
80      *\r
81      * @param feedid the feed id\r
82      * @return the URL\r
83      */\r
84     public static String generateFeedLogURL(int feedid) {\r
85         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/feedlog/" + feedid;\r
86     }\r
87 \r
88     /**\r
89      * Generate the URL used to access a subscription.\r
90      *\r
91      * @param subid the subscription id\r
92      * @return the URL\r
93      */\r
94     public static String generateSubscriptionURL(int subid) {\r
95         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/subs/" + subid;\r
96     }\r
97 \r
98     /**\r
99      * Generate the URL used to access a subscription's logs.\r
100      *\r
101      * @param subid the subscription id\r
102      * @return the URL\r
103      */\r
104     public static String generateSubLogURL(int subid) {\r
105         return getUrlSecurityOption() + BaseServlet.getProvName() + getAppropriateUrlPort() + "/sublog/" + subid;\r
106     }\r
107 \r
108     /**\r
109      * Generate the URL used to access the provisioning data on the peer POD.\r
110      *\r
111      * @return the URL\r
112      */\r
113     public static String generatePeerProvURL() {\r
114         return getUrlSecurityOption() + getPeerPodName() + getAppropriateUrlPort() + "/internal/prov";\r
115     }\r
116 \r
117     /**\r
118      * Generate the URL used to access the logfile data on the peer POD.\r
119      *\r
120      * @return the URL\r
121      */\r
122     public static String generatePeerLogsURL() {\r
123         //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.\r
124         String peerPodUrl = getPeerPodName();\r
125         if (peerPodUrl == null || "".equals(peerPodUrl)) {\r
126             return "";\r
127         }\r
128 \r
129         return getUrlSecurityOption() + peerPodUrl + getAppropriateUrlPort() + "/internal/drlogs/";\r
130     }\r
131 \r
132     /**\r
133      * Return the real (non CNAME) version of the peer POD's DNS name.\r
134      *\r
135      * @return the name\r
136      */\r
137     public static String getPeerPodName() {\r
138         if (otherPod == null) {\r
139             String thisPod;\r
140             try {\r
141                 thisPod = InetAddress.getLocalHost().getHostName();\r
142             } catch (UnknownHostException e) {\r
143                 utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);\r
144                 thisPod = "";\r
145             }\r
146             for (String pod : BaseServlet.getPods()) {\r
147                 if (!pod.equals(thisPod)) {\r
148                     otherPod = pod;\r
149                 }\r
150             }\r
151         }\r
152         return otherPod;\r
153     }\r
154 \r
155     public static String getUrlSecurityOption() {\r
156         if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) {\r
157             return "https://";\r
158         }\r
159         return "http://";\r
160     }\r
161 \r
162     private static String getAppropriateUrlPort() {\r
163         if (Boolean.TRUE.equals(ProvRunner.getTlsEnabled())) {\r
164             return "";\r
165         }\r
166         return ":" + ProvRunner.getProvProperties()\r
167             .getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080");\r
168     }\r
169 }\r