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;
25 import java.security.InvalidParameterException;
27 import org.apache.camel.Exchange;
28 import org.onap.aai.rest.RestClientEndpoint;
29 import org.onap.aai.cl.api.Logger;
30 import org.onap.aai.cl.eelf.LoggerFactory;
32 public class ChampRouter extends QueryRouter {
33 Logger logger = LoggerFactory.getInstance().getLogger(ChampRouter.class.getName());
35 private String champBaseURL;
38 public ChampRouter(String champBaseURL) {
39 String baseURL = champBaseURL.endsWith("/") ? champBaseURL.substring(0, champBaseURL.length() - 1)
41 if(checkRecursion(baseURL)){
42 logger.info(QueryMsgs.QUERY_INFO, "Invalid champBaseURL : Can't re-route back to DataRouter "+ champBaseURL);
43 throw new InvalidParameterException("Invalid champBaseURL : Can't re-route back to DataRouter "+ champBaseURL);
45 this.champBaseURL = baseURL;
48 public void setQueryRequest(Exchange exchange) {
50 String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
51 String queryParams = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
53 if (queryParams != null && !queryParams.isEmpty()) {
54 ecompUrl = champBaseURL + path + "?" + queryParams;
56 ecompUrl = champBaseURL + path;
59 logger.info(QueryMsgs.QUERY_INFO, "Routing request to Champ service URL: " + ecompUrl);
60 exchange.getIn().setHeader(RestClientEndpoint.IN_HEADER_URL, ecompUrl);
61 exchange.getIn().setHeader("X-FromAppId", SERVICE_NAME);
62 exchange.getIn().setHeader("X-TransactionId", getTxId(exchange));
66 public void setQueryResponse(Exchange exchange) {
67 Integer httpResponseCode = exchange.getIn().getHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_CODE, Integer.class);
68 // Object httpBody = exchange.getIn().getBody();
69 exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponseCode);