2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.schemaservice.healthcheck;
23 import java.util.ArrayList;
24 import java.util.HashMap;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.ws.rs.GET;
28 import javax.ws.rs.Path;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.*;
31 import javax.ws.rs.core.Response.Status;
33 import org.onap.aai.exceptions.AAIException;
34 import org.onap.aai.logging.ErrorLogHelper;
35 import org.onap.aai.restcore.RESTAPI;
38 * The Class EchoResponse.
41 public class EchoResource extends RESTAPI {
44 * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients.
45 * If there is a query string, a transaction gets logged into hbase, proving the application is
46 * connected to the data store.
47 * If there is no query string, no transaction logging is done to hbase.
49 * @param headers the headers
51 * @return the response
54 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
56 public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req,
57 @Context UriInfo uriInfo) {
58 Response response = null;
60 AAIException ex = null;
61 String fromAppId = null;
62 String transId = null;
65 fromAppId = getFromAppId(headers);
66 transId = getTransId(headers);
67 } catch (AAIException e) {
68 ArrayList<String> templateVars = new ArrayList<String>();
69 templateVars.add("Headers missing");
71 .status(e.getErrorObject().getHTTPResponseCode()).entity(ErrorLogHelper
72 .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
78 HashMap<AAIException, ArrayList<String>> exceptionList =
79 new HashMap<AAIException, ArrayList<String>>();
81 ArrayList<String> templateVars = new ArrayList<String>();
82 templateVars.add(fromAppId);
83 templateVars.add(transId);
85 exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars);
88 .status(Status.OK).entity(ErrorLogHelper
89 .getRESTAPIInfoResponse(headers.getAcceptableMediaTypes(), exceptionList))
92 } catch (Exception e) {
93 ex = new AAIException("AAI_4000", e);
94 ArrayList<String> templateVars = new ArrayList<String>();
95 templateVars.add(Action.GET.name());
96 templateVars.add(fromAppId + " " + transId);
99 .status(Status.INTERNAL_SERVER_ERROR).entity(ErrorLogHelper
100 .getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), ex, templateVars))
105 ErrorLogHelper.logException(ex);