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.v3.oas.annotations.Operation;
25 import io.swagger.v3.oas.annotations.media.Content;
26 import io.swagger.v3.oas.annotations.media.Schema;
27 import io.swagger.v3.oas.annotations.responses.ApiResponse;
28 import io.swagger.v3.oas.annotations.servers.Server;
29 import io.swagger.v3.oas.annotations.servers.Servers;
30 import io.swagger.v3.oas.annotations.tags.Tag;
31 import io.swagger.v3.oas.annotations.tags.Tags;
32 import org.openecomp.sdc.be.components.impl.aaf.AafPermission;
33 import org.openecomp.sdc.be.components.impl.aaf.PermissionAllowed;
34 import org.openecomp.sdc.be.config.Configuration;
35 import org.openecomp.sdc.common.api.ConfigurationSource;
36 import org.openecomp.sdc.common.api.Constants;
37 import org.openecomp.sdc.common.log.wrappers.Logger;
38 import org.openecomp.sdc.common.servlets.BasicServlet;
40 import javax.servlet.ServletContext;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.ws.rs.GET;
43 import javax.ws.rs.Path;
44 import javax.ws.rs.Produces;
45 import javax.ws.rs.core.Context;
46 import javax.ws.rs.core.MediaType;
49 * Root resource (exposed at "/" path)
51 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
53 @Tags({@Tag(name = "SDC Internal APIs")})
54 @Servers({@Server(url = "/sdc2/rest")})
55 public class ConfigServlet extends BasicServlet {
57 private static final Logger log = Logger.getLogger(ConfigServlet.class);
61 @Produces(MediaType.APPLICATION_JSON)
62 @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
63 @Operation(description = "Retrieve configuration", method = "GET", responses = {
64 @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class)))
66 public String getConfig(@Context final HttpServletRequest request) {
70 ServletContext context = request.getSession().getServletContext();
72 ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
73 if (configurationSource != null) {
74 Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
76 if (configuration == null) {
77 log.warn("Configuration of type {} was not found", Configuration.class);
79 log.debug("{}", configuration);
80 log.info("Info level ENABLED...");
81 log.info("The value returned from getConfig is {}", configuration);
83 result = gson.toJson(configuration);
86 log.warn("Source Configuration object was not initialized in the context.");