title: HttpServletResponse contained in servlet filter does not perform redirect
body: <p>I am using Spring 4.0.6 in a servlet application. I have an abstract base controller with some general methods for all my controllers to use.</p>
  
  <p>One of these methods is a redirect. I want to have a method with signature</p>
  
  <pre><code>redirect(String path)
  </code></pre>
  
  <p>To send a redirect, I am using </p>
  
  <pre><code>response.sendRedirect(response.encodeRedirectURL(path));
  </code></pre>
  
  <p>As I would like to keep method signatures short and clean, I need to get access to the response object inside the superclass method.</p>
  
  <p>In order to do this, I've followed a suggestion found online, and defined a servlet filter with a ThreadLocal HttpServletResponse.</p>
  
  <pre><code>public class ResponseFilter extends OncePerRequestFilter {
  
      private static final ThreadLocal&lt;HttpServletResponse&gt; responses = new ThreadLocal&lt;HttpServletResponse&gt;();
  
      public static HttpServletResponse getResponse() {
          return responses.get();
      }
  
      @Override
      protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
          try {
              responses.set(response);
          } finally {
              try {
                  filterChain.doFilter(request, response);
              } finally {
                  responses.remove();
              }
          }
      }
  }
  </code></pre>
  
  <p>As I am using Spring security with a Java configuration, I'm adding this filter in my WebSecurityConfigurerAdapter subclass: </p>
  
  <pre><code>.addFilterAfter(rf, SwitchUserFilter.class)
  </code></pre>
  
  <p>Note that I have also tried adding the filter as first in the filterchain, and that I have tried using an Interceptor instead. All with the same results.</p>
  
  <p>I have compared hashcodes on the response objects, and near as I can tell, the hashcodes match, but the redirect seems to be ignored. I have also looked at object ids on breakpoints in Eclipse, and there again, I have a match. The symptom is that the spring DispatcherServlet enters processDispatchResult and seems to think it needs to resolve a view. That view does not exist, as I expect to do a redirect:</p>
  
  <pre><code>javax.servlet.ServletException: File &amp;quot;/WEB-INF/views/application/redirecttest.jsp&amp;quot; not found
  </code></pre>
  
  <p>I have noticed that, if I add the response object back in my requestmapping controller method signature, the superclass redirect seems to work (even though I do not use the controller method response object at all).</p>
  
  <p>Unfortunately, this behavior is reproducible both on a Mac and on Linux. I use Tomcat 7 as container.</p>