title: Spring security: Cannot call sendRedirect() after the response has been committed
body: <p>I'm using the following code for logout:</p>
  
  <pre><code>public class LogoutHandler extends SimpleUrlLogoutSuccessHandler {
  
  
  @Override
  public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
          throws IOException, ServletException {
      if(!response.isCommitted()) {
          String targetURL = "myUrl";
          response.setContentType(MediaType.TEXT_PLAIN_VALUE);
          response.getWriter().write(target);
          response.getWriter().flush();
          response.getWriter().close();
          getRedirectStrategy().sendRedirect(request, response, targetURL);
      }
  
   }
  
  }
  </code></pre>
  
  <p>But when calling /logout WS I got the following exception:</p>
  
  <pre><code> java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
  at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:494)
  at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:138)
  at org.springframework.security.web.firewall.FirewalledResponse.sendRedirect(FirewalledResponse.java:26)
  at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:138)
  </code></pre>