X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Fserver%2Fhandler%2FShutdownHandler.java;h=6a4daa37ef249aaa308d8afa9e3439bb6d114a1a;hp=e946fb670e704b5822a7431f8335116bbba1e5b2;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=875b5e9651498a0cd8e0001c0742ba843e47cad0 diff --git a/lib/jetty/org/eclipse/jetty/server/handler/ShutdownHandler.java b/lib/jetty/org/eclipse/jetty/server/handler/ShutdownHandler.java index e946fb67..6a4daa37 100644 --- a/lib/jetty/org/eclipse/jetty/server/handler/ShutdownHandler.java +++ b/lib/jetty/org/eclipse/jetty/server/handler/ShutdownHandler.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 @@ -37,8 +37,12 @@ import org.eclipse.jetty.util.log.Logger; /* ------------------------------------------------------------ */ /** - * A handler that shuts the server down on a valid request. Used to do "soft" restarts from Java. If _exitJvm ist set to true a hard System.exit() call is being - * made. + * A handler that shuts the server down on a valid request. Used to do "soft" restarts from Java. + * If _exitJvm is set to true a hard System.exit() call is being made. + * If _sendShutdownAtStart is set to true, starting the server will try to shut down an existing server at the same port. + * If _sendShutdownAtStart is set to true, make a http call to + * "http://localhost:" + port + "/shutdown?token=" + shutdownCookie + * in order to shut down the server. * * This handler is a contribution from Johannes Brodwall: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357687 * @@ -48,7 +52,7 @@ import org.eclipse.jetty.util.log.Logger; Server server = new Server(8080); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] - { someOtherHandler, new ShutdownHandler("secret password") }); + { someOtherHandler, new ShutdownHandler("secret password", false, true) }); server.setHandler(handlers); server.start(); @@ -100,9 +104,11 @@ public class ShutdownHandler extends HandlerWrapper /** * @param shutdownToken + * a secret password to avoid unauthorized shutdown attempts + * @param exitJVM If true, when the shutdown is executed, the handler class System.exit() * @param sendShutdownAtStart If true, a shutdown is sent as a HTTP post - * during startup, which will shutdown any previously running instances of - * this server with an identically configured ShutdownHandler + * during startup, which will shutdown any previously running instances of + * this server with an identically configured ShutdownHandler */ public ShutdownHandler(String shutdownToken, boolean exitJVM, boolean sendShutdownAtStart) { @@ -120,7 +126,7 @@ public class ShutdownHandler extends HandlerWrapper HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setRequestMethod("POST"); connection.getResponseCode(); - LOG.info("Shutting down " + url + ": " + connection.getResponseMessage()); + LOG.info("Shutting down " + url + ": " + connection.getResponseCode() + " " + connection.getResponseMessage()); } catch (SocketException e) { @@ -133,6 +139,7 @@ public class ShutdownHandler extends HandlerWrapper } } + @SuppressWarnings("resource") private String getServerUrl() { NetworkConnector connector=null; @@ -188,6 +195,16 @@ public class ShutdownHandler extends HandlerWrapper } LOG.info("Shutting down by request from " + request.getRemoteAddr()); + doShutdown(baseRequest, response); + } + + protected void doShutdown(Request baseRequest, HttpServletResponse response) throws IOException { + for (Connector connector : getServer().getConnectors()) { + connector.shutdown(); + } + + response.sendError(200, "Connectors closed, commencing full shutdown"); + baseRequest.setHandled(true); final Server server=getServer(); new Thread() @@ -224,7 +241,8 @@ public class ShutdownHandler extends HandlerWrapper private boolean hasCorrectSecurityToken(HttpServletRequest request) { String tok = request.getParameter("token"); - LOG.debug("Token: {}", tok); + if (LOG.isDebugEnabled()) + LOG.debug("Token: {}", tok); return _shutdownToken.equals(tok); }