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.fe.servlets;
23 import org.openecomp.sdc.common.api.Constants;
24 import org.openecomp.sdc.common.log.wrappers.Logger;
25 import org.openecomp.sdc.common.rest.api.RestConfigurationInfo;
26 import org.openecomp.sdc.common.servlets.BasicServlet;
27 import org.openecomp.sdc.fe.config.Configuration;
28 import org.openecomp.sdc.fe.config.ConfigurationManager;
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.QueryParam;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
40 * Root resource (exposed at "/" path)
43 public class ConfigMgrServlet extends BasicServlet {
45 private static Logger log = Logger.getLogger(ConfigMgrServlet.class.getName());
49 @Produces(MediaType.APPLICATION_JSON)
50 public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
54 ServletContext context = request.getSession().getServletContext();
56 ConfigurationManager configurationManager = (ConfigurationManager) context
57 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
59 if (type == null || type.equals("configuration")) {
61 Configuration configuration = configurationManager.getConfiguration();
62 if (configuration == null) {
63 log.warn("Configuration of type {} was not found", Configuration.class);
65 log.info("The value returned from getConfig is {}", configuration);
67 result = gson.toJson(configuration);
70 } else if (type.equals("rest")) {
72 RestConfigurationInfo configuration = configurationManager.getRestClientConfiguration();
73 if (configuration == null) {
74 log.warn("Configuration of type {} was not found", RestConfigurationInfo.class);
76 log.info("The value returned from getConfig is {}", configuration);
78 result = gson.toJson(configuration);