Example usage for javax.servlet.http HttpFilter doFilter

List of usage examples for javax.servlet.http HttpFilter doFilter

Introduction

In this page you can find the example usage for javax.servlet.http HttpFilter doFilter.

Prototype

protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain)
        throws IOException, ServletException 

Source Link

Document

The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain.

Usage

From source file:org.auraframework.http.AuraTestFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    if (testContextAdapter == null || configAdapter == null || configAdapter.isProduction()) {
        chain.doFilter(request, response);
        return;/*from  w  w  w  . j ava  2  s  .c  om*/
    }

    if (testCaseFilters != null && testCaseFilters.size() > 0) {
        final AtomicBoolean handled = new AtomicBoolean(false);

        for (HttpFilter filter : testCaseFilters) {
            if (filter == null) {
                continue;
            }
            filter.doFilter((HttpServletRequest) request, (HttpServletResponse) response, (req, res) -> {
                innerFilter(req, res, chain);
                handled.set(true);
            });
            if (handled.get()) {
                return; // Only 1 filter is allowed to generate a response
            }
        }
    }

    innerFilter(request, response, chain);
}