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.servlets.BasicServlet;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import javax.servlet.ServletContext;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.ws.rs.GET;
34 import javax.ws.rs.Path;
35 import javax.ws.rs.Produces;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
40 * Root resource (exposed at "/" path)
42 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
44 public class ConfigServlet extends BasicServlet {
46 private static final Logger log = LoggerFactory.getLogger(ConfigServlet.class);
50 @Produces(MediaType.APPLICATION_JSON)
51 public String getConfig(@Context final HttpServletRequest request) {
55 ServletContext context = request.getSession().getServletContext();
57 ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
58 if (configurationSource != null) {
59 Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
61 if (configuration == null) {
62 log.warn("Configuration of type {} was not found", Configuration.class);
64 log.debug("{}", configuration);
65 log.info("Info level ENABLED...");
66 log.info("The value returned from getConfig is {}", configuration);
68 result = gson.toJson(configuration);
71 log.warn("Source Configuration object was not initialized in the context.");