title: Force downloading a file using Spring MVC and a self-implemented interceptor produces a weird issue
body: <p>All of my controllers extend the following abstract class:</p>
  
  <pre><code>public abstract class AbstractController {
  
      public HttpServletRequest request;
      public HttpServletResponse response;
      public ModelMap model;
  
  }
  </code></pre>
  
  <p>Moreover, I implemented the following interceptor:</p>
  
  <pre><code>public class HttpRequestInterceptor implements HandlerInterceptor {
  
      public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
          if (handler instanceof AbstractController) {
              AbstractController controller = (AbstractController) handler;
              controller.request = request;
              controller.response = response;
              controller.model = new ModelMap();
          }
          return true;
      }
  
      public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
          if (handler instanceof AbstractController &amp;&amp; modelAndView != null) {
              AbstractController controller = (AbstractController) handler;
              modelAndView.addAllObjects(controller.model);
          }
      }
  
      public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
      }
  
  }
  </code></pre>
  
  <p>This is a solution I found to improve the factorization of my code, since you won't need to pass the <code>request</code>, the <code>response</code> and the <code>model</code> as method parameters within your controllers. The solution works fine, until I found this issue:</p>
  
  <pre><code>public class HomeController extends AbstractController {
  
      @RequestMapping
      public void download1() {
          // use the parent attribute response
          File file = new File(MY_FILE_PATH);
          InputStream in = new BufferedInputStream(new FileInputStream(file));
          ServletOutputStream out = response.getOutputStream();
          IOUtils.copy(in, out);
          response.flushBuffer();
      }
  
      @RequestMapping
      public void download2(HttpServletResponse response) {
          // use the response passed as parameter
          File file = new File(MY_FILE_PATH);
          InputStream in = new BufferedInputStream(new FileInputStream(file));
          ServletOutputStream out = response.getOutputStream();
          IOUtils.copy(in, out);
          response.flushBuffer();
      }
  
  }
  </code></pre>
  
  <p>Both of the two methods above make the browser downloading a file, but the <code>download1</code> one generated an empty file while the <code>download2</code> generates the original file as it should. Any idea why?</p>
  
  <p>Thanks to the debugger, I noticed that in the <code>postHandle</code> method of the interceptor, the <code>download2</code> method generates a <code>modelAndView</code> which equals <code>null</code>, while the <code>download1</code> one generated an instanciated one. This should mean something for the issue, but I can't find what.</p>
  
  <p>How get a <code>response</code> instanciated when passed as a parameter of a controller's method?</p>