org.springframework.web.filter

Class OncePerRequestFilter

    • Constructor Detail

      • OncePerRequestFilter

        public OncePerRequestFilter()
    • Method Detail

      • isAsyncDispatch

        protected boolean isAsyncDispatch(HttpServletRequest request)
        The dispatcher type javax.servlet.DispatcherType.ASYNC introduced in Servlet 3.0 means a filter can be invoked in more than one thread over the course of a single request. This method returns true if the filter is currently executing within an asynchronous dispatch.
        Parameters:
        request - the current request
        Since:
        3.2
        See Also:
        WebAsyncManager.hasConcurrentResult()
      • isAsyncStarted

        protected boolean isAsyncStarted(HttpServletRequest request)
        Whether request processing is in asynchronous mode meaning that the response will not be committed after the current thread is exited.
        Parameters:
        request - the current request
        Since:
        3.2
        See Also:
        WebAsyncManager.isConcurrentHandlingStarted()
      • getAlreadyFilteredAttributeName

        protected java.lang.String getAlreadyFilteredAttributeName()
        Return the name of the request attribute that identifies that a request is already filtered.

        The default implementation takes the configured name of the concrete filter instance and appends ".FILTERED". If the filter is not fully initialized, it falls back to its class name.

        See Also:
        GenericFilterBean.getFilterName(), ALREADY_FILTERED_SUFFIX
      • shouldNotFilter

        protected boolean shouldNotFilter(HttpServletRequest request)
                                   throws ServletException
        Can be overridden in subclasses for custom filtering control, returning true to avoid filtering of the given request.

        The default implementation always returns false.

        Parameters:
        request - current HTTP request
        Returns:
        whether the given request should not be filtered
        Throws:
        ServletException - in case of errors
      • shouldNotFilterAsyncDispatch

        protected boolean shouldNotFilterAsyncDispatch()
        The dispatcher type javax.servlet.DispatcherType.ASYNC introduced in Servlet 3.0 means a filter can be invoked in more than one thread over the course of a single request. Some filters only need to filter the initial thread (e.g. request wrapping) while others may need to be invoked at least once in each additional thread for example for setting up thread locals or to perform final processing at the very end.

        Note that although a filter can be mapped to handle specific dispatcher types via web.xml or in Java through the ServletContext, servlet containers may enforce different defaults with regards to dispatcher types. This flag enforces the design intent of the filter.

        The default return value is "true", which means the filter will not be invoked during subsequent async dispatches. If "false", the filter will be invoked during async dispatches with the same guarantees of being invoked only once during a request within a single thread.

        Since:
        3.2
      • shouldNotFilterErrorDispatch

        protected boolean shouldNotFilterErrorDispatch()
        Whether to filter error dispatches such as when the servlet container processes and error mapped in web.xml. The default return value is "true", which means the filter will not be invoked in case of an error dispatch.
        Since:
        3.2