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.rest.util;
22 import java.util.ArrayList;
23 import java.util.HashMap;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.QueryParam;
30 import javax.ws.rs.core.Context;
31 import javax.ws.rs.core.HttpHeaders;
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
34 import javax.ws.rs.core.Response.Status;
36 import org.onap.aai.exceptions.AAIException;
37 import org.onap.aai.logging.ErrorLogHelper;
38 import org.onap.aai.restcore.RESTAPI;
41 * The Class EchoResponse.
44 public class EchoResponse extends RESTAPI {
46 protected static String authPolicyFunctionName = "util";
48 public static final String echoPath = "/echo";
51 * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients.
52 * If there is a query string, a transaction gets logged into hbase, proving the application is connected to the data store.
53 * If there is no query string, no transacction logging is done to hbase.
55 * @param headers the headers
57 * @param myAction if exists will cause transaction to be logged to hbase
58 * @return the response
61 @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
63 public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req,
64 @QueryParam("action") String myAction) {
65 Response response = null;
67 AAIException ex = null;
68 String fromAppId = null;
69 String transId = null;
72 fromAppId = getFromAppId(headers );
73 transId = getTransId(headers);
74 } catch (AAIException e) {
75 ArrayList<String> templateVars = new ArrayList<String>();
76 templateVars.add("PUT uebProvider");
77 templateVars.add("addTopic");
79 .status(e.getErrorObject().getHTTPResponseCode())
80 .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
86 HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<AAIException, ArrayList<String>>();
88 ArrayList<String> templateVars = new ArrayList<String>();
89 templateVars.add(fromAppId);
90 templateVars.add(transId);
92 exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars);
94 response = Response.status(Status.OK)
95 .entity(ErrorLogHelper.getRESTAPIInfoResponse(
96 headers.getAcceptableMediaTypes(), exceptionList))
99 } catch (Exception e) {
100 ex = new AAIException("AAI_4000", e);
101 ArrayList<String> templateVars = new ArrayList<String>();
102 templateVars.add(Action.GET.name());
103 templateVars.add(fromAppId +" "+transId);
106 .status(Status.INTERNAL_SERVER_ERROR)
107 .entity(ErrorLogHelper.getRESTAPIErrorResponse(
108 headers.getAcceptableMediaTypes(), ex,
109 templateVars)).build();
113 ErrorLogHelper.logException(ex);