Package alpine.server.filters
Class RequestRateThrottleFilter
java.lang.Object
alpine.server.filters.RequestRateThrottleFilter
- All Implemented Interfaces:
javax.servlet.Filter
The RequestRateThrottleFilter is a Servlet filter that can place a hard limit on the number of requests
per second. The filter conforms to RFC-6585 by sending HTTP status code 429 (too many requests) if the
limit is exceeded.
Sample usage:
<filter>
<filter-name>RequestRateThrottleFilter</filter-name>
<filter-class>alpine.filters.RequestRateThrottleFilter</filter-class>
<init-param>
<param-name>maximumRequestsPerPeriod</param-name>
<param-value>5</param-value>
</init-param>
<init-param>
<param-name>timePeriodSeconds</param-name>
<param-value>10</param-value>
</init-param>
</filter>
<!-- Place a request limit on all resources -->
<filter-mapping>
<filter-name>RequestRateThrottleFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Since:
- 1.0.0
- Author:
- Steve Springett
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) Determines if the request rate is below or has exceeded the the maximum requests per second for the given time period.voidinit(javax.servlet.FilterConfig filterConfig)
-
Constructor Details
-
RequestRateThrottleFilter
public RequestRateThrottleFilter()
-
-
Method Details
-
init
public void init(javax.servlet.FilterConfig filterConfig) - Specified by:
initin interfacejavax.servlet.Filter
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException Determines if the request rate is below or has exceeded the the maximum requests per second for the given time period. If exceeded, a HTTP status code of 429 (too many requests) will be send and no further processing of the request will be done. If the request has not exceeded the limit, the request will continue on as normal.- Specified by:
doFilterin interfacejavax.servlet.Filter- Parameters:
request- a ServletRequestresponse- a ServletResponsechain- a FilterChain- Throws:
IOException- a IOExceptionjavax.servlet.ServletException- a ServletException
-
destroy
public void destroy()- Specified by:
destroyin interfacejavax.servlet.Filter
-