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.service;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.ws.rs.GET;
25 import javax.ws.rs.Path;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.Produces;
28 import javax.ws.rs.core.Context;
29 import javax.ws.rs.core.HttpHeaders;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.UriInfo;
33 import org.onap.aai.cl.api.LogFields;
34 import org.onap.aai.cl.api.LogLine;
35 import org.onap.aai.cl.api.Logger;
36 import org.onap.aai.cl.eelf.LoggerFactory;
37 import org.onap.aai.cl.mdc.MdcContext;
38 import org.onap.aai.datarouter.logging.DataRouterMsgs;
39 import org.onap.aai.datarouter.util.DataRouterConstants;
41 import org.springframework.stereotype.Component;
44 @Path("/data-router/v1")
45 public class EchoService {
47 private static Logger logger = LoggerFactory.getInstance().getLogger(EchoService.class.getName());
48 private static Logger auditLogger =
49 LoggerFactory.getInstance().getAuditLogger(EchoService.class.getName());
50 private static final String XFROMAPPID = "X-FromAppId";
51 private static final String XTRANSACTIONID = "X-TransactionId";
54 @Path("/echo/{input}")
55 @Produces("text/plain")
56 public String ping(@PathParam("input") String input, @Context HttpHeaders headers,
57 @Context UriInfo info, @Context HttpServletRequest req) {
59 String fromIp = req.getRemoteAddr();
60 String fromAppId = "";
63 if (headers.getRequestHeaders().getFirst(XFROMAPPID) != null) {
64 fromAppId = headers.getRequestHeaders().getFirst(XFROMAPPID);
67 if ((headers.getRequestHeaders().getFirst(XTRANSACTIONID) == null)
68 || headers.getRequestHeaders().getFirst(XTRANSACTIONID).isEmpty()) {
69 transId = java.util.UUID.randomUUID().toString();
71 transId = headers.getRequestHeaders().getFirst(XTRANSACTIONID);
74 MdcContext.initialize(transId, DataRouterConstants.DATA_ROUTER_SERVICE_NAME, "", fromAppId,
78 String respStatusString = "";
79 if (Response.Status.fromStatusCode(status) != null) {
80 respStatusString = Response.Status.fromStatusCode(status).toString();
84 logger.info(DataRouterMsgs.PROCESS_REST_REQUEST, req.getMethod(),
85 req.getRequestURL().toString(), req.getRemoteHost(), Integer.toString(status));
87 // Generate audit log.
88 auditLogger.info(DataRouterMsgs.PROCESS_REST_REQUEST,
89 new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, status)
90 .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, respStatusString),
91 req.getMethod(), req.getRequestURL().toString(), req.getRemoteHost(), Integer.toString(status));
94 return "Hello, " + input + ".";