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