it is intended in a "container" way, this should go:
@WebFilter("/*")
public class RequestFilter implements Filter
{
private static final int THRESHOLD = 5;
private static Map<String, AtomicInteger> accessMap = new HashMap<String, AtomicInteger>();
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest) servletRequest;
AtomicInteger counter = accessMap.get(request.getRequestURI());
if(counter == null) counter = new AtomicInteger();
if(counter.incrementAndGet() < THRESHOLD)
{
filterChain.doFilter(servletRequest, servletResponse);
}
counter.decrementAndGet();
}
@Override
public void init(FilterConfig filterConfig) throws ServletException
{
// nothing to do
}
@Override
public void destroy()
{
// nothing to do
}