public class ThreadLimitHandler extends HandlerWrapper
Handler to limit the threads per IP address for DOS protection
The ThreadLimitHandler applies a limit to the number of Threads that can be used simultaneously per remote IP address.
The handler makes a determination of the remote IP separately to
any that may be made by the ForwardedRequestCustomizer
or similar:
This is a simpler alternative to DosFilter
AbstractHandler.ErrorDispatchHandler
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
_handler
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPING
Constructor and Description |
---|
ThreadLimitHandler() |
ThreadLimitHandler(String forwardedHeader) |
ThreadLimitHandler(String forwardedHeader,
boolean rfc7239) |
Modifier and Type | Method and Description |
---|---|
protected void |
doStart()
Starts the managed lifecycle beans in the order they were added.
|
void |
exclude(String inetAddressPattern) |
protected org.eclipse.jetty.server.handler.ThreadLimitHandler.Remote |
getRemote(Request baseRequest) |
protected String |
getRemoteIP(Request baseRequest) |
int |
getThreadLimit() |
protected int |
getThreadLimit(String ip) |
void |
handle(String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
Handle a request.
|
void |
include(String inetAddressPattern) |
boolean |
isEnabled() |
void |
setEnabled(boolean enabled) |
void |
setThreadLimit(int threadLimit) |
destroy, expandChildren, getHandler, getHandlers, insertHandler, setHandler
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass, setServer
doError, doStop, dumpThis, getServer
addBean, addBean, addBean, addEventListener, addManaged, contains, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
protected void doStart() throws Exception
ContainerLifeCycle
doStart
in class AbstractHandler
Exception
@ManagedAttribute(value="true if this handler is enabled") public boolean isEnabled()
public void setEnabled(boolean enabled)
@ManagedAttribute(value="The maximum threads that can be dispatched per remote IP") public int getThreadLimit()
public void setThreadLimit(int threadLimit)
@ManagedOperation(value="Include IP in thread limits") public void include(String inetAddressPattern)
@ManagedOperation(value="Exclude IP from thread limits") public void exclude(String inetAddressPattern)
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
Handler
handle
in interface Handler
handle
in class HandlerWrapper
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
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.IOException
- if unable to handle the request or response processingServletException
- if unable to handle the request or response due to underlying servlet issueprotected int getThreadLimit(String ip)
protected org.eclipse.jetty.server.handler.ThreadLimitHandler.Remote getRemote(Request baseRequest)
Copyright © 1995–2017 Webtide. All rights reserved.