From 5f3f4e0a6066b9c95d08b0d19fe023221b5b9650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Wed, 10 Dec 2014 11:32:22 -0800 Subject: [PATCH] prevent /status from redirect, fixes #953 --- .../io/druid/server/http/RedirectServlet.java | 80 ------------------- .../main/java/io/druid/cli/CliOverlord.java | 8 +- .../CoordinatorJettyServerInitializer.java | 9 ++- 3 files changed, 12 insertions(+), 85 deletions(-) delete mode 100644 server/src/main/java/io/druid/server/http/RedirectServlet.java diff --git a/server/src/main/java/io/druid/server/http/RedirectServlet.java b/server/src/main/java/io/druid/server/http/RedirectServlet.java deleted file mode 100644 index d402d64cddf..00000000000 --- a/server/src/main/java/io/druid/server/http/RedirectServlet.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Druid - a distributed column store. - * Copyright (C) 2012, 2013 Metamarkets Group Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package io.druid.server.http; - -import com.google.inject.Inject; -import com.metamx.common.logger.Logger; -import org.eclipse.jetty.servlet.DefaultServlet; - -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.URL; - -/** - */ -public class RedirectServlet extends DefaultServlet -{ - private static final Logger log = new Logger(RedirectServlet.class); - - private final RedirectInfo redirectInfo; - - @Inject - public RedirectServlet( - RedirectInfo redirectInfo - ) - { - this.redirectInfo = redirectInfo; - } - - @Override - public void service(ServletRequest req, ServletResponse res) - throws ServletException, IOException - { - HttpServletRequest request; - HttpServletResponse response; - - try { - request = (HttpServletRequest) req; - response = (HttpServletResponse) res; - } - catch (ClassCastException e) { - throw new ServletException("non-HTTP request or response"); - } - - if (redirectInfo.doLocal()) { - super.service(request, response); - } else { - final URL redirectURL = redirectInfo.getRedirectURL(request.getQueryString(), request.getRequestURI()); - if (redirectURL == null) { - response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); - } - else { - log.info("Forwarding request to [%s]", redirectURL); - - response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); - response.setHeader("Location", redirectURL.toString()); - } - } - } -} diff --git a/services/src/main/java/io/druid/cli/CliOverlord.java b/services/src/main/java/io/druid/cli/CliOverlord.java index 213e6ca7935..c0be380ac14 100644 --- a/services/src/main/java/io/druid/cli/CliOverlord.java +++ b/services/src/main/java/io/druid/cli/CliOverlord.java @@ -239,11 +239,15 @@ public class CliOverlord extends ServerRunnable } ) ); - root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null); root.addFilter(GzipFilter.class, "/*", null); - // Can't use /* here because of Guice and Jetty static content conflicts + // /status should not redirect, so add first root.addFilter(GuiceFilter.class, "/status/*", null); + + // redirect anything other than status to the current lead + root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null); + + // Can't use /* here because of Guice and Jetty static content conflicts root.addFilter(GuiceFilter.class, "/druid/*", null); HandlerList handlerList = new HandlerList(); diff --git a/services/src/main/java/io/druid/cli/CoordinatorJettyServerInitializer.java b/services/src/main/java/io/druid/cli/CoordinatorJettyServerInitializer.java index 03063d66bfa..9b3a69252cc 100644 --- a/services/src/main/java/io/druid/cli/CoordinatorJettyServerInitializer.java +++ b/services/src/main/java/io/druid/cli/CoordinatorJettyServerInitializer.java @@ -60,13 +60,16 @@ class CoordinatorJettyServerInitializer implements JettyServerInitializer } else { root.setResourceBase(config.getConsoleStatic()); } - - root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null); root.addFilter(GzipFilter.class, "/*", null); + // /status should not redirect, so add first + root.addFilter(GuiceFilter.class, "/status/*", null); + + // redirect anything other than status to the current lead + root.addFilter(new FilterHolder(injector.getInstance(RedirectFilter.class)), "/*", null); + // Can't use '/*' here because of Guice and Jetty static content conflicts // The coordinator really needs a standarized api path - root.addFilter(GuiceFilter.class, "/status/*", null); root.addFilter(GuiceFilter.class, "/info/*", null); root.addFilter(GuiceFilter.class, "/druid/coordinator/*", null); // this will be removed in the next major release