> This is interesting.  The OncePerRequestFilter was just copied from
> Spring - did they not have the same issue then?

Here's the latest code I just grabbed from src.springsource.org:


        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;

                String alreadyFilteredAttributeName = 
getAlreadyFilteredAttributeName();
                if (request.getAttribute(alreadyFilteredAttributeName) != null 
||
shouldNotFilter(httpRequest)) {
                        // Proceed without invoking this filter...
                        filterChain.doFilter(request, response);
                }
                else {
                        // Do invoke this filter...
                        request.setAttribute(alreadyFilteredAttributeName, 
Boolean.TRUE);
                        try {
                                doFilterInternal(httpRequest, httpResponse, 
filterChain);
                        }
                        finally {
                                // Remove the "already filtered" request 
attribute for this request.
                                
request.removeAttribute(alreadyFilteredAttributeName);
                        }
                }
        }

Note that they now remove the request attribute. I'll add that.

Cheers,

Peter

Reply via email to