jsfjsf-2omnifacesviewexpiredexception

Override of logException method of OmniFaces FullAjaxExceptionHandler does not get invoked


I am using OmniFaces (1.7) FullAjaxExceptionHandler to handle (ViewExpired)Exception's during ajax requests.

I don't want to the FullAjaxExceptionHandler to log the exception with level SEVERE as the default implementation does. So I did override the logException method, but still the default method rather than the overridden one is called.

I have registered the following factories:

  <factory>
    <exception-handler-factory>my.package.ViewExpiredExceptionHandlerFactory</exception-handler-factory>
  </factory>

  <factory>
      <exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
  </factory>

Here is my ViewExpiredExceptionHandlerFactory

public class ViewExpiredExceptionHandlerFactory extends ExceptionHandlerFactory {

  private ExceptionHandlerFactory parent;

  public ViewExpiredExceptionHandlerFactory(ExceptionHandlerFactory parent) {
    this.parent = parent;
  }

  @Override
  public ExceptionHandler getExceptionHandler() {
    ExceptionHandler result = parent.getExceptionHandler();
    result = new ViewExpiredExceptionHandler(result);

    return result;
  }

}

and the extended FullAjaxExceptionHandler

public class ViewExpiredExceptionHandler extends FullAjaxExceptionHandler {

  private static final Logger LOGGER = Logger.getLogger(ViewExpiredExceptionHandler.class);

  private ExceptionHandler wrapped;

  public ViewExpiredExceptionHandler(ExceptionHandler wrapped) {
    super(wrapped);
    this.wrapped = wrapped;
  }

  @Override
  public ExceptionHandler getWrapped() {
    return this.wrapped;
  }

  @Override
  public void logException(FacesContext context, Throwable exception, String location, String message, Object... parameters) {
    String user = UserFilter.readUserIdFromSession();
    LOGGER.info("The view/session has expired for user " + (user == null ? "null" : user));
  }

}

Am I missing something?


Solution

  • Remove the FullAjaxExceptionHandlerFactory entry from faces-config.xml. Right now you've basically two entirely distinct exception handler instances each doing their own thing whereby the later registered one wraps (and thus takes precedence over) the previously registered one. However the FullAjaxExceptionHandler by itself doesn't delegate to the wrapped one once an ajax exception is encountered.

    So, all you need is just this:

    <factory>
        <exception-handler-factory>my.package.ViewExpiredExceptionHandlerFactory</exception-handler-factory>
    </factory>