MyFaces Core
  1. MyFaces Core
  2. MYFACES-2355

ExceptionHandler not redirecting to error page for exceptions thrown during listeners attached to render response phase

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Invalid
    • Affects Version/s: 2.0.0-alpha
    • Fix Version/s: 2.0.8, 2.1.2
    • Component/s: JSR-314
    • Labels:
      None

      Description

      If an exception is thrown by a listener attached to the render response phase, the exception handler is unable to redirect to the error handler page as with other lifecycle phases.

      The reason for this is that the render response execution has already flushed the response buffer, marking the response as committed. This can be resolved for before phase listeners by simply not rendering the response. For after phase listeners we may have to be content with logging the exception. I'll go ahead and check in the fix for before phase listeners and leave the issue open for now until a resolution can be reached for after phase listeners (or if its better to just leave it as is in that case).

        Activity

        Hide
        Leonardo Uribe added a comment -

        The code commited here is invalid, because it does not follow the algorithm described on JSF 2.0 rev A section 12.3 PhaseListener. All exceptions thrown before and after a phase must be published so ExceptionHandler can get it and process them later. In JSF 2.0, two new methods were added to clear the response buffer: ExternalContext.responseReset() and ExternalContext.isResponseCommitted(), so before output any response by a custom ExceptionHandler, these two methods should be called in this way:

        if (!externalContext.isResponseCommitted())

        { externalContext.responseReset(); }

        I tried it and it works. I know it sounds weird that exceptions thrown on beforePhase() cannot short-circuit the lifecycle, but it is clear JSF spec doesn't allow that. Maybe this issue must be raised on JSF spec issue tracker.

        Show
        Leonardo Uribe added a comment - The code commited here is invalid, because it does not follow the algorithm described on JSF 2.0 rev A section 12.3 PhaseListener. All exceptions thrown before and after a phase must be published so ExceptionHandler can get it and process them later. In JSF 2.0, two new methods were added to clear the response buffer: ExternalContext.responseReset() and ExternalContext.isResponseCommitted(), so before output any response by a custom ExceptionHandler, these two methods should be called in this way: if (!externalContext.isResponseCommitted()) { externalContext.responseReset(); } I tried it and it works. I know it sounds weird that exceptions thrown on beforePhase() cannot short-circuit the lifecycle, but it is clear JSF spec doesn't allow that. Maybe this issue must be raised on JSF spec issue tracker.

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Michael Concini
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development