Version: 9.4.5.v20170502 |

Shutdown Handler
Previous | Chapter 18. Provided Servlets, Filters, and Handlers Home | Next

##### Contact the core Jetty developers at www.webtide.com

private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development

## Shutdown Handler

### Info

- Classname: `org.eclipse.jetty.server.handler.ShutdownHandler`
- Maven Artifact: org.eclipse.jetty:jetty-server
- Javadoc: http://www.eclipse.org/jetty/javadoc/9.4.5.v20170502/org/eclipse/jetty/server/handler/ShutdownHandler.html
- Xref: http://download.eclipse.org/jetty/stable-9/xref/org/eclipse/jetty/server/handler/ShutdownHandler.html

### Usage

A handler that shuts the server down on a valid request. This is used to perform "soft" restarts from Java. If `_exitJvm` is set to true a hard `System.exit()` call is being made.

This is an example of how you can setup this handler directly with the Server. It can also be added as a part of handler chain or collection.

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

This is an example that you can use to call the shutdown handler from within java.

       public static void attemptShutdown(int port, String shutdownCookie) {
            try {
                URL url = new URL("http://localhost:" + port + "/shutdown?token=" + 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);
            }
        }

Previous | Top | Next
Moved Context Handler | Home | Default Handler

See an error or something missing? Contribute to this documentation at Github!(Generated: 2017-05-02)