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.exception.NotFoundException;
25 import org.openecomp.sdc.fe.config.ConfigurationManager;
26 import org.openecomp.sdc.fe.config.FeEcompErrorManager;
27 import org.openecomp.sdc.fe.config.WorkspaceConfiguration;
28 import org.openecomp.sdc.fe.impl.PluginStatusBL;
29 import org.owasp.esapi.ESAPI;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import javax.servlet.ServletContext;
34 import javax.servlet.http.HttpServletRequest;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.core.Context;
40 import javax.ws.rs.core.MediaType;
41 import javax.ws.rs.core.Response;
42 import javax.ws.rs.core.Response.Status;
45 * Root resource (exposed at "/" path)
48 public class ConfigServlet extends LoggingServlet {
50 private static final Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
51 public static final String UNEXPECTED_FE_RESPONSE_LOGGING_ERROR = "Unexpected FE response logging error :";
52 public static final String ERROR_FE_RESPONSE = "FE Response";
55 @Path("/ui/workspace")
56 @Produces(MediaType.APPLICATION_JSON)
57 public Response getUIWorkspaceConfiguration(@Context final HttpServletRequest request) {
60 logFeRequest(request);
62 ServletContext context = request.getSession().getServletContext();
64 ConfigurationManager configurationManager = (ConfigurationManager) context
65 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR);
67 WorkspaceConfiguration configuration = configurationManager.getWorkspaceConfiguration();
68 if (configuration == null) {
69 throw new NotFoundException(WorkspaceConfiguration.class.getSimpleName());
71 log.info("The value returned from getConfig is {}", configuration);
72 String result = gson.toJson(configuration);
73 Response response = Response.status(Status.OK).entity(result).build();
74 logFeResponse(request, response);
77 } catch (Exception e) {
78 FeEcompErrorManager.getInstance().logFeHttpLoggingError(ERROR_FE_RESPONSE);
79 log.error(UNEXPECTED_FE_RESPONSE_LOGGING_ERROR, e);
80 return Response.status(Status.INTERNAL_SERVER_ERROR).entity("{}").build();
88 @Produces(MediaType.APPLICATION_JSON)
89 public Response getPluginsConfiguration(@Context final HttpServletRequest request) {
92 logFeRequest(request);
94 ServletContext context = request.getSession().getServletContext();
96 PluginStatusBL pluginStatusBL = (PluginStatusBL) context.getAttribute(Constants.PLUGIN_BL_COMPONENT);
98 String result = pluginStatusBL.getPluginsList();
100 Response response = Response.status(Status.OK).entity(result).build();
102 logFeResponse(request, response);
105 } catch (Exception e) {
106 FeEcompErrorManager.getInstance().logFeHttpLoggingError( ERROR_FE_RESPONSE);
107 log.error(UNEXPECTED_FE_RESPONSE_LOGGING_ERROR, e);
108 return Response.status(Status.INTERNAL_SERVER_ERROR).entity("{}").build();
114 @Path("/ui/plugins/{pluginId}/online")
115 @Produces(MediaType.APPLICATION_JSON)
116 public Response getPluginOnlineState(@PathParam("pluginId") String pluginId, @Context final HttpServletRequest request) {
119 logFeRequest(request);
120 pluginId = ESAPI.encoder().encodeForHTML(pluginId);
121 ServletContext context = request.getSession().getServletContext();
123 PluginStatusBL pluginStatusBL = (PluginStatusBL) context.getAttribute(Constants.PLUGIN_BL_COMPONENT);
125 String result = pluginStatusBL.getPluginAvailability(pluginId);
127 if (result == null) {
128 log.debug("Plugin with pluginId: {} was not found in the configuration", pluginId);
129 return Response.status(Status.NOT_FOUND).entity("Plugin with pluginId:\"" + pluginId + "\" was not found in the configuration").build();
132 Response response = Response.status(Status.OK).entity(result).build();
134 logFeResponse(request, response);
137 } catch (Exception e) {
138 FeEcompErrorManager.getInstance().logFeHttpLoggingError(ERROR_FE_RESPONSE);
139 log.error(UNEXPECTED_FE_RESPONSE_LOGGING_ERROR, e);
140 return Response.status(Status.INTERNAL_SERVER_ERROR).entity("{}").build();
144 protected void inHttpRequest(HttpServletRequest httpRequest) {
145 log.info("{} {} {}", httpRequest.getMethod(), httpRequest.getRequestURI(), httpRequest.getProtocol());
149 * Extracted for purpose of clear method name, for logback %M parameter
151 * @param response http response
153 protected void outHttpResponse(Response response) {
154 log.info("SC=\"{}\"", response.getStatus());