spring-session-core/src/main/java/org/springframework/session/web/http/OncePerRequestFilter.java
@Override
	public final void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws ServletException, IOException {

		if (!(request instanceof HttpServletRequest)
				|| !(response instanceof HttpServletResponse)) {
			throw new ServletException(
					"OncePerRequestFilter just supports HTTP requests");
		}
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		boolean hasAlreadyFilteredAttribute = request
				.getAttribute(this.alreadyFilteredAttributeName) != null;

		if (hasAlreadyFilteredAttribute) {

			// Proceed without invoking this filter...
			filterChain.doFilter(request, response);
		}
		else {
			// Do invoke this filter...
			request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
			try {
				doFilterInternal(httpRequest, httpResponse, filterChain);
			}
			finally {
				// Remove the "already filtered" request attribute for this request.
				request.removeAttribute(this.alreadyFilteredAttributeName);
			}
		}
	}
@Override
	public final void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws ServletException, IOException {

		if (!(request instanceof HttpServletRequest)
				|| !(response instanceof HttpServletResponse)) {
			throw new ServletException(
					"OncePerRequestFilter just supports HTTP requests");
		}
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		boolean hasAlreadyFilteredAttribute = request
				.getAttribute(this.alreadyFilteredAttributeName) != null;

		if (hasAlreadyFilteredAttribute) {

			// Proceed without invoking this filter...
			filterChain.doFilter(request, response);
		}
		else {
			// Do invoke this filter...
			request.setAttribute(this.alreadyFilteredAttributeName, Boolean.TRUE);
			try {
				doFilterInternal(httpRequest, httpResponse, filterChain);
			}
			finally {
				// Remove the "already filtered" request attribute for this request.
				request.removeAttribute(this.alreadyFilteredAttributeName);
			}
		}
	}
@ Override public final void doFilter ( ServletRequest request , ServletResponse response , FilterChain filterChain ) throws ServletException , IOException { if ( ! ( request instanceof HttpServletRequest ) || ! ( response instanceof HttpServletResponse ) ) { throw new ServletException ( "OncePerRequestFilter just supports HTTP requests" ) ; } HttpServletRequest httpRequest = ( HttpServletRequest ) request ; HttpServletResponse httpResponse = ( HttpServletResponse ) response ; boolean hasAlreadyFilteredAttribute = request . getAttribute ( this . alreadyFilteredAttributeName ) != null ; if ( hasAlreadyFilteredAttribute ) { // Proceed without invoking this filter... filterChain . doFilter ( request , response ) ; } else { // Do invoke this filter... request . setAttribute ( this . alreadyFilteredAttributeName , Boolean . TRUE ) ; try { doFilterInternal ( httpRequest , httpResponse , filterChain ) ; } finally { // Remove the "already filtered" request attribute for this request. request . removeAttribute ( this . alreadyFilteredAttributeName ) ; } } }
This {@code doFilter} implementation stores a request attribute for
"already filtered", proceeding without filtering again if the attribute is already
there.
@param request the request
@param response the response
@param filterChain the filter chain
@throws ServletException if request is not HTTP request
@throws IOException in case of I/O operation exception
This {