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=========================================================
20 package org.onap.aai.schemaservice.healthcheck;
22 import org.onap.aai.exceptions.AAIException;
23 import org.onap.aai.logging.ErrorLogHelper;
24 import org.onap.aai.restcore.RESTAPI;
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;
32 import java.util.ArrayList;
33 import java.util.HashMap;
36 * The Class EchoResponse.
39 public class EchoResource extends RESTAPI {
42 * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients.
43 * If there is a query string, a transaction gets logged into hbase, proving the application is connected to the data store.
44 * If there is no query string, no transaction logging is done to hbase.
46 * @param headers the headers
48 * @return the response
51 @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
53 public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req, @Context UriInfo uriInfo) {
54 Response response = null;
56 AAIException ex = null;
57 String fromAppId = null;
58 String transId = null;
61 fromAppId = getFromAppId(headers );
62 transId = getTransId(headers);
63 } catch (AAIException e) {
64 ArrayList<String> templateVars = new ArrayList<String>();
65 templateVars.add("Headers missing");
67 .status(e.getErrorObject().getHTTPResponseCode())
68 .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
74 HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<AAIException, ArrayList<String>>();
76 ArrayList<String> templateVars = new ArrayList<String>();
77 templateVars.add(fromAppId);
78 templateVars.add(transId);
80 exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars);
82 response = Response.status(Status.OK)
83 .entity(ErrorLogHelper.getRESTAPIInfoResponse(
84 headers.getAcceptableMediaTypes(), exceptionList))
87 } catch (Exception e) {
88 ex = new AAIException("AAI_4000", e);
89 ArrayList<String> templateVars = new ArrayList<String>();
90 templateVars.add(Action.GET.name());
91 templateVars.add(fromAppId +" "+transId);
94 .status(Status.INTERNAL_SERVER_ERROR)
95 .entity(ErrorLogHelper.getRESTAPIErrorResponse(
96 headers.getAcceptableMediaTypes(), ex,
97 templateVars)).build();
101 ErrorLogHelper.logException(ex);