title: IllegalStateException on redirect
body: <p>I have a PhaseListener which listens on phaseId RENDER_RESPONSE. This faceListener calls this method:</p>
  
  <pre><code>   public void doLogin(ServletRequest request) throws IOException {
          FacesContext fc = FacesContext.getCurrentInstance();
          HttpServletRequest req = (HttpServletRequest) request;
          String code = req.getParameter("code");
          if (StringUtil.isNotBlankString(code)) {
              String authURL = Facebook.getAuthURL(code);
              URL url = new URL(authURL);
              try {
                  ....
                  if (accessToken != null &amp;&amp; expires != null) {
                      boolean isLoginOk = service.authFacebookLogin(accessToken);
                      if (isLoginOk) {
                          fc.getApplication().getNavigationHandler().handleNavigation(fc, "/welcome.xhtml", "logged-in");
                      }
                  } else {
                      throw new RuntimeException("Access token and expires not found");
                  }
              } catch (IOException e) {
                  throw new RuntimeException(e);
              } catch (FacebookException e) {
                  Logger.getLogger(FBOauth.class.getName()).log(Level.SEVERE, "Facebook error", e);
              }
          }
      }
  
      private String readURL(URL url) throws IOException {
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          InputStream is = url.openStream();
          int r;
          while ((r = is.read()) != -1) {
              baos.write(r);
          }
          return new String(baos.toByteArray());
      }
  </code></pre>
  
  <p>When it redirects I get the following exception which I cant really find any solution to. From what I understand it is thrown because response is already comitted but why is it already comitted? </p>
  
  <pre><code>java.lang.IllegalStateException at 
  org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:522)
                  at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:572)
                  at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:182)
                  at wmc.web.facebook.FBOauth.doLogin(FBOauth.java:57)
                  at wmc.web.listeners.FacebookSignInListener.afterPhase(FacebookSignInListener.java:56)
                  at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:189)
                  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:107)
                  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
  </code></pre>
  
  <p>By the way I really appreciate all the help I get in here :)</p>