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.
45 public class EchoResponse extends RESTAPI {
47 protected static String authPolicyFunctionName = "util";
49 public static final String echoPath = "/util/echo";
52 * Simple health-check API that echos back the X-FromAppId and X-TransactionId to clients.
53 * If there is a query string, a transaction gets logged into hbase, proving the application is connected to the data store.
54 * If there is no query string, no transacction logging is done to hbase.
56 * @param headers the headers
58 * @param myAction if exists will cause transaction to be logged to hbase
59 * @return the response
62 @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
64 public Response echoResult(@Context HttpHeaders headers, @Context HttpServletRequest req,
65 @QueryParam("action") String myAction) {
66 Response response = null;
68 AAIException ex = null;
69 String fromAppId = null;
70 String transId = null;
73 fromAppId = getFromAppId(headers );
74 transId = getTransId(headers);
75 } catch (AAIException e) {
76 ArrayList<String> templateVars = new ArrayList<String>();
77 templateVars.add("PUT uebProvider");
78 templateVars.add("addTopic");
80 .status(e.getErrorObject().getHTTPResponseCode())
81 .entity(ErrorLogHelper.getRESTAPIErrorResponse(headers.getAcceptableMediaTypes(), e, templateVars))
87 HashMap<AAIException, ArrayList<String>> exceptionList = new HashMap<AAIException, ArrayList<String>>();
89 ArrayList<String> templateVars = new ArrayList<String>();
90 templateVars.add(fromAppId);
91 templateVars.add(transId);
93 exceptionList.put(new AAIException("AAI_0002", "OK"), templateVars);
95 response = Response.status(Status.OK)
96 .entity(ErrorLogHelper.getRESTAPIInfoResponse(
97 headers.getAcceptableMediaTypes(), exceptionList))
100 } catch (Exception e) {
101 ex = new AAIException("AAI_4000", e);
102 ArrayList<String> templateVars = new ArrayList<String>();
103 templateVars.add(Action.GET.name());
104 templateVars.add(fromAppId +" "+transId);
107 .status(Status.INTERNAL_SERVER_ERROR)
108 .entity(ErrorLogHelper.getRESTAPIErrorResponse(
109 headers.getAcceptableMediaTypes(), ex,
110 templateVars)).build();
114 ErrorLogHelper.logException(ex);