2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
25 package org.onap.aai.spike.service;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.ws.rs.core.Response.Status;
29 import org.onap.aai.cl.api.LogFields;
30 import org.onap.aai.cl.api.LogLine;
31 import org.onap.aai.cl.api.Logger;
32 import org.onap.aai.cl.eelf.LoggerFactory;
33 import org.onap.aai.cl.mdc.MdcContext;
34 import org.onap.aai.spike.logging.SpikeMsgs;
35 import org.onap.aai.spike.util.SpikeConstants;
37 import org.springframework.http.HttpHeaders;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.GetMapping;
41 import org.springframework.web.bind.annotation.RequestHeader;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RestController;
46 @RequestMapping(value = "/services/spike/v1/echo-service")
47 public class EchoService {
49 private static Logger logger = LoggerFactory.getInstance().getLogger(EchoService.class.getName());
50 private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(EchoService.class.getName());
53 public ResponseEntity<String> ping(@RequestHeader HttpHeaders headers, HttpServletRequest req) {
55 String fromIp = req.getRemoteAddr();
56 String fromAppId = "";
57 String transId = null;
59 if (headers.getFirst("X-FromAppId") != null) {
60 fromAppId = headers.getFirst("X-FromAppId");
63 if ((headers.getFirst("X-TransactionId") == null) || headers.getFirst("X-TransactionId").isEmpty()) {
64 transId = java.util.UUID.randomUUID().toString();
66 transId = headers.getFirst("X-TransactionId");
69 MdcContext.initialize(transId, SpikeConstants.SPIKE_SERVICE_NAME, "", fromAppId, fromIp);
72 logger.info(SpikeMsgs.PROCESS_REST_REQUEST, req.getMethod(), req.getRequestURL().toString(),
73 req.getRemoteHost(), Status.OK.toString());
75 // Generate audit log.
76 auditLogger.info(SpikeMsgs.PROCESS_REST_REQUEST,
77 new LogFields().setField(LogLine.DefinedFields.RESPONSE_CODE, Status.OK.toString())
78 .setField(LogLine.DefinedFields.RESPONSE_DESCRIPTION, Status.OK.toString()),
79 (req != null) ? req.getMethod() : "Unknown", (req != null) ? req.getRequestURL().toString() : "Unknown",
80 (req != null) ? req.getRemoteHost() : "Unknown", Status.OK.toString());
83 return new ResponseEntity<>("Alive", HttpStatus.OK);