Package sk.antons.web.filter.limiter
Class RequestLimiter<T>
- java.lang.Object
-
- sk.antons.web.filter.limiter.RequestLimiter<T>
-
- All Implemented Interfaces:
Limiter
public class RequestLimiter<T> extends Object implements Limiter
Servlet request limiter implementation. If you implement servlet filter and you want to limit some functionality in this filter. You can add this instance to your implementation and use them in filter implementation to limit a functionality. As example you can see in messagge loggerpublic class LogFilter implements Filter { private RequestLimiter limiter = new RequestLimiter(); public RequestLimiter limit() { return limiter; }By this you can configure your instancesLogFilter 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 likeif (limiter.allow(request)) { doFilterInternal(wrapRequest(request), wrapResponse(response), chain); } else { chain.doFilter(request, response); }- Author:
- antons
-
-
Constructor Summary
Constructors Constructor Description RequestLimiter(T parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallow(javax.servlet.ServletRequest request)Returns true if limiter allow filter processingbooleanallowResponseStatus(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.Tfilter()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.
-
-
-
Constructor Detail
-
RequestLimiter
public RequestLimiter(T parent)
-
-
Method Detail
-
filter
public T filter()
-
path
public PathConf<RequestLimiter<T>> path()
Path mather configuration for limiter.- Returns:
-
host
public StringConf<RequestLimiter<T>> host()
Host name configuration for limiter. This will apply for all requests. You can also limit this only for concrete path in path() configuration.- Returns:
-
contentType
public StringConf<RequestLimiter<T>> contentType()
Content type configuration for limiter. This will apply for all requests. You can also limit this only for concrete path in path() configuration.- Returns:
-
custom
public RequestLimiter<T> custom(Limiter limiter)
You can add your custom limiter implementation.- Parameters:
limiter-- Returns:
-
responseStatus
public RequestLimiter<T> responseStatus(ResponseStatusCheck check)
Response status configuration for limiter. This will apply for all requests. You can also limit this only for concrete path in path() configuration.- Returns:
-
reset
public RequestLimiter<T> reset()
Clears all settings for this limiter.- Returns:
-
allow
public boolean allow(javax.servlet.ServletRequest request)
Description copied from interface:LimiterReturns true if limiter allow filter processing
-
allowResponseStatus
public boolean allowResponseStatus(javax.servlet.ServletRequest request, int status)Description copied from interface:LimiterReturns true if limiter allow filter processing after cain execution. This variant can be used after chanin prpocessing when status code is known.- Specified by:
allowResponseStatusin interfaceLimiter- Parameters:
request- request to checkstatus- response status to check- Returns:
- true is filter should be processed.
-
-