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.be.servlets;
23 import com.jcabi.aspects.Loggable;
24 import org.openecomp.sdc.be.config.Configuration;
25 import org.openecomp.sdc.common.api.ConfigurationSource;
26 import org.openecomp.sdc.common.api.Constants;
27 import org.openecomp.sdc.common.log.wrappers.Logger;
28 import org.openecomp.sdc.common.servlets.BasicServlet;
30 import javax.servlet.ServletContext;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.core.Context;
36 import javax.ws.rs.core.MediaType;
39 * Root resource (exposed at "/" path)
41 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
43 public class ConfigServlet extends BasicServlet {
45 private static final Logger log = Logger.getLogger(ConfigServlet.class);
49 @Produces(MediaType.APPLICATION_JSON)
50 public String getConfig(@Context final HttpServletRequest request) {
54 ServletContext context = request.getSession().getServletContext();
56 ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
57 if (configurationSource != null) {
58 Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
60 if (configuration == null) {
61 log.warn("Configuration of type {} was not found", Configuration.class);
63 log.debug("{}", configuration);
64 log.info("Info level ENABLED...");
65 log.info("The value returned from getConfig is {}", configuration);
67 result = gson.toJson(configuration);
70 log.warn("Source Configuration object was not initialized in the context.");