2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.rest.util;
24 import java.util.ArrayList;
25 import java.util.HashMap;
27 import javax.servlet.http.HttpServletRequest;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.Produces;
31 import javax.ws.rs.QueryParam;
32 import javax.ws.rs.core.Context;
33 import javax.ws.rs.core.HttpHeaders;
34 import javax.ws.rs.core.MediaType;
35 import javax.ws.rs.core.Response;
36 import javax.ws.rs.core.Response.Status;
38 import org.onap.aai.exceptions.AAIException;
39 import org.onap.aai.logging.ErrorLogHelper;
40 import org.onap.aai.restcore.RESTAPI;
43 * The Class EchoResponse.
46 public class EchoResponse extends RESTAPI {
48 protected static String authPolicyFunctionName = "util";
50 public static final String echoPath = "/echo";
53 * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients.
54 * If there is a query string, a transaction gets logged into hbase, proving the application is connected to the data store.
55 * If there is no query string, no transacction logging is done to hbase.
57 * @param headers the headers
59 * @param myAction if exists will cause transaction to be logged to hbase
60 * @return the response
63 @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
65 public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req,
66 @QueryParam("action") String myAction) {
67 Response response = null;
69 AAIException ex = null;
70 String fromAppId = null;
71 String transId = null;
74 fromAppId = getFromAppId(headers );
75 transId = getTransId(headers);
76 } catch (AAIException e) {
77 ArrayList<String> templateVars = new ArrayList<String>();
78 templateVars.add("PUT uebProvider");
79 templateVars.add("addTopic");
81 .status(e.getErrorObject().getHTTPResponseCode())
82 .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
88 HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<AAIException, ArrayList<String>>();
90 ArrayList<String> templateVars = new ArrayList<String>();
91 templateVars.add(fromAppId);
92 templateVars.add(transId);
94 exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars);
96 response = Response.status(Status.OK)
97 .entity(ErrorLogHelper.getRESTAPIInfoResponse(
98 headers.getAcceptableMediaTypes(), exceptionList))
101 } catch (Exception e) {
102 ex = new AAIException("AAI_4000", e);
103 ArrayList<String> templateVars = new ArrayList<String>();
104 templateVars.add(Action.GET.name());
105 templateVars.add(fromAppId +" "+transId);
108 .status(Status.INTERNAL_SERVER_ERROR)
109 .entity(ErrorLogHelper.getRESTAPIErrorResponse(
110 headers.getAcceptableMediaTypes(), ex,
111 templateVars)).build();
115 ErrorLogHelper.logException(ex);