aabeac2c7d414752d8e76b3f5e542944c089fd7d
[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-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 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 package org.onap.aai.datarouter.query;
22
23 import java.util.Map;
24 import java.util.UUID;
25
26 import org.apache.camel.Exchange;
27 import org.onap.aai.cl.api.Logger;
28 import org.onap.aai.cl.eelf.LoggerFactory;
29 import org.onap.aai.cl.mdc.MdcContext;
30
31
32 public abstract class QueryRouter {
33   Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
34
35
36   protected static final String SERVICE_NAME = "DATA-ROUTER";
37   /** HTTP header containing the ECOMP Request Id */
38   protected static final String HEADER_TRANS_ID = "X-TransactionId";
39   
40   /** HTTP header containing the calling application Id */
41   protected static final String HEADER_FROM_APP_ID = "X-FromAppId";
42   
43   /** HTTP header containing the calling host details */
44   protected static final String HEADER_FROM_HOST = "Host";
45   
46   /** HTTP header containing the calling host details */
47   protected static final String DATA_ROUTER_PORT = "9502";
48   
49
50   public abstract void setQueryRequest(Exchange exchange) ;
51   
52   public abstract void setQueryResponse(Exchange exchange);
53   
54   protected String getTxId(final Exchange exchange){
55     String txId = exchange.getIn().getHeader("X-TransactionId",String.class);    
56     return ((txId==null||txId.isEmpty())?UUID.randomUUID().toString():txId);
57   }
58   
59   protected boolean checkRecursion(String url){
60    return url.contains(DATA_ROUTER_PORT);
61   }
62   
63   protected void setMDC(final Exchange exchange) {
64     String transId = exchange.getIn().getHeader(HEADER_TRANS_ID, String.class);
65     String appId = exchange.getIn().getHeader(HEADER_FROM_APP_ID, String.class);
66     String hostId = exchange.getIn().getHeader(HEADER_FROM_HOST, String.class);
67
68     // Set MDC transaction id, calling service name, calling service id,
69     // partner name, client address
70     MdcContext.initialize(transId, "DataRouter", "", appId, hostId);
71   }
72  
73
74 }