2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdc.fe.servlets;
25 import org.eclipse.jetty.proxy.ProxyServlet;
26 import org.openecomp.sdc.common.api.Constants;
27 import org.openecomp.sdc.fe.config.Configuration;
28 import org.openecomp.sdc.fe.config.ConfigurationManager;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 import javax.servlet.http.HttpServletRequest;
34 public class KibanaServlet extends ProxyServlet {
36 private static final long serialVersionUID = 1L;
37 private static final Logger LOGGER = LoggerFactory.getLogger(KibanaServlet.class.getName());
40 public String rewriteTarget(HttpServletRequest request) {
41 String originalUrl = request.getRequestURI();
42 String redirectedUrl = getModifiedUrl(request);
44 LOGGER.debug("KibanaServlet Redirecting request from: {} , to: {}", originalUrl, redirectedUrl);
49 public String getModifiedUrl(HttpServletRequest request) {
50 Configuration config = getConfiguration(request);
53 LOGGER.error("Failed to retrieve configuration.");
54 throw new NullPointerException("Failed to retrieve configuration.");
57 String contextPath = request.getContextPath();
58 String servletPath = request.getServletPath();
59 String pathInfo = request.getPathInfo();
60 String queryString = request.getQueryString();
62 StringBuilder url = new StringBuilder();
63 url.append(config.getKibanaProtocol()).append("://").append(config.getKibanaHost());
64 url.append(":").append(config.getKibanaPort());
65 url.append(contextPath).append(servletPath);
67 if (pathInfo != null) {
71 if (queryString != null) {
72 url.append("?").append(queryString);
75 return url.toString().replace("/sdc1/kibanaProxy/", "/");
78 private Configuration getConfiguration(HttpServletRequest request) {
79 return ((ConfigurationManager) request.getSession().getServletContext()
80 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).getConfiguration();