fix swagger issue
[sdc.git] / catalog-fe / src / main / java / org / openecomp / sdc / fe / 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
21 package org.openecomp.sdc.fe.servlets;
22
23 import org.openecomp.sdc.common.api.Constants;
24 import org.openecomp.sdc.fe.config.FeEcompErrorManager;
25 import org.openecomp.sdc.fe.impl.PluginStatusBL;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.ws.rs.GET;
32 import javax.ws.rs.Path;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.core.Context;
35 import javax.ws.rs.core.MediaType;
36 import javax.ws.rs.core.Response;
37 import javax.ws.rs.core.Response.Status;
38
39 /**
40  * Root resource (exposed at "/" path)
41  */
42 @Path("/config")
43 public class ConfigServlet extends LoggingServlet {
44
45         private static final Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
46
47
48         @GET
49         @Path("/ui/plugins")
50         @Produces(MediaType.APPLICATION_JSON)
51         public Response getPluginsConfiguration(@Context final HttpServletRequest request) {
52
53                 try {
54                         logFeRequest(request);
55
56                         ServletContext context = request.getSession().getServletContext();
57
58                         PluginStatusBL pluginStatusBL = (PluginStatusBL) context.getAttribute(Constants.PLUGIN_BL_COMPONENT);
59
60             String result = pluginStatusBL.checkPluginsListAvailability();
61
62                         Response response = Response.status(Status.OK).entity(result).build();
63
64                         logFeResponse(request, response);
65
66                         return response;
67                 } catch (Exception e) {
68                         FeEcompErrorManager.getInstance().logFeHttpLoggingError("FE Response");
69                         log.error("Unexpected FE response logging error :", e);
70                         return Response.status(Status.OK).entity(null).build();
71                 }
72
73         }
74
75     protected  void inHttpRequest(HttpServletRequest httpRequest) {
76         log.info("{} {} {}", httpRequest.getMethod(), httpRequest.getRequestURI(), httpRequest.getProtocol());
77     }
78
79     /**
80      * Extracted for purpose of clear method name, for logback %M parameter
81      * @param response http response
82      */
83     protected void outHttpResponse(Response response) {
84         log.info("SC=\"{}\"", response.getStatus());
85     }
86 }