public class ShutdownHandler extends HandlerWrapper
Server server = new Server(8080);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]
{ someOtherHandler, new ShutdownHandler("secret password", false, true) });
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);
}
}
AbstractHandler.ErrorDispatchHandlerAbstractLifeCycle.AbstractLifeCycleListenerLifeCycle.ListenerContainer.InheritedListener, Container.Listener| Modifier and Type | Field and Description |
|---|---|
private boolean |
_exitJvm |
private boolean |
_sendShutdownAtStart |
private java.lang.String |
_shutdownToken |
private static Logger |
LOG |
_handlerFAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING| Constructor and Description |
|---|
ShutdownHandler(Server server,
java.lang.String shutdownToken)
Deprecated.
|
ShutdownHandler(java.lang.String shutdownToken) |
ShutdownHandler(java.lang.String shutdownToken,
boolean exitJVM,
boolean sendShutdownAtStart) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doShutdown(Request baseRequest,
javax.servlet.http.HttpServletResponse response) |
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
private java.lang.String |
getServerUrl() |
java.lang.String |
getShutdownToken() |
void |
handle(java.lang.String target,
Request baseRequest,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a request.
|
private boolean |
hasCorrectSecurityToken(javax.servlet.http.HttpServletRequest request) |
boolean |
isExitJvm() |
boolean |
isSendShutdownAtStart() |
private boolean |
requestFromLocalhost(Request request) |
void |
sendShutdown() |
void |
setExitJvm(boolean exitJvm) |
void |
setSendShutdownAtStart(boolean sendShutdownAtStart) |
private void |
shutdownServer(Server server) |
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandlerexpandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServerdoError, doStop, dumpThis, getServeraddBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansaddLifeCycleListener, getState, getState, getStopTimeout, 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, start, stop, stopprivate static final Logger LOG
private final java.lang.String _shutdownToken
private boolean _sendShutdownAtStart
private boolean _exitJvm
@Deprecated public ShutdownHandler(Server server, java.lang.String shutdownToken)
server - the Jetty instance that should be shut downshutdownToken - a secret password to avoid unauthorized shutdown attemptspublic ShutdownHandler(java.lang.String shutdownToken)
public ShutdownHandler(java.lang.String shutdownToken,
boolean exitJVM,
boolean sendShutdownAtStart)
shutdownToken - a secret password to avoid unauthorized shutdown attemptsexitJVM - If true, when the shutdown is executed, the handler class System.exit()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 ShutdownHandlerpublic void sendShutdown()
throws java.io.IOException
java.io.IOExceptionprivate java.lang.String getServerUrl()
protected void doStart()
throws java.lang.Exception
ContainerLifeCycledoStart in class AbstractHandlerjava.lang.Exceptionpublic 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
Handlerhandle in interface Handlerhandle in class HandlerWrappertarget - 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
HttpConnection.getCurrentConnection().getHttpChannel().getRequest()
method can be used access the Request object if required.response - The response as the Response object or a wrapper of that request. The
HttpConnection.getCurrentConnection().getHttpChannel().getResponse()
method can be used access the Response object if required.java.io.IOException - if unable to handle the request or response processingjavax.servlet.ServletException - if unable to handle the request or response due to underlying servlet issueprotected void doShutdown(Request baseRequest, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
java.io.IOExceptionprivate boolean requestFromLocalhost(Request request)
private boolean hasCorrectSecurityToken(javax.servlet.http.HttpServletRequest request)
private void shutdownServer(Server server) throws java.lang.Exception
java.lang.Exceptionpublic void setExitJvm(boolean exitJvm)
public boolean isSendShutdownAtStart()
public void setSendShutdownAtStart(boolean sendShutdownAtStart)
public java.lang.String getShutdownToken()
public boolean isExitJvm()