1 /*******************************************************************************
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
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.service;
24 import java.io.IOException;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.PathParam;
31 import javax.ws.rs.core.Context;
33 import org.apache.kafka.common.errors.TopicExistsException;
35 import org.apache.http.HttpStatus;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.beans.factory.annotation.Qualifier;
41 import org.springframework.stereotype.Component;
43 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
44 import org.onap.dmaap.dmf.mr.service.UIService;
45 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
46 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
47 import com.att.nsa.configs.ConfigDbException;
51 * @author rajashree.khare
55 public class UIRestServices {
60 //private static final Logger LOGGER = Logger.getLogger(UIRestServices.class);
62 private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(UIRestServices.class);
65 private UIService uiService;
71 @Qualifier("configurationReader")
72 private ConfigurationReader configReader;
75 * HttpServletRequest obj
78 private HttpServletRequest request;
81 * HttpServletResponse obj
84 private HttpServletResponse response;
93 LOGGER.info("Calling hello page.");
95 uiService.hello(getDmaapContext());
97 LOGGER.info("Hello page is returned.");
98 } catch (IOException excp) {
99 LOGGER.error("Error while calling hello page: " + excp.getMessage(), excp);
100 DMaaPResponseBuilder.respondWithError(getDmaapContext(), HttpStatus.SC_NOT_FOUND,
101 "Error while calling hello page: " + excp.getMessage());
110 public void getApiKeysTable() {
112 LOGGER.info("Fetching list of all api keys.");
114 uiService.getApiKeysTable(getDmaapContext());
116 LOGGER.info("Returning list of all api keys.");
117 } catch (ConfigDbException | IOException excp) {
118 LOGGER.error("Error while fetching list of all api keys: " + excp.getMessage(), excp);
119 DMaaPResponseBuilder.respondWithError(getDmaapContext(), HttpStatus.SC_NOT_FOUND,
120 "Error while fetching list of all api keys: " + excp.getMessage());
128 * @exception Exception
131 @Path("/ui/apikeys/{apiKey}")
132 public void getApiKey(@PathParam("apiKey") String apiKey) {
134 LOGGER.info("Fetching details of api key: " + apiKey);
136 uiService.getApiKey(getDmaapContext(), apiKey);
138 LOGGER.info("Returning details of api key: " + apiKey);
139 } catch (Exception excp) {
140 LOGGER.error("Error while fetching details of api key: " + apiKey, excp);
141 DMaaPResponseBuilder.respondWithError(getDmaapContext(), HttpStatus.SC_NOT_FOUND,
142 "Error while fetching details of api key: " + apiKey);
148 public void getTopicsTable() {
150 LOGGER.info("Fetching list of all topics.");
152 uiService.getTopicsTable(getDmaapContext());
154 LOGGER.info("Returning list of all topics.");
155 } catch (ConfigDbException | IOException excp) {
156 LOGGER.error("Error while fetching list of all topics: " + excp, excp);
157 DMaaPResponseBuilder.respondWithError(getDmaapContext(), HttpStatus.SC_NOT_FOUND,
158 "Error while fetching list of all topics: " + excp.getMessage());
167 @Path("/ui/topics/{topic}")
168 public void getTopic(@PathParam("topic") String topic) {
170 LOGGER.info("Fetching details of topic: " + topic);
172 uiService.getTopic(getDmaapContext(), topic);
174 LOGGER.info("Returning details of topic: " + topic);
175 } catch (ConfigDbException | IOException | TopicExistsException excp) {
176 LOGGER.error("Error while fetching details of topic: " + topic, excp);
177 DMaaPResponseBuilder.respondWithError(getDmaapContext(), HttpStatus.SC_NOT_FOUND,
178 "Error while fetching details of topic: " + topic);
183 * This method is used for taking Configuration Object,HttpServletRequest
184 * Object,HttpServletRequest HttpServletResponse Object,HttpServletSession
187 * @return DMaaPContext object from where user can get Configuration
188 * Object,HttpServlet Object
191 private DMaaPContext getDmaapContext() {
192 DMaaPContext dmaapContext = new DMaaPContext();
193 dmaapContext.setConfigReader(configReader);
194 dmaapContext.setRequest(request);
195 dmaapContext.setResponse(response);