Search in sources :

Example 6 with ExceptionToCatchEvent

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

the class BridgeExceptionHandlerWrapper method processEvent.

@Override
public void processEvent(SystemEvent event) throws AbortProcessingException {
    //needed because #handle gets called too late in this case
    if (event instanceof ExceptionQueuedEvent) {
        ExceptionQueuedEvent exceptionQueuedEvent = (ExceptionQueuedEvent) event;
        FacesContext facesContext = exceptionQueuedEvent.getContext().getContext();
        if (facesContext.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE && exceptionQueuedEvent.getContext().inBeforePhase()) {
            Throwable exception = getRootCause(exceptionQueuedEvent.getContext().getException());
            if (exception instanceof AccessDeniedException) {
                processAccessDeniedException(exception);
            } else {
                ExceptionToCatchEvent exceptionToCatchEvent = new ExceptionToCatchEvent(exception);
                exceptionToCatchEvent.setOptional(true);
                this.beanManager.fireEvent(exceptionToCatchEvent);
                if (exceptionToCatchEvent.isHandled()) {
                    return;
                }
            }
        }
    }
    super.processEvent(event);
}
Also used : ExceptionQueuedEvent(javax.faces.event.ExceptionQueuedEvent) FacesContext(javax.faces.context.FacesContext) 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)

Example 7 with ExceptionToCatchEvent

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

the class TraversalPathTest method testTraversalPathOrder.

/**
     * Tests SEAMCATCH-32, see JIRA for more information about this test. https://issues.jboss.org/browse/SEAMCATCH-32
     */
@Test
public void testTraversalPathOrder() {
    // create an exception stack E1 -> E2 -> E3
    Exceptions.Exception1 exception = new Exceptions.Exception1(new Exceptions.Exception2(new Exceptions.Exception3()));
    manager.fireEvent(new ExceptionToCatchEvent(exception));
    /*
            handleException3SuperclassBF
            handleException3BF
            handleException3DF
            handleException3SuperclassDF
            handleException2BF
            handleException2DF
            handleException1BF
            handleException1DF
        */
    Object[] expectedOrder = { 1, 2, 3, 4, 5, 6, 7, 8 };
    assertArrayEquals(expectedOrder, ExceptionHandlerMethods.getExecutionorder().toArray());
}
Also used : ExceptionToCatchEvent(org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent) Test(org.junit.Test)

Example 8 with ExceptionToCatchEvent

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

the class CallingHandlersTest method assertProtectedHandlersAreCalled.

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

Example 9 with ExceptionToCatchEvent

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

the class OSValidator method validOS.

public void validOS(final String os) {
    if (os.toLowerCase().contains("win")) {
        // can be a caugh exceptino
        final Exception ex = new OSRuntimeException();
        exceptionEvent.fire(new ExceptionToCatchEvent(ex));
    }
}
Also used : ExceptionToCatchEvent(org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent)

Example 10 with ExceptionToCatchEvent

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

the class UnMuteHandlerTest method assertCorrectNumberOfCallsForUnMute.

@Test
public void assertCorrectNumberOfCallsForUnMute() {
    bm.fireEvent(new ExceptionToCatchEvent(new Exception(new NullPointerException())));
    assertEquals(2, unMuteHandler.getDepthFirstNumberCalled());
    assertEquals(2, unMuteHandler.getBreadthFirstNumberCalled());
}
Also used : ExceptionToCatchEvent(org.apache.deltaspike.core.api.exception.control.event.ExceptionToCatchEvent) Test(org.junit.Test)

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