summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonErrorProcessor.java50
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java83
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java277
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChampRouter.java73
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/QueryMsgs.java47
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/QueryRouter.java76
-rw-r--r--src/main/resources/logging/QueryMsgs.properties31
7 files changed, 637 insertions, 0 deletions
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonErrorProcessor.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonErrorProcessor.java
new file mode 100644
index 0000000..8206d38
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonErrorProcessor.java
@@ -0,0 +1,50 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import org.apache.camel.Exchange;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+
+public class ChameleonErrorProcessor {
+
+ Logger logger = LoggerFactory.getInstance().getLogger(ChameleonRouter.class.getName());
+
+ public static final String ECOMP_QUERY_ERROR_CODE = "ECOMP_QUERY_ERROR_CODE";
+
+ private ChameleonErrorProcessor(){}
+
+
+ public void process(Exchange exchange) throws Exception {
+ int code = 500;
+ if (exchange.getIn().getHeader(ECOMP_QUERY_ERROR_CODE, Integer.class) != null) {
+ code = exchange.getIn().getHeader(ECOMP_QUERY_ERROR_CODE, Integer.class);
+ }
+ Exception e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
+ if (e != null) {
+ logger.error(QueryMsgs.QUERY_ERROR, e.toString());
+ }
+
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, code);
+ }
+}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
new file mode 100644
index 0000000..73bf54c
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
@@ -0,0 +1,83 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+
+public class ChameleonResponseBuiler {
+
+ public static void buildEntity(Exchange exchange, String ID){
+ String response = exchange.getIn().getBody().toString();
+ JsonParser parser = new JsonParser();
+ JsonObject root = parser.parse(response).getAsJsonObject();
+ JsonObject champResponse = new JsonObject();
+ if (!root.has("type")) {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ return ;
+ }
+ champResponse.addProperty("key", ID);
+ champResponse.addProperty("type", root.get("type").getAsString());
+ if (root.has("source")) {
+ champResponse.add("source", root.get("source"));
+ }
+ if (root.has("target")) {
+ champResponse.add("target", root.get("target"));
+ }
+
+ JsonObject props = new JsonObject();
+ List<Map.Entry<String, JsonElement>> entries = new ArrayList<Map.Entry<String, JsonElement>>(
+ root.getAsJsonObject().entrySet());
+ for (Map.Entry<String, JsonElement> e : entries) {
+ if (!e.getKey().equals("type") && !e.getKey().equals("source") && !e.getKey().equals("target")) {
+ if (e.getKey().equals("source")) {
+
+ }
+ props.addProperty(e.getKey(), e.getValue().getAsString());
+ }
+
+ }
+
+ champResponse.add("properties", props);
+
+ exchange.getIn().setBody(champResponse.toString());
+
+ }
+
+
+ public static void buildObjectRelationship(Exchange exchange, String ID){
+ //TODO: implement when chameleon supports this query
+ }
+ public static void buildCollection(Exchange exchange){
+ //TODO: implement when chameleon supports this query
+ }
+
+
+}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java
new file mode 100644
index 0000000..3033820
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java
@@ -0,0 +1,277 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import java.security.InvalidParameterException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.ws.rs.BadRequestException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeCamelException;
+import org.onap.aai.rest.RestClientEndpoint;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+
+public class ChameleonRouter extends QueryRouter {
+
+ Logger logger = LoggerFactory.getInstance().getLogger(ChameleonRouter.class.getName());
+
+ private String chameleonBaseURL;
+
+ private enum ChameleonAction {
+ GET_OBJECT_BY_ID, GET_REL_BY_ID, GET_OBJECT_RELS, GET_OBJECTS_BY_FILTER, GET_RELS_BY_FILTER
+ };
+
+ private static final Pattern QUERY_OBJECT_FILTER_URL_MATCH = Pattern.compile("/objects/filter(.*)");
+ private static final Pattern QUERY_REL_FILTER_URL_MATCH = Pattern.compile("/relationships/filter(.*)");
+ private static final Pattern QUERY_OBJECT_REL_URL_MATCH = Pattern.compile("/objects/relationships/(.*)");
+ private static final Pattern QUERY_OBJECT_ID_URL_MATCH = Pattern.compile("/objects/(.*)");
+ private static final Pattern QUERY_REL_ID_URL_MATCH = Pattern.compile("/relationships/(.*)");
+
+ private static final String ECOMP_QUERY_ID = "ECOMP_QUERY_ID";
+ private static final String ECOMP_QUERY_TYPE = "ECOMP_QUERY_TYPE";
+
+ public ChameleonRouter(String chameleonBaseURL) {
+ String baseURL = chameleonBaseURL.endsWith("/") ? chameleonBaseURL.substring(0, chameleonBaseURL.length() - 1)
+ : chameleonBaseURL;
+ if (checkRecursion(baseURL)) {
+ logger.error(QueryMsgs.QUERY_ERROR,
+ "Invalid chameleonBaseURL : Can't re-route back to DataRouter " + chameleonBaseURL);
+ throw new InvalidParameterException(
+ "Invalid chameleonBaseURL : Can't re-route back to DataRouter " + chameleonBaseURL);
+ }
+ this.chameleonBaseURL = baseURL;
+ }
+
+ public void setQueryRequest(Exchange exchange) {
+ setMDC(exchange);
+ ChameleonAction action = resolveChameleonAction(exchange);
+ String ecompUrl = buildUrl(exchange, action);
+ logger.info(QueryMsgs.QUERY_INFO, "Routing request to Chameleon service URL: " + ecompUrl);
+ exchange.getIn().setHeader(RestClientEndpoint.IN_HEADER_URL, ecompUrl);
+ exchange.getIn().setHeader("X-FromAppId", SERVICE_NAME);
+ exchange.getIn().setHeader("X-TransactionId", getTxId(exchange));
+
+ }
+
+ private boolean urlMatcher(Pattern p, String url) {
+ Matcher m = p.matcher(url);
+ if (m.matches() && !m.group(1).contains("/")) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private ChameleonAction resolveChameleonAction(Exchange exchange) {
+ String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
+ path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
+ ChameleonAction action;
+
+ if (urlMatcher(QUERY_OBJECT_FILTER_URL_MATCH, path)) {
+ action = ChameleonAction.GET_OBJECTS_BY_FILTER;
+ } else if (urlMatcher(QUERY_REL_FILTER_URL_MATCH, path)) {
+ action = ChameleonAction.GET_RELS_BY_FILTER;
+ } else if (urlMatcher(QUERY_OBJECT_REL_URL_MATCH, path)) {
+ action = ChameleonAction.GET_OBJECT_RELS;
+ } else if (urlMatcher(QUERY_OBJECT_ID_URL_MATCH, path)) {
+ action = ChameleonAction.GET_OBJECT_BY_ID;
+ } else if (urlMatcher(QUERY_REL_ID_URL_MATCH, path)) {
+ action = ChameleonAction.GET_REL_BY_ID;
+ } else {
+ exchange.getIn().setHeader(ChameleonErrorProcessor.ECOMP_QUERY_ERROR_CODE, 404);
+ throw new RuntimeCamelException();
+ }
+ return action;
+ }
+
+ private String buildUrl(Exchange exchange, ChameleonAction action) {
+ String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
+ path = path.endsWith("/") ? path.substring(0, path.length() - 1) : path;
+ String queryParams = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ String ecompUrl = "";
+ String ID = "";
+
+ switch (action) {
+ case GET_OBJECT_BY_ID:
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
+ if (ID == null || ID.isEmpty()) {
+ throw new IllegalArgumentException("Invalid URI path with no Object ID: " + path);
+ } else {
+ if (queryParams != null && !queryParams.isEmpty()) {
+ ecompUrl = chameleonBaseURL + "/" + ID + "?" + queryParams;
+
+ } else {
+ ecompUrl = chameleonBaseURL + "/" + ID;
+ }
+ }
+ exchange.getIn().setHeader(ECOMP_QUERY_ID, ID);
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_OBJECT_BY_ID);
+ break;
+
+ case GET_REL_BY_ID:
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
+ if (ID == null || ID.isEmpty()) {
+ throw new IllegalArgumentException("Invalid URI path with no Relationship ID: " + path);
+ } else {
+ if (queryParams != null && !queryParams.isEmpty()) {
+ ecompUrl = chameleonBaseURL + "/" + ID + "?" + queryParams;
+
+ } else {
+ ecompUrl = chameleonBaseURL + "/" + ID;
+ }
+ }
+ exchange.getIn().setHeader(ECOMP_QUERY_ID, ID);
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_REL_BY_ID);
+ break;
+
+ case GET_OBJECT_RELS:
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
+ if (ID == null || ID.isEmpty()) {
+ throw new IllegalArgumentException("Invalid URI path with no Object ID: " + path);
+ } else {
+ if (queryParams != null && !queryParams.isEmpty()) {
+ // TODO: Fix the URL for getting object relations when Chameloen
+ // supports this API
+ ecompUrl = chameleonBaseURL + "/relations" + ID + "?" + queryParams;
+
+ } else {
+ ecompUrl = chameleonBaseURL + "/relations" + ID;
+ }
+ }
+ exchange.getIn().setHeader(ECOMP_QUERY_ID, ID);
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_OBJECT_RELS);
+ break;
+
+ case GET_OBJECTS_BY_FILTER:
+ if (queryParams != null && !queryParams.isEmpty()) {
+ // TODO: Fix the URL for getting object filter when Chameloen
+ // supports this API
+ ecompUrl = chameleonBaseURL + "/filter?" + queryParams;
+ } else {
+ ecompUrl = chameleonBaseURL + "/filter";
+ }
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_OBJECTS_BY_FILTER);
+ break;
+
+ case GET_RELS_BY_FILTER:
+ if (queryParams != null && !queryParams.isEmpty()) {
+ // TODO: Fix the URL for getting rel filter when Chameloen
+ // supports this API
+ ecompUrl = chameleonBaseURL + "/filter?" + queryParams;
+ } else {
+ ecompUrl = chameleonBaseURL + "/filter";
+ }
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_RELS_BY_FILTER);
+ break;
+
+ }
+
+ return ecompUrl;
+ }
+
+ public void setQueryResponse(Exchange exchange) {
+ parseResponse(exchange);
+ adjustHeaders(exchange);
+ }
+
+ private void adjustHeaders(Exchange exchange) {
+ // Remove the internal heders
+ exchange.getIn().removeHeader(ECOMP_QUERY_ID);
+ exchange.getIn().removeHeader(ECOMP_QUERY_TYPE);
+ }
+
+ private void parseResponse(Exchange exchange) throws BadRequestException {
+
+ ChameleonAction action = exchange.getIn().getHeader(ECOMP_QUERY_TYPE, ChameleonAction.class);
+ Integer httpResponseCode = exchange.getIn().getHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_CODE, Integer.class);
+ String ID = "";
+
+ switch (action) {
+ case GET_OBJECT_BY_ID:
+ if (httpResponseCode >= 200 && httpResponseCode <= 299) {
+ ID = exchange.getIn().getHeader(ECOMP_QUERY_ID, String.class);
+ if (ID == null || ID.isEmpty()) {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ } else {
+ ChameleonResponseBuiler.buildEntity(exchange, ID);
+ }
+ } else {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponseCode);
+ }
+ break;
+ case GET_REL_BY_ID:
+ if (httpResponseCode >= 200 && httpResponseCode <= 299) {
+ ID = exchange.getIn().getHeader(ECOMP_QUERY_ID, String.class);
+ if (ID == null || ID.isEmpty()) {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ } else {
+ ChameleonResponseBuiler.buildEntity(exchange, ID);
+ }
+ } else {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponseCode);
+ }
+ break;
+ case GET_OBJECT_RELS:
+ if (httpResponseCode >= 200 && httpResponseCode <= 299) {
+ ID = exchange.getIn().getHeader(ECOMP_QUERY_ID, String.class);
+ if (ID == null || ID.isEmpty()) {
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ } else {
+ ChameleonResponseBuiler.buildObjectRelationship(exchange, ID);
+ }
+ } else {
+ // TODO:Return 200 with empty body for now until chameleon supports this
+ // query
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
+ exchange.getIn().setBody("[]");
+ }
+ break;
+ case GET_OBJECTS_BY_FILTER:
+ if (httpResponseCode >= 200 && httpResponseCode <= 299) {
+ ChameleonResponseBuiler.buildCollection(exchange);
+ } else {
+ // TODO:Return 200 with empty body for now until chameleon supports this
+ // query
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
+ exchange.getIn().setBody("[]");
+ }
+ break;
+ case GET_RELS_BY_FILTER:
+ if (httpResponseCode >= 200 && httpResponseCode <= 299) {
+ ChameleonResponseBuiler.buildCollection(exchange);
+ } else {
+ // TODO:Return 200 with empty body for now until chameleon supports this
+ // query
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 200);
+ exchange.getIn().setBody("[]");
+ }
+ break;
+
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java b/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java
new file mode 100644
index 0000000..0844c93
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java
@@ -0,0 +1,73 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import java.security.InvalidParameterException;
+
+import org.apache.camel.Exchange;
+import org.onap.aai.rest.RestClientEndpoint;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+
+public class ChampRouter extends QueryRouter {
+ Logger logger = LoggerFactory.getInstance().getLogger(ChampRouter.class.getName());
+
+ private String champBaseURL;
+
+
+ public ChampRouter(String champBaseURL) {
+ String baseURL = champBaseURL.endsWith("/") ? champBaseURL.substring(0, champBaseURL.length() - 1)
+ : champBaseURL;
+ if(checkRecursion(baseURL)){
+ logger.info(QueryMsgs.QUERY_INFO, "Invalid champBaseURL : Can't re-route back to DataRouter "+ champBaseURL);
+ throw new InvalidParameterException("Invalid champBaseURL : Can't re-route back to DataRouter "+ champBaseURL);
+ }
+ this.champBaseURL = baseURL;
+ }
+
+ public void setQueryRequest(Exchange exchange) {
+ setMDC(exchange);
+ String path = exchange.getIn().getHeader(Exchange.HTTP_PATH, String.class);
+ String queryParams = exchange.getIn().getHeader(Exchange.HTTP_QUERY, String.class);
+ String ecompUrl;
+ if (queryParams != null && !queryParams.isEmpty()) {
+ ecompUrl = champBaseURL + path + "?" + queryParams;
+ } else {
+ ecompUrl = champBaseURL + path;
+ }
+
+ logger.info(QueryMsgs.QUERY_INFO, "Routing request to Champ service URL: " + ecompUrl);
+ exchange.getIn().setHeader(RestClientEndpoint.IN_HEADER_URL, ecompUrl);
+ exchange.getIn().setHeader("X-FromAppId", SERVICE_NAME);
+ exchange.getIn().setHeader("X-TransactionId", getTxId(exchange));
+
+ }
+
+ public void setQueryResponse(Exchange exchange) {
+ Integer httpResponseCode = exchange.getIn().getHeader(RestClientEndpoint.OUT_HEADER_RESPONSE_CODE, Integer.class);
+ // Object httpBody = exchange.getIn().getBody();
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponseCode);
+
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/datarouter/query/QueryMsgs.java b/src/main/java/org/onap/aai/datarouter/query/QueryMsgs.java
new file mode 100644
index 0000000..fba7314
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/QueryMsgs.java
@@ -0,0 +1,47 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import org.onap.aai.cl.eelf.LogMessageEnum;
+
+import com.att.eelf.i18n.EELFResourceManager;
+
+public enum QueryMsgs implements LogMessageEnum {
+
+ /**
+ * Arguments: {0} = Enricher URL
+ */
+ QUERY_INFO,
+
+ QUERY_ERROR;
+
+
+
+
+ /**
+ * Static initializer to ensure the resource bundles for this class are loaded...
+ */
+ static {
+ EELFResourceManager.loadMessageBundle("logging/QueryMsgs");
+ };
+}
diff --git a/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java b/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java
new file mode 100644
index 0000000..c9e004c
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java
@@ -0,0 +1,76 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017 Amdocs
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.aai.datarouter.query;
+
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.camel.Exchange;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.cl.mdc.MdcContext;
+
+
+public abstract class QueryRouter {
+ Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
+
+
+ protected static final String SERVICE_NAME = "DATA-ROUTER";
+ /** HTTP header containing the ECOMP Request Id */
+ protected static final String HEADER_TRANS_ID = "X-TransactionId";
+
+ /** HTTP header containing the calling application Id */
+ protected static final String HEADER_FROM_APP_ID = "X-FromAppId";
+
+ /** HTTP header containing the calling host details */
+ protected static final String HEADER_FROM_HOST = "Host";
+
+ /** HTTP header containing the calling host details */
+ protected static final String DATA_ROUTER_PORT = "9502";
+
+
+ public abstract void setQueryRequest(Exchange exchange) ;
+
+ public abstract void setQueryResponse(Exchange exchange);
+
+ protected String getTxId(final Exchange exchange){
+ String txId = exchange.getIn().getHeader("X-TransactionId",String.class);
+ return ((txId==null||txId.isEmpty())?UUID.randomUUID().toString():txId);
+ }
+
+ protected boolean checkRecursion(String url){
+ return url.contains(DATA_ROUTER_PORT);
+ }
+
+ protected void setMDC(final Exchange exchange) {
+ String transId = exchange.getIn().getHeader(HEADER_TRANS_ID, String.class);
+ String appId = exchange.getIn().getHeader(HEADER_FROM_APP_ID, String.class);
+ String hostId = exchange.getIn().getHeader(HEADER_FROM_HOST, String.class);
+
+ // Set MDC transaction id, calling service name, calling service id,
+ // partner name, client address
+ MdcContext.initialize(transId, "DataRouter", "", appId, hostId);
+ }
+
+
+}
diff --git a/src/main/resources/logging/QueryMsgs.properties b/src/main/resources/logging/QueryMsgs.properties
new file mode 100644
index 0000000..4211c09
--- /dev/null
+++ b/src/main/resources/logging/QueryMsgs.properties
@@ -0,0 +1,31 @@
+#Resource key=Error Code|Message text|Resolution text |Description text
+#######
+#Newlines can be utilized to add some clarity ensuring continuing line
+#has atleast one leading space
+#ResourceKey=\
+# ERR0000E\
+# Sample error msg txt\
+# Sample resolution msg\
+# Sample description txt
+#
+######
+#Error code classification category
+#000 Info/Debug
+#100 Permission errors
+#200 Availability errors/Timeouts
+#300 Data errors
+#400 Schema Interface type/validation errors
+#500 Business process errors
+#900 Unknown errors
+#
+########################################################################
+
+
+
+QUERY_INFO=\
+ DR0013I|\
+ QueryRouter Info: {0}
+QUERY_ERROR=\
+ DR0013E|\
+ QueryRouter Error: {0}
+