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.eclipse.jetty.client.api.Request;
24 import org.eclipse.jetty.client.api.Response;
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;
33 import javax.servlet.http.HttpServletResponse;
36 public class KibanaServlet extends ProxyServlet {
37 private static final long serialVersionUID = 1L;
38 private static Logger log = LoggerFactory.getLogger(KibanaServlet.class.getName());
41 public URI rewriteURI(HttpServletRequest request) {
43 String originalUrl = request.getRequestURI();
45 String redirectedUrl = getModifiedUrl(request);
47 log.debug("KibanaServlet Redirecting request from: {} , to: {}", originalUrl, redirectedUrl);
49 return URI.create(redirectedUrl);
53 public void customizeProxyRequest(Request proxyRequest, HttpServletRequest request) {
54 super.customizeProxyRequest(proxyRequest, request);
59 protected void onResponseSuccess(HttpServletRequest request, HttpServletResponse response, Response proxyResponse) {
61 super.onResponseSuccess(request, response, proxyResponse);
64 public String getModifiedUrl(HttpServletRequest request) {
65 Configuration config = getConfiguration(request);
67 log.error("failed to retrive configuration.");
69 // String scheme = request.getScheme();
70 String contextPath = request.getContextPath(); // /mywebapp
71 String servletPath = request.getServletPath(); // /servlet/MyServlet
72 String pathInfo = request.getPathInfo(); // /a/b;c=123
73 String queryString = request.getQueryString(); // d=789
75 StringBuilder url = new StringBuilder();
76 url.append(config.getKibanaProtocol()).append("://").append(config.getKibanaHost());
77 url.append(":").append(config.getKibanaPort());
78 url.append(contextPath).append(servletPath);
80 if (pathInfo != null) {
83 if (queryString != null) {
84 url.append("?").append(queryString);
87 String redirectedUrl = url.toString().replace("/sdc1/kibanaProxy/", "/");
92 private Configuration getConfiguration(HttpServletRequest request) {
93 Configuration config = ((ConfigurationManager) request.getSession().getServletContext()
94 .getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).getConfiguration();