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 io.swagger.annotations.Api;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
29 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
30 import org.openecomp.sdc.be.config.Configuration;
31 import org.openecomp.sdc.common.api.ConfigurationSource;
32 import org.openecomp.sdc.common.api.Constants;
33 import org.openecomp.sdc.common.log.wrappers.Logger;
34 import org.openecomp.sdc.common.servlets.BasicServlet;
36 import javax.servlet.ServletContext;
37 import javax.servlet.http.HttpServletRequest;
38 import javax.ws.rs.GET;
39 import javax.ws.rs.Path;
40 import javax.ws.rs.Produces;
41 import javax.ws.rs.core.Context;
42 import javax.ws.rs.core.MediaType;
45 * Root resource (exposed at "/" path)
47 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
49 @Api(value = "Get configuration", description = "Get configuration")
50 public class ConfigServlet extends BasicServlet {
52 private static final Logger log = Logger.getLogger(ConfigServlet.class);
56 @Produces(MediaType.APPLICATION_JSON)
57 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
58 @ApiOperation(value = "Retrieve configuration", httpMethod = "GET", notes = "Returns configuration", response = String.class)
59 @ApiResponses(value = { @ApiResponse(code = 200, message = "OK") })
60 public String getConfig(@Context final HttpServletRequest request) {
64 ServletContext context = request.getSession().getServletContext();
66 ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
67 if (configurationSource != null) {
68 Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
70 if (configuration == null) {
71 log.warn("Configuration of type {} was not found", Configuration.class);
73 log.debug("{}", configuration);
74 log.info("Info level ENABLED...");
75 log.info("The value returned from getConfig is {}", configuration);
77 result = gson.toJson(configuration);
80 log.warn("Source Configuration object was not initialized in the context.");