c9e004c4cd3a805c19034b50c0386ceac0c178ae
[aai/data-router.git] / src / main / java / org / onap / aai / datarouter / query / QueryRouter.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.datarouter.query;
24
25 import java.util.Map;
26 import java.util.UUID;
27
28 import org.apache.camel.Exchange;
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
31 import org.onap.aai.cl.mdc.MdcContext;
32
33
34 public abstract class QueryRouter {
35   Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
36
37
38   protected static final String SERVICE_NAME = "DATA-ROUTER";
39   /** HTTP header containing the ECOMP Request Id */
40   protected static final String HEADER_TRANS_ID = "X-TransactionId";
41   
42   /** HTTP header containing the calling application Id */
43   protected static final String HEADER_FROM_APP_ID = "X-FromAppId";
44   
45   /** HTTP header containing the calling host details */
46   protected static final String HEADER_FROM_HOST = "Host";
47   
48   /** HTTP header containing the calling host details */
49   protected static final String DATA_ROUTER_PORT = "9502";
50   
51
52   public abstract void setQueryRequest(Exchange exchange) ;
53   
54   public abstract void setQueryResponse(Exchange exchange);
55   
56   protected String getTxId(final Exchange exchange){
57     String txId = exchange.getIn().getHeader("X-TransactionId",String.class);    
58     return ((txId==null||txId.isEmpty())?UUID.randomUUID().toString():txId);
59   }
60   
61   protected boolean checkRecursion(String url){
62    return url.contains(DATA_ROUTER_PORT);
63   }
64   
65   protected void setMDC(final Exchange exchange) {
66     String transId = exchange.getIn().getHeader(HEADER_TRANS_ID, String.class);
67     String appId = exchange.getIn().getHeader(HEADER_FROM_APP_ID, String.class);
68     String hostId = exchange.getIn().getHeader(HEADER_FROM_HOST, String.class);
69
70     // Set MDC transaction id, calling service name, calling service id,
71     // partner name, client address
72     MdcContext.initialize(transId, "DataRouter", "", appId, hostId);
73   }
74  
75
76 }