public class RequestLimiter<T> extends Object implements Limiter
public class LogFilter implements Filter {
private RequestLimiter limiter = new RequestLimiter();
public RequestLimiter limit() { return limiter; }
By this you can configure your instances
LogFilter filter = LogFilter.instance();
filter
.limit()
.path()
.include("/foo/**", "POST") // - allow path pattern together with POST method
.include("/dummy/**" //path - allow only this pattern
, null //method - allow all methos
, null //ip - allow all incoming ips
, null //host - allow all incoming host names
, MediaType.APPLICATION_JSON_VALUE //contentType - allow only json
, (status) -> { return status >= 400;}) //respons status check - allow bad statuses
.exclude("/bar/**" //path - disallow only this pattern
, "PUT" //method - disallow POT
, "127.0.0.1" //ip - disallow all incoming ips
, null //host - disallow all incoming host names
, null //contentType - disallow all
, null) //respons status check - disallow all
//.exclude("/dummy/**", "GET")
;
And in LogFilter implementation you can use something like
if (limiter.allow(request)) {
doFilterInternal(wrapRequest(request), wrapResponse(response), chain);
} else {
chain.doFilter(request, response);
}
| Constructor and Description |
|---|
RequestLimiter(T parent) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
allow(javax.servlet.ServletRequest request)
Returns true if limiter allow filter processing
|
boolean |
allowResponseStatus(javax.servlet.ServletRequest request,
int status)
Returns true if limiter allow filter processing after cain execution.
|
StringConf<RequestLimiter<T>> |
contentType()
Content type configuration for limiter.
|
RequestLimiter<T> |
custom(Limiter limiter)
You can add your custom limiter implementation.
|
T |
filter() |
StringConf<RequestLimiter<T>> |
host()
Host name configuration for limiter.
|
PathConf<RequestLimiter<T>> |
path()
Path mather configuration for limiter.
|
RequestLimiter<T> |
reset()
Clears all settings for this limiter.
|
RequestLimiter<T> |
responseStatus(ResponseStatusCheck check)
Response status configuration for limiter.
|
public RequestLimiter(T parent)
public T filter()
public PathConf<RequestLimiter<T>> path()
public StringConf<RequestLimiter<T>> host()
public StringConf<RequestLimiter<T>> contentType()
public RequestLimiter<T> custom(Limiter limiter)
limiter - public RequestLimiter<T> responseStatus(ResponseStatusCheck check)
public RequestLimiter<T> reset()
public boolean allow(javax.servlet.ServletRequest request)
Limiterpublic boolean allowResponseStatus(javax.servlet.ServletRequest request,
int status)
LimiterallowResponseStatus in interface Limiterrequest - request to checkstatus - response status to checkCopyright © 2020. All rights reserved.