Silence FullAjaxExceptionHandler

孤者浪人 提交于 2019-12-04 06:06:53

As per OmniFaces 1.6, you can extend it and override the method logException() as below to skip the stack trace for ViewExpiredException.

public class YourAjaxExceptionHandler extends FullAjaxExceptionHandler {

    public YourAjaxExceptionHandler(ExceptionHandler wrapped) {
        super(wrapped);
    }

    @Override
    protected void logException(FacesContext context, Throwable exception, String location, String message, Object... parameters) {
        if (exception instanceof ViewExpiredException) {
            // With exception==null, no trace will be logged.
            super.logException(context, null, location, message, parameters);
        }
        else {
            super.logException(context, exception, location, message, parameters);
        }
    }

}

Create a factory around it:

public class YourAjaxExceptionHandlerFactory extends ExceptionHandlerFactory {

    private ExceptionHandlerFactory wrapped;

    public YourAjaxExceptionHandlerFactory(ExceptionHandlerFactory wrapped) {
        this.wrapped = wrapped;
    }

    @Override
    public ExceptionHandler getExceptionHandler() {
        return new YourAjaxExceptionHandler(getWrapped().getExceptionHandler());
    }

    @Override
    public ExceptionHandlerFactory getWrapped() {
        return wrapped;
    }

}

In order to get this to run, register it as factory in faces-config.xml the usual way (don't forget to remove the original registration for FullAjaxExceptionHandlerFactory):

<factory>
    <exception-handler-factory>com.example.YourExceptionHandlerFactory</exception-handler-factory>
</factory>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!