re base code
[sdc.git] / catalog-fe / src / main / java / org / openecomp / sdc / fe / servlets / ConfigMgrServlet.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.fe.servlets;
22
23 import org.openecomp.sdc.common.api.Constants;
24 import org.openecomp.sdc.common.rest.api.RestConfigurationInfo;
25 import org.openecomp.sdc.common.servlets.BasicServlet;
26 import org.openecomp.sdc.fe.config.Configuration;
27 import org.openecomp.sdc.fe.config.ConfigurationManager;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
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.QueryParam;
37 import javax.ws.rs.core.Context;
38 import javax.ws.rs.core.MediaType;
39
40 /**
41  * Root resource (exposed at "/" path)
42  */
43 @Path("/configmgr")
44 public class ConfigMgrServlet extends BasicServlet {
45
46         private static Logger log = LoggerFactory.getLogger(ConfigMgrServlet.class.getName());
47
48         @GET
49         @Path("/get")
50         @Produces(MediaType.APPLICATION_JSON)
51         public String getConfig(@Context final HttpServletRequest request, @QueryParam("type") String type) {
52
53                 String result = null;
54
55                 ServletContext context = request.getSession().getServletContext();
56
57                 ConfigurationManager configurationManager = (ConfigurationManager) context
58                                 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
59
60                 if (type == null || type.equals("configuration")) {
61
62                         Configuration configuration = configurationManager.getConfiguration();
63                         if (configuration == null) {
64                                 log.warn("Configuration of type {} was not found", Configuration.class);
65                         } else {
66                                 log.info("The value returned from getConfig is {}", configuration);
67
68                                 result = gson.toJson(configuration);
69
70                         }
71                 } else if (type.equals("rest")) {
72
73                         RestConfigurationInfo configuration = configurationManager.getRestClientConfiguration();
74                         if (configuration == null) {
75                                 log.warn("Configuration of type {} was not found", RestConfigurationInfo.class);
76                         } else {
77                                 log.info("The value returned from getConfig is {}", configuration);
78
79                                 result = gson.toJson(configuration);
80
81                         }
82
83                 }
84                 return result;
85
86         }
87
88 }