2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.datarouter.query;
24 import java.util.UUID;
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;
32 public abstract class QueryRouter {
33 Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
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";
40 /** HTTP header containing the calling application Id */
41 protected static final String HEADER_FROM_APP_ID = "X-FromAppId";
43 /** HTTP header containing the calling host details */
44 protected static final String HEADER_FROM_HOST = "Host";
46 /** HTTP header containing the calling host details */
47 protected static final String DATA_ROUTER_PORT = "9502";
50 public abstract void setQueryRequest(Exchange exchange) ;
52 public abstract void setQueryResponse(Exchange exchange);
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);
59 protected boolean checkRecursion(String url){
60 return url.contains(DATA_ROUTER_PORT);
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);
68 // Set MDC transaction id, calling service name, calling service id,
69 // partner name, client address
70 MdcContext.initialize(transId, "DataRouter", "", appId, hostId);