45f671efac140723969950ba09fa3ff0a6060047
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / AAIApiServerURLBase.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  *
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22 package org.onap.aai.util;
23
24 import java.util.List;
25 import java.util.Map;
26
27 import org.apache.cxf.helpers.CastUtils;
28 import org.apache.cxf.message.Message;
29 import org.apache.cxf.phase.PhaseInterceptorChain;
30
31 import org.onap.aai.exceptions.AAIException;
32 import org.onap.aai.introspection.Version;
33
34 public class AAIApiServerURLBase {
35         
36         /**
37          * Gets the.
38          *
39          * @return the string
40          * @throws AAIException the AAI exception
41          */
42         public static String get() throws AAIException {
43                 
44                 String hostName = null;
45                 try {
46                         Message message = PhaseInterceptorChain.getCurrentMessage();
47                         Map<String, List<String>> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS));
48                         List sa = null;
49                             if (headers != null) {
50                                     sa = headers.get("host");
51                                 }
52
53                                 if (sa != null && sa.size() == 1) {
54                                     hostName = "https://"+ sa.get(0).toString() + "/aai/";
55                                 }
56                 } catch (Exception e) { 
57                         // TODO: we may want to log an error here
58                 }
59                 // TODO: should this check the value a little closer and look for a pattern?
60                 if (hostName == null) { 
61                         hostName = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE);
62                         //AAIConstants.AAI_SERVER_URL_BASE;
63                 }
64                 return hostName;
65         }
66         
67         /**
68          * Gets the.
69          *
70          * @param v the v
71          * @return the string
72          * @throws AAIException the AAI exception
73          */
74         public static String get(Version v) throws AAIException {
75                 String hostName = null;
76             hostName = AAIApiServerURLBase.get();
77                 
78                 return hostName;
79         }
80         
81 }