2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.datarouter.query;
26 import java.util.UUID;
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;
34 public abstract class QueryRouter {
35 Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
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";
42 /** HTTP header containing the calling application Id */
43 protected static final String HEADER_FROM_APP_ID = "X-FromAppId";
45 /** HTTP header containing the calling host details */
46 protected static final String HEADER_FROM_HOST = "Host";
48 /** HTTP header containing the calling host details */
49 protected static final String DATA_ROUTER_PORT = "9502";
52 public abstract void setQueryRequest(Exchange exchange) ;
54 public abstract void setQueryResponse(Exchange exchange);
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);
61 protected boolean checkRecursion(String url){
62 return url.contains(DATA_ROUTER_PORT);
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);
70 // Set MDC transaction id, calling service name, calling service id,
71 // partner name, client address
72 MdcContext.initialize(transId, "DataRouter", "", appId, hostId);