Search code examples
jsfjakarta-eeprimefaceswildflyomnifaces

Omnifaces FullAjaxExceptionHandler produces endless loop - config issue, bug or lack of understanding?


I am experiencing an endless loop in the FullAjaxExceptionHandler. I do not see if this is a configuration issue, a bug in Omnifaces or my own lack of understanding. So, I am asking for help to get me in the right direction.

I am using Omnifaces 2.6 with Primefaces 6 on Wildfly 10.1.0 Final I instrumented the FullAjaxExceptionHandler as precise as i could as it is recommended in the Showcase

My web.xml contains this:

<error-page>
    <error-code>500</error-code>
    <location>/error/java/defaulterror.jsf</location>
</error-page>

Now lets say a user sends an Ajax Request like this:

<p:commandButton value="Do something long" 
    action="#{bean.doSomethingLong()}" async="true"/>

Bean:

public void doSomethingLong() {
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
    }
}

And now lets say the user does not wait for the Request to complete but instead hits the logout button:

    <p:commandButton value="Logout" 
        action="#{bean.invalidateSession()}" />

Bean:

public void invalidateSession() {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.invalidateSession();
}

When the first request finally completes its waiting time, it produces an endless (or very long) loop which looks in the log like this:

at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.renderErrorPageView(FullAjaxExceptionHandler.java:541) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handleAjaxException(FullAjaxExceptionHandler.java:414) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handle(FullAjaxExceptionHandler.java:367) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.renderErrorPageView(FullAjaxExceptionHandler.java:541) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handleAjaxException(FullAjaxExceptionHandler.java:414) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handle(FullAjaxExceptionHandler.java:367) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.renderErrorPageView(FullAjaxExceptionHandler.java:541) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handleAjaxException(FullAjaxExceptionHandler.java:414) at org.omnifaces.exceptionhandler.FullAjaxExceptionHandler.handle(FullAjaxExceptionHandler.java:367) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:123) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)

In other cases, like invalidating the session before calling the long request or invalidating the request inside of the long request, or any other exception in an ajax request, the exception page will be shown just fine. The content of the errorpage itself does not seem to matter. For completeness:

defaulterror.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>ErrorPage</title>
    </h:head>
    <h:body>
        This is bad.
    </h:body>
</html>

What is going wrong? Any help appreciated.


Solution

  • The endless loop issue will be solved in Release 2.6.4, see: https://github.com/omnifaces/omnifaces/issues/386#issuecomment-308043128