org.eclipse.jetty.server.handler

## Class ShutdownHandler

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.util.component.AggregateLifeCycle
    - - org.eclipse.jetty.server.handler.AbstractHandler
      - - org.eclipse.jetty.server.handler.ShutdownHandler

- All Implemented Interfaces:
    Handler, Destroyable, Dumpable, LifeCycle

      public class ShutdownHandler
      extends AbstractHandler

  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. This handler is a contribution from Johannes Brodwall: https://bugs.eclipse.org/bugs/show_bug.cgi?id=357687 Usage:

          Server server = new Server(8080);
          HandlerList handlers = new HandlerList();
          handlers.setHandlers(new Handler[]
          { someOtherHandler, new ShutdownHandler(server,"secret password") });
          server.setHandler(handlers);
          server.start();

         public static void attemptShutdown(int port, String shutdownCookie) {
              try {
                  URL url = new URL("http://localhost:" + port + "/shutdown?cookie=" + shutdownCookie);
                  HttpURLConnection connection = (HttpURLConnection)url.openConnection();
                  connection.setRequestMethod("POST");
                  connection.getResponseCode();
                  logger.info("Shutting down " + url + ": " + connection.getResponseMessage());
              } catch (SocketException e) {
                  logger.debug("Not running");
                  // Okay - the server is not running
              } catch (IOException e) {
                  throw new RuntimeException(e);
              }
          }

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `AbstractLifeCycle.AbstractLifeCycleListener`

    - ### Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `LifeCycle.Listener`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShutdownHandler(Server server, java.lang.String shutdownToken)` Creates a listener that lets the server be shut down remotely (but only from localhost).

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected java.lang.String` | `getRemoteAddr(javax.servlet.http.HttpServletRequest request)`
    `void` | `handle(java.lang.String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Handle a request.
    `void` | `setExitJvm(boolean exitJvm)`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

      `destroy, doStart, doStop, dumpThis, getServer, setServer`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

      `addBean, addBean, contains, dump, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

- - ### Constructor Detail

    - #### ShutdownHandler

          public ShutdownHandler(Server server,
                         java.lang.String shutdownToken)

      Creates a listener that lets the server be shut down remotely (but only from localhost).
      Parameters:
        `server` - the Jetty instance that should be shut down
        `shutdownToken` - a secret password to avoid unauthorized shutdown attempts

  - ### Method Detail

    - #### handle

          public void handle(java.lang.String target,
                    Request baseRequest,
                    javax.servlet.http.HttpServletRequest request,
                    javax.servlet.http.HttpServletResponse response)
                      throws java.io.IOException,
                             javax.servlet.ServletException

      Description copied from interface: `Handler`
      Handle a request.
      Parameters:
        `target` - The target of the request - either a URI or a name.
        `baseRequest` - The original unwrapped request object.
        `request` - The request either as the `Request` object or a wrapper of that request. The `AbstractHttpConnection.getCurrentConnection()` method can be used access the Request object if required.
        `response` - The response as the `Response` object or a wrapper of that request. The `AbstractHttpConnection.getCurrentConnection()` method can be used access the Response object if required.
      Throws:
        `java.io.IOException`
        `javax.servlet.ServletException`

    - #### getRemoteAddr

          protected java.lang.String getRemoteAddr(javax.servlet.http.HttpServletRequest request)

    - #### setExitJvm

          public void setExitJvm(boolean exitJvm)

Copyright © 2013 FuseSource, Corp.. All Rights Reserved.