java.lang.IllegalStateException: Response already committed

Coderanch | mk yadav | 4 years ago
  1. 0

    java.lang.IllegalStateException: Response already committed

    Coderanch | 4 years ago | mk yadav
    java.lang.IllegalStateException: Response already committed
  2. 0

    Weblogic Deadlock

    Oracle Community | 3 years ago | 131b7eed-82f6-4cd0-96f7-e4a472b03668
    java.lang.IllegalStateException: Response already committed
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    From the javadoc for ExternalContext.redirect(): http://docs.oracle.com/javaee/6/api/javax/faces/context/ExternalContext.html#redirect%28java.lang.String%29 "Throws: IllegalStateException - if, in a servlet environment, the current response has already been committed" This works fine for full page refresh / submit. We see this exception when attempting to write to response stream after response is complete: java.lang.IllegalStateException: Response already committed at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1608) at weblogic.servlet.internal.ServletResponseImpl.sendRedirect(ServletResponseImpl.java:834) at javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:136) at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:421) However for Partial page submit / AJAX case, this exception is not raised, and there is possibility of writing to response even after the response is logically complete. The bug is evident looking at the implementation of redirect() method in ExternalContext: 549 /** 550 * @see ExternalContext#redirect(String) 551 */ 552 public void redirect(String requestURI) throws IOException { 553 554 FacesContext ctx = FacesContext.getCurrentInstance(); 555 getELFlash().doLastPhaseActions(ctx, true); 556 557 if (ctx.getPartialViewContext().isAjaxRequest()) { 558 PartialResponseWriter pwriter; 559 ResponseWriter writer = ctx.getResponseWriter(); 560 if (writer instanceof PartialResponseWriter) { 561 pwriter = (PartialResponseWriter) writer; 562 } else { 563 pwriter = ctx.getPartialViewContext().getPartialResponseWriter(); 564 } 565 setResponseContentType("text/xml"); 566 setResponseCharacterEncoding("UTF-8"); 567 addResponseHeader("Cache-Control", "no-cache"); 568 pwriter.startDocument(); 569 pwriter.redirect(requestURI); 570 pwriter.endDocument(); 571 } else { 572 ((HttpServletResponse) response).sendRedirect(requestURI); 573 } 574 ctx.responseComplete(); 575 576 } The Servlet specification essentially says that sendRedirect() commits the request, so a second sendRedirect() will throw an IllegalStateException. For the AJAX case, looks like the above implementation is simply using a redirect header and is likely rendering content to perform the redirect. Furthermore looks like for AJAX case call to redirect() does not result in calling FacesContext.responseComplete(), which is not right. The consequence of this is bug in JSF based applications that in AJAX case, the response can contain as many redirects as possible, which is invalid to do so. Expected: Mojarra should implement the redirect semantics correctly and completely for the partial rendering / AJAX case as is done for the full page refresh case. Testcase: Code like the following when executed for AJAX request should show the issue: ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext(); HttpSession session = (HttpSession)ectx.getSession(true); String temp = session.getServletContext().getContextPath() + "/faces/welcomePage.jspx"; String temp2 = session.getServletContext().getContextPath() + "/faces/mainPage.jspx"; try { boolean complete1 = FacesContext.getCurrentInstance().getResponseComplete(); ectx.redirect(temp); boolean complete2 = FacesContext.getCurrentInstance().getResponseComplete(); ectx.redirect(temp2); boolean complete3 = FacesContext.getCurrentInstance().getResponseComplete(); } catch (Exception ex) { ex.printStackTrace(); }

    Java.net JIRA | 4 years ago | prakashudupa
    java.lang.IllegalStateException: Response already committed
  5. 0

    Error while opening b2b console

    Oracle Community | 5 years ago | 795096
    java.lang.IllegalStateException: Response already committed

    2 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Response already committed

      at weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted()
    2. Atmosphere weblogic
      ServletResponseImpl.sendRedirect
      1. weblogic.servlet.internal.ServletResponseImpl.objectIfCommitted(ServletResponseImpl.java:1608)
      2. weblogic.servlet.internal.ServletResponseImpl.sendRedirect(ServletResponseImpl.java:834)
      2 frames
    3. com.diy.controller
      LoginServlet.doPost
      1. com.diy.controller.LoginServlet.doPost(LoginServlet.java:56)
      1 frame
    4. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      2. javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
      2 frames
    5. Atmosphere weblogic
      FilterChainImpl.doFilter
      1. weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
      2. weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
      3. weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
      4. weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
      5. weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      5 frames
    6. oracle.security.jps
      JpsAbsFilter$1.run
      1. oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
      1 frame
    7. Java RT
      AccessController.doPrivileged
      1. java.security.AccessController.doPrivileged(Native Method)
      1 frame
    8. oracle.security.jps
      JpsFilter.doFilter
      1. oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
      2. oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
      3. oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
      4. oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
      5. oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
      5 frames
    9. Atmosphere weblogic
      FilterChainImpl.doFilter
      1. weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      1 frame
    10. oracle.dms.servlet
      DMSServletFilter.doFilter
      1. oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
      1 frame
    11. Atmosphere weblogic
      WebAppServletContext$ServletInvocationAction.run
      1. weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
      2. weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
      3. weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
      3 frames
    12. weblogic.security.acl
      AuthenticatedSubject.doAs
      1. weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
      1 frame
    13. weblogic.security.service
      SecurityManager.runAs
      1. weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
      1 frame
    14. Atmosphere weblogic
      ServletRequestImpl.run
      1. weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
      2. weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
      3. weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
      3 frames