2010-11-20 4 views
0

phaseId RENDER_RESPONSE를 수신하는 PhaseListener가 있습니다. 이 faceListener는이 메소드를 호출합니다.리디렉션시 IllegalStateException

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 && 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()); 
    } 

리다이렉트하면 다음과 같은 예외가 발생합니다. 응답이 이미 완결되었지만 이미 완결 된 이유는 무엇입니까?

난 정말 내가 여기에 :) 얻을 수있는 모든 도움을 주셔서 감사합니다 그런데
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) 

답변

0

귀하의 phaselistener가 afterPhase (RENDER_RESPONSE)에 연결되어있는 것 같습니다. 응답을 변경하기에는 너무 늦었습니다. 응답이 이미 클라이언트로 전송되었습니다. 오히려 beforePhase()의`RENDER_RESPONSE '에 연결하십시오.

+0

나는 그것을 해냈다. :)하지만 이제 나는 어제의 문제로 돌아왔다. http://stackoverflow.com/questions/4225014/managed-bean-is-sometimes-null-and-sometimes-not 현재 버전으로 업데이트 됨 – AnAmuser

0

내 생각은 sendRedirect()가 실행되기 전에 코드의 일부는 이미 서블릿 repsonse에 텍스트를 스트리밍 것을 할 것입니다, 어쩌면 모든 응답에 보내는 일반적인 정보일까요?

관련 문제