Search in sources :

Example 16 with ExceptionToCatchEvent

use of org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent in project deltaspike by apache.

the class CallingHandlersTest method assertAdditionalParamsAreInjected.

@Test
public void assertAdditionalParamsAreInjected() {
    bm.fireEvent(new ExceptionToCatchEvent(new RuntimeException(new IllegalArgumentException())));
    assertTrue(calledExceptionHandler.isBeanmanagerInjected());
}
Also used : ExceptionToCatchEvent(org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent) Test(org.junit.Test)

Example 17 with ExceptionToCatchEvent

use of org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent in project deltaspike by apache.

the class BridgeExceptionHandlerWrapper method handle.

@Override
public void handle() throws FacesException {
    FacesContext context = FacesContext.getCurrentInstance();
    if (context == null || context.getResponseComplete()) {
        return;
    }
    Iterable<ExceptionQueuedEvent> exceptionQueuedEvents = getUnhandledExceptionQueuedEvents();
    if (exceptionQueuedEvents != null && exceptionQueuedEvents.iterator() != null) {
        Iterator<ExceptionQueuedEvent> iterator = exceptionQueuedEvents.iterator();
        while (iterator.hasNext()) {
            Throwable throwable = iterator.next().getContext().getException();
            Throwable rootCause = getRootCause(throwable);
            if (rootCause instanceof AccessDeniedException) {
                processAccessDeniedException(rootCause);
                iterator.remove();
                continue;
            } else {
                ExceptionToCatchEvent event = new ExceptionToCatchEvent(rootCause, exceptionQualifier);
                event.setOptional(true);
                beanManager.fireEvent(event);
                if (event.isHandled()) {
                    iterator.remove();
                }
            }
            // a handle method might redirect and set responseComplete
            if (context.getResponseComplete()) {
                break;
            }
        }
    }
    super.handle();
}
Also used : FacesContext(javax.faces.context.FacesContext) ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) ErrorViewAwareAccessDeniedException(org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException) AccessDeniedException(org.apache.deltaspike.security.api.authorization.AccessDeniedException) ExceptionToCatchEvent(org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent)

Aggregations

ExceptionToCatchEvent (org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent)17 Test (org.junit.Test)12 FacesContext (javax.faces.context.FacesContext)2 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)2 AccessDeniedException (org.apache.deltaspike.security.api.authorization.AccessDeniedException)2 ErrorViewAwareAccessDeniedException (org.apache.deltaspike.security.api.authorization.ErrorViewAwareAccessDeniedException)2 SQLException (java.sql.SQLException)1