public abstract class

OncePerRequestFilter

extends GenericFilterBean
java.lang.Object
   ↳ org.springframework.web.filter.GenericFilterBean
     ↳ org.springframework.web.filter.OncePerRequestFilter
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Filter base class that guarantees to be just executed once per request, on any servlet container. It provides a doFilterInternal(HttpServletRequest, HttpServletResponse, FilterChain) method with HttpServletRequest and HttpServletResponse arguments.

The getAlreadyFilteredAttributeName() method determines how to identify that a request is already filtered. The default implementation is based on the configured name of the concrete filter instance.

Summary

Constants
String ALREADY_FILTERED_SUFFIX Suffix that gets appended to the filter name for the "already filtered" request attribute.
[Expand]
Inherited Fields
From class org.springframework.web.filter.GenericFilterBean
Public Constructors
OncePerRequestFilter()
Public Methods
final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
This doFilter implementation stores a request attribute for "already filtered", proceeding without filtering again if the attribute is already there.
Protected Methods
abstract void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as for doFilter, but guaranteed to be just invoked once per request.
String getAlreadyFilteredAttributeName()
Return the name of the request attribute that identifies that a request is already filtered.
boolean shouldNotFilter(HttpServletRequest request)
Can be overridden in subclasses for custom filtering control, returning true to avoid filtering of the given request.
[Expand]
Inherited Methods
From class org.springframework.web.filter.GenericFilterBean
From class java.lang.Object
From interface javax.servlet.Filter
From interface org.springframework.beans.factory.BeanNameAware
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.context.EnvironmentAware
From interface org.springframework.web.context.ServletContextAware

Constants

public static final String ALREADY_FILTERED_SUFFIX

Suffix that gets appended to the filter name for the "already filtered" request attribute.

Constant Value: ".FILTERED"

Public Constructors

public OncePerRequestFilter ()

Public Methods

public final void doFilter (ServletRequest request, ServletResponse response, FilterChain filterChain)

This doFilter implementation stores a request attribute for "already filtered", proceeding without filtering again if the attribute is already there.

Throws
IOException
ServletException

Protected Methods

protected abstract void doFilterInternal (HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)

Same contract as for doFilter, but guaranteed to be just invoked once per request. Provides HttpServletRequest and HttpServletResponse arguments instead of the default ServletRequest and ServletResponse ones.

Throws
IOException
ServletException

protected String getAlreadyFilteredAttributeName ()

Return the name of the request attribute that identifies that a request is already filtered.

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.

protected boolean shouldNotFilter (HttpServletRequest request)

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