Class AsyncUtils


  • public final class AsyncUtils
    extends Object
    A utility classes for dealing with asynchronous request handling.
    Author:
    Rob Spoor
    • Method Detail

      • doFilter

        public static void doFilter​(ServletRequest request,
                                    ServletResponse response,
                                    FilterChain chain,
                                    ServletConsumer action)
                             throws IOException,
                                    ServletException
        Proceeds in the filter chain and executes an action after the chain ends. This method can be used to ensure the given action is executed at the end of the request, regardless of whether or not the request is handled asynchronously.

        If the request has not been put into asynchronous mode, this method will execute the following:

        
         try {
             chain.doFilter(request, response);
         } finally {
             action.run(request, response);
         }
         
        However, if the request has been put into asynchronous mode, this method will ensure that the given action will execute once the asynchronous operation completes, successfully or not.
        Parameters:
        request - The request to use in both chain.doFilter and the action.
        response - The response to use in both chain.doFilter and the action.
        chain - The filter chain to call FilterChain.doFilter(ServletRequest, ServletResponse) on.
        action - The action to execute after the chain ends.
        Throws:
        IOException - Re-thrown from the call to chain.doFilter or the action.
        ServletException - Re-thrown from the call to chain.doFilter.
        NullPointerException - If the request, response filter chain or action is null.