summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/aai/datarouter/Application.java14
-rw-r--r--src/main/java/org/onap/aai/datarouter/JerseyConfiguration.java41
-rw-r--r--src/main/java/org/onap/aai/datarouter/exception/BaseDataRouterException.java85
-rw-r--r--src/main/java/org/onap/aai/datarouter/exception/DataRouterError.java102
-rw-r--r--src/main/java/org/onap/aai/datarouter/exception/DataRouterException.java59
-rw-r--r--src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java6
-rw-r--r--src/main/java/org/onap/aai/datarouter/logging/LoggingUtil.java78
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java21
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java217
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/ChampRouter.java89
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/QueryRouter.java47
-rw-r--r--src/main/java/org/onap/aai/datarouter/query/RestClientConfig.java87
-rw-r--r--src/main/java/org/onap/aai/datarouter/service/EchoService.java23
-rw-r--r--src/main/java/org/onap/aai/datarouter/service/HistoricalQueryService.java107
14 files changed, 389 insertions, 587 deletions
diff --git a/src/main/java/org/onap/aai/datarouter/Application.java b/src/main/java/org/onap/aai/datarouter/Application.java
index 1d4bdc3..5abe7f3 100644
--- a/src/main/java/org/onap/aai/datarouter/Application.java
+++ b/src/main/java/org/onap/aai/datarouter/Application.java
@@ -22,14 +22,20 @@ package org.onap.aai.datarouter;
import java.util.HashMap;
+import org.apache.camel.component.servlet.CamelHttpTransportServlet;
import org.eclipse.jetty.util.security.Password;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
+
+ private static final String CAMEL_URL_MAPPING = "/*";
+ private static final String CAMEL_SERVLET_NAME = "CamelServlet";
public static void main(String[] args) {
String keyStorePassword = System.getenv("KEY_STORE_PASSWORD");
@@ -42,5 +48,13 @@ public class Application extends SpringBootServletInitializer{
}
+
+ @Bean
+ public ServletRegistrationBean getServletRegistrationBean() {
+ ServletRegistrationBean registration = new ServletRegistrationBean(new CamelHttpTransportServlet(), CAMEL_URL_MAPPING);
+ registration.setName(CAMEL_SERVLET_NAME);
+ return registration;
+ }
+
} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/datarouter/JerseyConfiguration.java b/src/main/java/org/onap/aai/datarouter/JerseyConfiguration.java
deleted file mode 100644
index 04e8cad..0000000
--- a/src/main/java/org/onap/aai/datarouter/JerseyConfiguration.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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=========================================================
- */
-package org.onap.aai.datarouter;
-
-import javax.ws.rs.ApplicationPath;
-
-import org.glassfish.jersey.server.ResourceConfig;
-import org.onap.aai.datarouter.service.EchoService;
-import org.onap.aai.datarouter.service.HistoricalQueryService;
-import org.springframework.stereotype.Component;
-
-
-@Component
-@ApplicationPath("/")
-public class JerseyConfiguration extends ResourceConfig
-{
- public JerseyConfiguration()
- {
- register(EchoService.class);
- register(HistoricalQueryService.class);
-
- }
-} \ No newline at end of file
diff --git a/src/main/java/org/onap/aai/datarouter/exception/BaseDataRouterException.java b/src/main/java/org/onap/aai/datarouter/exception/BaseDataRouterException.java
new file mode 100644
index 0000000..c256da3
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/exception/BaseDataRouterException.java
@@ -0,0 +1,85 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 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=========================================================
+ */
+package org.onap.aai.datarouter.exception;
+
+/*
+ * COPYRIGHT NOTICE: Copyright (c) 2016 Team Pacifica (Amdocs & AT&T) The contents and intellectual
+ * property contained herein, remain the property of Team Pacifica (Amdocs & AT&T).
+ */
+
+import java.util.Locale;
+
+/**
+ * Base SMAdaptor exception class.
+ */
+public class BaseDataRouterException extends Exception {
+
+ /** Force serialVersionUID. */
+ private static final long serialVersionUID = -6663403070792969748L;
+
+ /** Default locale. */
+ public static final Locale LOCALE = Locale.US;
+
+ /** Exception id. */
+ private final String id;
+
+ /**
+ * Constructor.
+ *
+ * @param id the incoming id.
+ */
+ public BaseDataRouterException(final String id) {
+ super();
+ this.id = id;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param id the incoming id
+ * @param message the incoming message
+ */
+ public BaseDataRouterException(final String id, final String message) {
+ super(message);
+ this.id = id;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param id the incoming id
+ * @param message the incoming message
+ * @param cause the incoming throwable
+ */
+ public BaseDataRouterException(final String id, final String message, final Throwable cause) {
+ super(message, cause);
+ this.id = id;
+ }
+
+ /**
+ * Get the exception id.
+ *
+ * @return the exception id
+ */
+ public String getId() {
+ return this.id;
+ }
+}
diff --git a/src/main/java/org/onap/aai/datarouter/exception/DataRouterError.java b/src/main/java/org/onap/aai/datarouter/exception/DataRouterError.java
new file mode 100644
index 0000000..6ca4bd8
--- /dev/null
+++ b/src/main/java/org/onap/aai/datarouter/exception/DataRouterError.java
@@ -0,0 +1,102 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 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=========================================================
+ */
+package org.onap.aai.datarouter.exception;
+
+/*
+ * COPYRIGHT NOTICE: Copyright (c) 2016 Team Pacifica (Amdocs & AT&T) The contents and intellectual
+ * property contained herein, remain the property of Team Pacifica (Amdocs & AT&T).
+ */
+
+import java.text.MessageFormat;
+
+import javax.ws.rs.core.Response.Status;
+
+/**
+ * DL enum for error conditions.
+ */
+public enum DataRouterError {
+
+ /** Parsing exceptions - Range 100..199. */
+ DL_PARSE_100("DL-100", "Unable to find resource {0} in the model", Status.BAD_REQUEST),
+ DL_PARSE_101("DL-101", "Unable to parse ", Status.BAD_REQUEST),
+ DL_PARSE_102("DL-102", "Sot Filter error: {0} ", Status.INTERNAL_SERVER_ERROR),
+ DL_PARSE_103("DL-103", "URL Parsing error: {0} ", Status.BAD_REQUEST),
+ DL_PARSE_104("DL-104", "Missing Ids filter: {0} ", Status.BAD_REQUEST),
+ DL_PARSE_105("DL-105", "Invalid Ids filter: {0} ", Status.BAD_REQUEST),
+
+ /** Validation exceptions - Range 200..299. */
+ DL_VALIDATION_200("DL-200", "Missing X-TransactionId in header ", Status.BAD_REQUEST),
+
+ /** Other components integration errors - Range 300..399. */
+ DL_INTEGRATION_300("DL-300", "Unable to decorate Graph ", Status.INTERNAL_SERVER_ERROR),
+
+ /** Environment related exceptions - Range 400..499. */
+ DL_ENV_400("DL-400", "Unable to find file {0} ", Status.INTERNAL_SERVER_ERROR),
+ DL_ENV_401("DL-401", "Unable to Load OXM Models", Status.INTERNAL_SERVER_ERROR),
+
+ /** Other components integration errors - Range 500..599. */
+ DL_AUTH_500("DL-500", "Unable to authorize User ", Status.FORBIDDEN);
+
+ /** The error id. */
+ private String id;
+ /** The error message. */
+ private String message;
+ /** The error http return code. */
+ private Status status;
+
+ /**
+ * Constructor.
+ *
+ * @param id the error id
+ * @param message the error message
+ */
+ DataRouterError(final String id, final String message, final Status status) {
+ this.id = id;
+ this.message = message;
+ this.status = status;
+ }
+
+ /**
+ * Get the id.
+ *
+ * @return the error id
+ */
+ public String getId() {
+ return this.id;
+ }
+
+ /**
+ * Get the message.
+ *
+ * @param args the error arguments
+ * @return the error message
+ */
+ public String getMessage(final Object... args) {
+ final MessageFormat formatter = new MessageFormat("");
+ formatter.applyPattern(this.message);
+ return formatter.format(args);
+ }
+
+ public Status getHttpStatus() {
+ return this.status;
+ }
+
+}
diff --git a/src/main/java/org/onap/aai/datarouter/exception/DataRouterException.java b/src/main/java/org/onap/aai/datarouter/exception/DataRouterException.java
deleted file mode 100644
index 46f0d58..0000000
--- a/src/main/java/org/onap/aai/datarouter/exception/DataRouterException.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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=========================================================
- */
-package org.onap.aai.datarouter.exception;
-
-import javax.ws.rs.core.Response.Status;
-
-public class DataRouterException extends Exception {
-
- private static final long serialVersionUID = 8162385108397238865L;
-
- private Status httpStatus;
-
- public DataRouterException() {
- }
-
- public DataRouterException(String message, Status httpStatus) {
- super(message);
- this.setHttpStatus(httpStatus);
- }
-
- public DataRouterException(Throwable cause) {
- super(cause);
- }
-
- public DataRouterException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public DataRouterException(String message, Throwable cause, boolean enableSuppression,
- boolean writableStackTrace) {
- super(message, cause, enableSuppression, writableStackTrace);
- }
-
- public Status getHttpStatus() {
- return httpStatus;
- }
-
- public void setHttpStatus(Status httpStatus) {
- this.httpStatus = httpStatus;
- }
-}
diff --git a/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java b/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
index f0d6541..93f4c54 100644
--- a/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
+++ b/src/main/java/org/onap/aai/datarouter/logging/DataRouterMsgs.java
@@ -26,12 +26,6 @@ import org.onap.aai.cl.eelf.LogMessageEnum;
public enum DataRouterMsgs implements LogMessageEnum {
-
- /**
- * Arguments: {0} = HTTP request type, {1} = time to process in milliseconds
- */
- PROCESSED_REQUEST,
-
/** Data Layer Service started. */
SERVICE_STARTED,
diff --git a/src/main/java/org/onap/aai/datarouter/logging/LoggingUtil.java b/src/main/java/org/onap/aai/datarouter/logging/LoggingUtil.java
deleted file mode 100644
index e29af73..0000000
--- a/src/main/java/org/onap/aai/datarouter/logging/LoggingUtil.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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=========================================================
- */
-package org.onap.aai.datarouter.logging;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.Response;
-
-import org.onap.aai.cl.api.LogFields;
-import org.onap.aai.cl.api.LogLine;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.datarouter.util.DataRouterConstants;
-import org.slf4j.MDC;
-
-public class LoggingUtil {
- public static void initMdcContext(HttpServletRequest httpReq, HttpHeaders headers) {
- String fromIp = httpReq.getRemoteAddr();
- String fromAppId = "";
- String transId = null;
-
- if (headers.getRequestHeaders().getFirst("X-FromAppId") != null) {
- fromAppId = headers.getRequestHeaders().getFirst("X-FromAppId");
- }
-
- if ((headers.getRequestHeaders().getFirst("X-TransactionId") == null)
- || headers.getRequestHeaders().getFirst("X-TransactionId").isEmpty()) {
- transId = java.util.UUID.randomUUID().toString();
- } else {
- transId = headers.getRequestHeaders().getFirst("X-TransactionId");
- }
-
- MdcContext.initialize(transId, DataRouterConstants.DATA_ROUTER_SERVICE_NAME, "", fromAppId,
- fromIp);
- }
-
- public static void logRestRequest(Logger logger, Logger auditLogger, HttpServletRequest req, Response response) {
- String respStatusString = "";
- if (Response.Status.fromStatusCode(response.getStatus()) != null) {
- respStatusString = Response.Status.fromStatusCode(response.getStatus()).toString();
- }
-
- // Generate error log
- logger.info(DataRouterMsgs.PROCESS_REST_REQUEST, req.getMethod(), req.getRequestURL().toString(),
- req.getRemoteHost(), Integer.toString(response.getStatus()));
-
- // Generate audit log.
- auditLogger.info(DataRouterMsgs.PROCESS_REST_REQUEST,
- new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, response.getStatus())
- .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, respStatusString),
- (req != null) ? req.getMethod() : "Unknown", (req != null) ? req.getRequestURL().toString() : "Unknown",
- (req != null) ? req.getRemoteHost() : "Unknown", Integer.toString(response.getStatus()) + " payload: "
- + (response.getEntity() == null ? "" : response.getEntity().toString()));
- MDC.clear();
- }
-
- public static String setDuration(long startTime, long stopTime) {
- return String.valueOf(stopTime - startTime);
- }
-}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
index 502fbf2..d319c48 100644
--- a/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonResponseBuiler.java
@@ -24,10 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import javax.ws.rs.core.Response.Status;
-
import org.apache.camel.Exchange;
-import org.onap.aai.datarouter.exception.DataRouterException;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -39,13 +36,14 @@ public class ChameleonResponseBuiler {
private static final String TARGET = "target";
private static final String TYPE = "type";
- public static String buildEntity(String chameleonResponse, String id) throws DataRouterException{
-
+ public static void buildEntity(Exchange exchange, String id){
+ String response = exchange.getIn().getBody().toString();
JsonParser parser = new JsonParser();
- JsonObject root = parser.parse(chameleonResponse).getAsJsonObject();
+ JsonObject root = parser.parse(response).getAsJsonObject();
JsonObject champResponse = new JsonObject();
if (!root.has(TYPE)) {
- throw new DataRouterException("Chameloen response does not have type : "+chameleonResponse , Status.BAD_REQUEST);
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
+ return ;
}
champResponse.addProperty("key", id);
champResponse.addProperty(TYPE, root.get(TYPE).getAsString());
@@ -68,19 +66,16 @@ public class ChameleonResponseBuiler {
champResponse.add("properties", props);
- return champResponse.toString();
+ exchange.getIn().setBody(champResponse.toString());
}
- public static String buildObjectRelationship(String chameleonResponse, String id){
+ public static void buildObjectRelationship(Exchange exchange, String id){
//TODO: implement when chameleon supports this query
- return "[]";
}
- public static String buildCollection(String chameleonResponse){
+ public static void buildCollection(Exchange exchange){
//TODO: implement when chameleon supports this query
- return "[]";
-
}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java b/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java
index 4e9f75b..2df2524 100644
--- a/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java
+++ b/src/main/java/org/onap/aai/datarouter/query/ChameleonRouter.java
@@ -18,40 +18,26 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.aai.datarouter.query;
+package org.onap.aai.datarouter.query;
import java.security.InvalidParameterException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.BadRequestException;
-import org.eclipse.jetty.util.security.Password;
+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;
-import org.onap.aai.datarouter.exception.DataRouterException;
-import org.onap.aai.datarouter.util.DataRouterConstants;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
-@Component
-@Qualifier("chameleon")
-public class ChameleonRouter implements QueryRouter {
+public class ChameleonRouter extends QueryRouter {
Logger logger = LoggerFactory.getInstance().getLogger(ChameleonRouter.class.getName());
private String chameleonBaseURL;
- private RestClient restClient ;
-
private enum ChameleonAction {
GET_OBJECT_BY_ID, GET_REL_BY_ID, GET_OBJECT_RELS, GET_OBJECTS_BY_FILTER, GET_RELS_BY_FILTER
};
@@ -62,26 +48,13 @@ public class ChameleonRouter implements QueryRouter {
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(){}
-
-
- public ChameleonRouter(String chameleonBaseURL, RestClientConfig config) {
- this.chameleonBaseURL = chameleonBaseURL;
- this.restClient = new RestClient().validateServerHostname(false).validateServerCertChain(true)
- .clientCertFile(config.getCertPath())
- .clientCertPassword(Password.deobfuscate(config.getCertPassword()))
- .trustStore(config.getTrustStorePath())
- .connectTimeoutMs(config.getConnectionTimeout())
- .readTimeoutMs(config.getReadTimeout());
- validate();
- }
-
-
- public void validate() {
+ public ChameleonRouter(String chameleonBaseURL) {
String baseURL = chameleonBaseURL.endsWith("/") ? chameleonBaseURL.substring(0, chameleonBaseURL.length() - 1)
: chameleonBaseURL;
- if (baseURL.contains(DATA_ROUTER_PORT)) {
+ if (checkRecursion(baseURL)) {
logger.error(QueryMsgs.QUERY_ERROR,
"Invalid chameleonBaseURL : Can't re-route back to DataRouter " + chameleonBaseURL);
throw new InvalidParameterException(
@@ -90,6 +63,17 @@ public class ChameleonRouter implements QueryRouter {
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("/")) {
@@ -99,39 +83,40 @@ public class ChameleonRouter implements QueryRouter {
}
}
- private ChameleonAction resolveChameleonAction(String urlContext) throws DataRouterException {
-
- urlContext = urlContext.endsWith("/") ? urlContext.substring(0, urlContext.length() - 1) : urlContext;
+ 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, urlContext)) {
+ if (urlMatcher(QUERY_OBJECT_FILTER_URL_MATCH, path)) {
action = ChameleonAction.GET_OBJECTS_BY_FILTER;
- } else if (urlMatcher(QUERY_REL_FILTER_URL_MATCH, urlContext)) {
+ } else if (urlMatcher(QUERY_REL_FILTER_URL_MATCH, path)) {
action = ChameleonAction.GET_RELS_BY_FILTER;
- } else if (urlMatcher(QUERY_OBJECT_REL_URL_MATCH, urlContext)) {
+ } else if (urlMatcher(QUERY_OBJECT_REL_URL_MATCH, path)) {
action = ChameleonAction.GET_OBJECT_RELS;
- } else if (urlMatcher(QUERY_OBJECT_ID_URL_MATCH, urlContext)) {
+ } else if (urlMatcher(QUERY_OBJECT_ID_URL_MATCH, path)) {
action = ChameleonAction.GET_OBJECT_BY_ID;
- } else if (urlMatcher(QUERY_REL_ID_URL_MATCH, urlContext)) {
+ } else if (urlMatcher(QUERY_REL_ID_URL_MATCH, path)) {
action = ChameleonAction.GET_REL_BY_ID;
} else {
-
- throw new DataRouterException("", Status.NOT_FOUND);
+ exchange.getIn().setHeader(ChameleonErrorProcessor.ECOMP_QUERY_ERROR_CODE, 404);
+ throw new RuntimeCamelException();
}
return action;
}
- private String buildUrl(String urlContext, String queryParams, ChameleonAction action) {
-
- urlContext = urlContext.endsWith("/") ? urlContext.substring(0, urlContext.length() - 1) : urlContext;
+ 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 = urlContext.substring(urlContext.lastIndexOf("/") + 1, urlContext.length());
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
if (ID == null || ID.isEmpty()) {
- throw new IllegalArgumentException("Invalid URI path with no Object ID: " + urlContext);
+ throw new IllegalArgumentException("Invalid URI path with no Object ID: " + path);
} else {
if (queryParams != null && !queryParams.isEmpty()) {
ecompUrl = chameleonBaseURL + "/" + ID + "?" + queryParams;
@@ -140,13 +125,14 @@ public class ChameleonRouter implements QueryRouter {
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 = urlContext.substring(urlContext.lastIndexOf("/") + 1, urlContext.length());
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
if (ID == null || ID.isEmpty()) {
- throw new IllegalArgumentException("Invalid URI path with no Relationship ID: " + urlContext);
+ throw new IllegalArgumentException("Invalid URI path with no Relationship ID: " + path);
} else {
if (queryParams != null && !queryParams.isEmpty()) {
ecompUrl = chameleonBaseURL + "/" + ID + "?" + queryParams;
@@ -155,13 +141,14 @@ public class ChameleonRouter implements QueryRouter {
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 = urlContext.substring(urlContext.lastIndexOf("/") + 1, urlContext.length());
+ ID = path.substring(path.lastIndexOf("/") + 1, path.length());
if (ID == null || ID.isEmpty()) {
- throw new IllegalArgumentException("Invalid URI path with no Object ID: " + urlContext);
+ 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
@@ -172,7 +159,8 @@ public class ChameleonRouter implements QueryRouter {
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:
@@ -183,7 +171,7 @@ public class ChameleonRouter implements QueryRouter {
} else {
ecompUrl = chameleonBaseURL + "/filter";
}
-
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_OBJECTS_BY_FILTER);
break;
case GET_RELS_BY_FILTER:
@@ -194,7 +182,7 @@ public class ChameleonRouter implements QueryRouter {
} else {
ecompUrl = chameleonBaseURL + "/filter";
}
-
+ exchange.getIn().setHeader(ECOMP_QUERY_TYPE, ChameleonAction.GET_RELS_BY_FILTER);
break;
}
@@ -202,83 +190,86 @@ public class ChameleonRouter implements QueryRouter {
return ecompUrl;
}
- private String parseResponse(String urlContext, OperationResult result, ChameleonAction action)
- throws DataRouterException {
+ 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);
+ }
- Integer httpResponseCode = result.getResultCode();
- String ID = urlContext.substring(urlContext.lastIndexOf("/") + 1, urlContext.length());
+ 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()) {
- throw new DataRouterException("", Status.BAD_REQUEST);
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
} else {
- return ChameleonResponseBuiler.buildEntity(result.getResult(), ID);
+ ChameleonResponseBuiler.buildEntity(exchange, ID);
}
} else {
- throw new DataRouterException("", Status.fromStatusCode(httpResponseCode));
+ 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()) {
- throw new DataRouterException("", Status.BAD_REQUEST);
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);
} else {
- return ChameleonResponseBuiler.buildEntity(result.getResult(), ID);
+ ChameleonResponseBuiler.buildEntity(exchange, ID);
}
} else {
- throw new DataRouterException("", Status.fromStatusCode(httpResponseCode));
+ exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, httpResponseCode);
}
-
+ break;
case GET_OBJECT_RELS:
-
- // TODO:Return 200 with empty body for now until chameleon supports this
- // query
- if (ID == null || ID.isEmpty()) {
- throw new DataRouterException("", Status.BAD_REQUEST);
+ 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 {
- return ChameleonResponseBuiler.buildObjectRelationship(result.getResult(), ID);
+ // 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:
- // TODO:Return 200 with empty body for now until chameleon supports this
- // query
- return ChameleonResponseBuiler.buildCollection(result.getResult());
-
+ 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:
- // TODO:Return 200 with empty body for now until chameleon supports this
- // query
- return ChameleonResponseBuiler.buildCollection(result.getResult());
- default:
- throw new DataRouterException("", Status.NOT_FOUND);
-
- }
-
- }
+ 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;
- @Override
- public String process(String urlContext, String queryParams, Map<String, List<String>> headers)
- throws DataRouterException {
- String response;
- ChameleonAction action = resolveChameleonAction(urlContext);
- String chameleonURL = buildUrl(urlContext, queryParams, action);
- logger.info(QueryMsgs.QUERY_INFO, "Routing request to Chameleon service URL: " + chameleonURL);
-
- headers = headers == null ? new HashMap<String, List<String>>() : headers;
- headers.put("X-FromAppId", Arrays.asList(DataRouterConstants.DATA_ROUTER_SERVICE_NAME));
- OperationResult result = restClient.get(chameleonURL, headers, MediaType.APPLICATION_JSON_TYPE);
-
- try {
- response = parseResponse(urlContext, result, action);
- } catch (DataRouterException ex) {
- logger.info(QueryMsgs.QUERY_ERROR,
- "Error while calling Chameleon service URL: " + chameleonURL + " failure cause: " + result.getFailureCause());
- throw ex;
}
- return response;
}
}
diff --git a/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java b/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java
index 7e63869..a120f89 100644
--- a/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java
+++ b/src/main/java/org/onap/aai/datarouter/query/ChampRouter.java
@@ -21,87 +21,50 @@
package org.onap.aai.datarouter.query;
import java.security.InvalidParameterException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.PostConstruct;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response.Status;
-
-import org.eclipse.jetty.util.security.Password;
+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;
-import org.onap.aai.datarouter.exception.DataRouterException;
-import org.onap.aai.datarouter.util.DataRouterConstants;
-import org.onap.aai.restclient.client.OperationResult;
-import org.onap.aai.restclient.client.RestClient;
-import org.onap.aai.restclient.rest.HttpUtil;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
-
-@Component
-@Qualifier("champ")
-public class ChampRouter implements QueryRouter {
+public class ChampRouter extends QueryRouter {
Logger logger = LoggerFactory.getInstance().getLogger(ChampRouter.class.getName());
private String champBaseURL;
-
- private RestClient restClient ;
- public ChampRouter(){}
-
- public ChampRouter(String champBaseURL, RestClientConfig config) {
- this.champBaseURL = champBaseURL;
- this.restClient = new RestClient().validateServerHostname(false).validateServerCertChain(true)
- .clientCertFile(config.getCertPath())
- .clientCertPassword(Password.deobfuscate(config.getCertPassword()))
- .trustStore(config.getTrustStorePath())
- .connectTimeoutMs(config.getConnectionTimeout())
- .readTimeoutMs(config.getReadTimeout());
- validate();
- }
-
- public void validate(){
- String baseURL = champBaseURL.endsWith("/") ? champBaseURL.substring(0, champBaseURL.length() - 1) : champBaseURL;
- if (baseURL.contains(DATA_ROUTER_PORT)) {
- 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);
+ 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;
+ this.champBaseURL = baseURL;
}
- @Override
- public String process(String urlContext, String queryParams, Map<String, List<String>> headers)
- throws DataRouterException {
- String champURL;
- String response;
+ 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()) {
- champURL = champBaseURL + urlContext + "?" + queryParams;
+ ecompUrl = champBaseURL + path + "?" + queryParams;
} else {
- champURL = champBaseURL + urlContext;
+ ecompUrl = champBaseURL + path;
}
- logger.info(QueryMsgs.QUERY_INFO, "Routing request to Champ service URL: " + champURL);
+ 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));
- headers = headers == null ? new HashMap<String, List<String>>() : headers;
- headers.put("X-FromAppId", Arrays.asList(DataRouterConstants.DATA_ROUTER_SERVICE_NAME));
- OperationResult result = restClient.get(champURL, headers, MediaType.APPLICATION_JSON_TYPE);
-
- if (HttpUtil.isHttpResponseClassSuccess(result.getResultCode())) {
- response = result.getResult();
- } else {
- logger.info(QueryMsgs.QUERY_ERROR,
- "Error while calling Champ service URL: " + champURL + " failure cause: " + result.getFailureCause());
- throw new DataRouterException(
- "Error while calling Champ service URL: " + champURL + " failure cause: " + result.getFailureCause(),
- Status.fromStatusCode(result.getResultCode()));
- }
+ }
- return response;
+ 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/QueryRouter.java b/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java
index 07b4e79..aabeac2 100644
--- a/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java
+++ b/src/main/java/org/onap/aai/datarouter/query/QueryRouter.java
@@ -20,22 +20,55 @@
*/
package org.onap.aai.datarouter.query;
-import java.util.List;
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.datarouter.exception.DataRouterException;
+import org.onap.aai.cl.mdc.MdcContext;
-public interface QueryRouter {
- Logger logger = LoggerFactory.getInstance().getLogger(QueryRouter.class.getName());
+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 */
- static final String DATA_ROUTER_PORT = "9502";
+ 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);
- public String process(String urlContext, String queryParams, Map<String, List<String>> headers)
- throws DataRouterException;
+ // 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/java/org/onap/aai/datarouter/query/RestClientConfig.java b/src/main/java/org/onap/aai/datarouter/query/RestClientConfig.java
deleted file mode 100644
index 96a61ba..0000000
--- a/src/main/java/org/onap/aai/datarouter/query/RestClientConfig.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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=========================================================
- */
-package org.onap.aai.datarouter.query;
-
-public class RestClientConfig {
-
- private String certPath;
- private String certPassword;
- private String trustStorePath;
- private String connectionTimeout;
- private String readTimeout;
-
- public String getCertPath() {
- return certPath;
- }
-
- public void setCertPath(String certPath) {
- this.certPath = certPath;
- }
-
- public String getCertPassword() {
- return certPassword;
- }
-
- public void setCertPassword(String certPassword) {
- this.certPassword = certPassword;
- }
-
- public String getTrustStorePath() {
- return trustStorePath;
- }
-
- public void setTrustStorePath(String trustStorePath) {
- this.trustStorePath = trustStorePath;
- }
-
- public int getConnectionTimeout() {
- return parseInt(connectionTimeout,10000);
- }
-
- public void setConnectionTimeout(String connectionTimeout) {
- this.connectionTimeout = connectionTimeout;
- }
-
- public int getReadTimeout() {
- return parseInt(connectionTimeout,10000);
- }
-
- public void setReadTimeout(String readTimeout) {
- this.readTimeout = readTimeout;
- }
-
-
- private int parseInt(String config, int defaultValue) {
- int intVal = defaultValue; // Default delay of half a sec
- try {
- intVal = Integer.parseInt(config);
- } catch (Exception e) {
- // Ignore the parsing error and use the default
- }
- return intVal;
- }
- @Override
- public String toString() {
- return "RestClientConfig [certPath=" + certPath + ", certPassword=" + certPassword + ", trustStorePath="
- + trustStorePath + ", connectionTimeout=" + connectionTimeout + ", readTimeout=" + readTimeout + "]";
- }
-
-}
diff --git a/src/main/java/org/onap/aai/datarouter/service/EchoService.java b/src/main/java/org/onap/aai/datarouter/service/EchoService.java
index 70bc129..8192935 100644
--- a/src/main/java/org/onap/aai/datarouter/service/EchoService.java
+++ b/src/main/java/org/onap/aai/datarouter/service/EchoService.java
@@ -20,6 +20,15 @@
*/
package org.onap.aai.datarouter.service;
+import org.onap.aai.cl.api.LogFields;
+import org.onap.aai.cl.api.LogLine;
+import org.onap.aai.cl.api.Logger;
+import org.onap.aai.cl.eelf.LoggerFactory;
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.datarouter.logging.DataRouterMsgs;
+import org.onap.aai.datarouter.util.DataRouterConstants;
+import org.slf4j.MDC;
+
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -30,18 +39,6 @@ import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
-import org.onap.aai.cl.api.LogFields;
-import org.onap.aai.cl.api.LogLine;
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.datarouter.logging.DataRouterMsgs;
-import org.onap.aai.datarouter.util.DataRouterConstants;
-import org.slf4j.MDC;
-import org.springframework.stereotype.Component;
-
-@Component
-@Path("/data-router/v1")
public class EchoService {
private static Logger logger = LoggerFactory.getInstance().getLogger(EchoService.class.getName());
@@ -51,7 +48,7 @@ public class EchoService {
private static final String XTRANSACTIONID = "X-TransactionId";
@GET
- @Path("/echo/{input}")
+ @Path("echo/{input}")
@Produces("text/plain")
public String ping(@PathParam("input") String input, @Context HttpHeaders headers,
@Context UriInfo info, @Context HttpServletRequest req) {
diff --git a/src/main/java/org/onap/aai/datarouter/service/HistoricalQueryService.java b/src/main/java/org/onap/aai/datarouter/service/HistoricalQueryService.java
deleted file mode 100644
index 2b401b0..0000000
--- a/src/main/java/org/onap/aai/datarouter/service/HistoricalQueryService.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 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=========================================================
- */
-package org.onap.aai.datarouter.service;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Encoded;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-
-import org.onap.aai.cl.api.Logger;
-import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.datarouter.exception.DataRouterException;
-import org.onap.aai.datarouter.logging.DataRouterMsgs;
-import org.onap.aai.datarouter.logging.LoggingUtil;
-import org.onap.aai.datarouter.query.QueryRouter;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Component;
-
-@Component
-@Path("/services/champ-service/v1")
-public class HistoricalQueryService {
-
- private Logger logger = LoggerFactory.getInstance().getLogger(HistoricalQueryService.class);
- Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(HistoricalQueryService.class.getName());
- private static Logger metricsLogger = LoggerFactory.getInstance()
- .getMetricsLogger(HistoricalQueryService.class.getName());
-
- @Autowired
- @Qualifier("champ")
- private QueryRouter champRouter;
-
- @Autowired
- @Qualifier("chameleon")
- private QueryRouter chameleonRouter;
-
- @GET
- @Path("{uri: .+}")
- @Produces({ MediaType.APPLICATION_JSON })
- public Response process(String content, @PathParam("version") String versionParam,
- @PathParam("uri") @Encoded String uri, @Context HttpHeaders httpHeaders, @Context UriInfo uriInfo,
- @Context HttpServletRequest req) {
- LoggingUtil.initMdcContext(req, httpHeaders);
- long startTimeInMs = System.currentTimeMillis();
- Response response = null;
- String urlContext = "/"+ uri;
- String queryParams = uriInfo.getRequestUri().getQuery();
-
- try {
-
- Map<String, List<String>> parameters = new HashMap<String, List<String>>();
- for (Map.Entry<String, List<String>> e : httpHeaders.getRequestHeaders().entrySet()) {
- parameters.put(e.getKey(), e.getValue());
- }
- if (uriInfo.getQueryParameters().containsKey("t-k")) {
- response = Response.status(Status.OK).entity(chameleonRouter.process(urlContext, queryParams, parameters))
- .build();
- } else {
- response = Response.status(Status.OK).entity(champRouter.process(urlContext, queryParams, parameters)).build();
- }
- } catch (DataRouterException ex) {
- response = Response.status(ex.getHttpStatus()).entity(ex.getMessage()).build();
-
- } catch (Exception e) {
- response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
-
- } finally {
- LoggingUtil.logRestRequest(logger, auditLogger, req, response);
- metricsLogger.info(DataRouterMsgs.PROCESSED_REQUEST, "GET",
- Long.toString(System.currentTimeMillis() - startTimeInMs));
- }
- return response;
-
- }
-
-}