public class ShutdownHandler extends AbstractHandler
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?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);
}
}
AbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.Listener_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING| Constructor and Description |
|---|
ShutdownHandler(Server server,
String shutdownToken)
Creates a listener that lets the server be shut down remotely (but only from localhost).
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
getRemoteAddr(javax.servlet.http.HttpServletRequest request) |
void |
handle(String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a request.
|
void |
setExitJvm(boolean exitJvm) |
destroy, doStart, doStop, dumpThis, getServer, setServeraddBean, addBean, contains, dump, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanageaddLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stoppublic ShutdownHandler(Server server, String shutdownToken)
server - the Jetty instance that should be shut downshutdownToken - a secret password to avoid unauthorized shutdown attemptspublic void handle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException, javax.servlet.ServletException
Handlertarget - 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.IOExceptionjavax.servlet.ServletExceptionprotected String getRemoteAddr(javax.servlet.http.HttpServletRequest request)
public void setExitJvm(boolean exitJvm)
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.