Remove legacy certificate handling
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / servlets / ConfigServlet.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 package org.openecomp.sdc.be.servlets;
21
22 import com.jcabi.aspects.Loggable;
23 import io.swagger.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.media.Content;
25 import io.swagger.v3.oas.annotations.media.Schema;
26 import io.swagger.v3.oas.annotations.responses.ApiResponse;
27 import io.swagger.v3.oas.annotations.servers.Server;
28 import io.swagger.v3.oas.annotations.servers.Servers;
29 import io.swagger.v3.oas.annotations.tags.Tag;
30 import io.swagger.v3.oas.annotations.tags.Tags;
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;
38 import org.openecomp.sdc.be.config.Configuration;
39 import org.openecomp.sdc.common.api.ConfigurationSource;
40 import org.openecomp.sdc.common.api.Constants;
41 import org.openecomp.sdc.common.log.wrappers.Logger;
42 import org.openecomp.sdc.common.servlets.BasicServlet;
43
44 /**
45  * Root resource (exposed at "/" path)
46  */
47 @Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
48 @Path("/config")
49 @Tags({@Tag(name = "SDCE-2 APIs")})
50 @Servers({@Server(url = "/sdc2/rest")})
51 public class ConfigServlet extends BasicServlet {
52
53     private static final Logger log = Logger.getLogger(ConfigServlet.class);
54
55     @GET
56     @Path("/get")
57     @Produces(MediaType.APPLICATION_JSON)
58     @Operation(description = "Retrieve configuration", method = "GET", responses = {
59         @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class)))})
60     public String getConfig(@Context final HttpServletRequest request) {
61         String result = null;
62         ServletContext context = request.getSession().getServletContext();
63         ConfigurationSource configurationSource = (ConfigurationSource) context.getAttribute(Constants.CONFIGURATION_SOURCE_ATTR);
64         if (configurationSource != null) {
65             Configuration configuration = configurationSource.getAndWatchConfiguration(Configuration.class, null);
66             if (configuration == null) {
67                 log.warn("Configuration of type {} was not found", Configuration.class);
68             }
69             log.debug("{}", configuration);
70             log.info("Info level ENABLED...");
71             log.info("The value returned from getConfig is {}", configuration);
72             result = gson.toJson(configuration);
73         } else {
74             log.warn("Source Configuration object was not initialized in the context.");
75         }
76         return result;
77     }
78 }