2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.sdc.fe.servlets;
23 import java.util.concurrent.TimeUnit;
25 import javax.servlet.ServletContext;
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.container.AsyncResponse;
31 import javax.ws.rs.container.Suspended;
32 import javax.ws.rs.container.TimeoutHandler;
33 import javax.ws.rs.core.Context;
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.openecomp.sdc.common.api.ConfigurationSource;
39 import org.openecomp.sdc.common.api.Constants;
40 import org.openecomp.sdc.common.servlets.BasicServlet;
41 import org.openecomp.sdc.fe.config.Configuration;
42 import org.openecomp.sdc.fe.impl.PluginStatusBL;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
47 * Root resource (exposed at "/" path)
50 public class ConfigServlet extends BasicServlet {
52 private static final long serialVersionUID = 1L;
53 private static Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
57 //@Produces(MediaType.APPLICATION_JSON)
58 public String getConfig(@Context final HttpServletRequest request) {
62 ServletContext context = request.getSession().getServletContext();
64 ConfigurationSource configurationSource = (ConfigurationSource) context
65 .getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
66 if (configurationSource != null) {
67 Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
69 if (configuration == null) {
70 log.warn("Configuration of type {} was not found", Configuration.class);
72 log.debug("{}", configuration);
73 if (log.isInfoEnabled()) {
74 log.info("Info level ENABLED...");
76 log.info("The value returned from getConfig is {}", configuration);
78 result = gson.toJson(configuration);
81 log.warn("Source Configuration object was not initialized in the context.");
90 public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
92 asyncResponse.setTimeoutHandler(new TimeoutHandler() {
95 public void handleTimeout(AsyncResponse asyncResponse) {
97 Response.status(Response.Status.SERVICE_UNAVAILABLE).entity("Operation time out.").build());
100 asyncResponse.setTimeout(3, TimeUnit.SECONDS);
102 new Thread(new Runnable() {
105 String result = veryExpensiveOperation();
106 asyncResponse.resume(result);
109 private String veryExpensiveOperation() {
111 return "veryExpensiveOperation SUCCESS";
119 @Produces(MediaType.APPLICATION_JSON)
120 public Response getPluginsConfiguration(@Context final HttpServletRequest request) {
121 String result = null;
123 ServletContext context = request.getSession().getServletContext();
125 PluginStatusBL pluginStatusBL = (PluginStatusBL) context.getAttribute(Constants.PLUGIN_BL_COMPONENT);
127 result = pluginStatusBL.checkPluginsListAvailability();
129 return Response.status(Status.OK).entity(result).build();