Search in sources :

Example 1 with Interceptor

use of org.mule.runtime.extension.api.runtime.operation.Interceptor in project mule by mulesoft.

the class DefaultExecutionMediator method before.

InterceptorsExecutionResult before(ExecutionContext executionContext, List<Interceptor> interceptors) {
    List<Interceptor> interceptorList = new ArrayList<>();
    try {
        for (Interceptor interceptor : interceptors) {
            interceptorList.add(interceptor);
            interceptor.before(executionContext);
        }
    } catch (Exception e) {
        return new InterceptorsExecutionResult(exceptionEnricherManager.handleThrowable(e), interceptorList);
    }
    return new InterceptorsExecutionResult(null, interceptorList);
}
Also used : ArrayList(java.util.ArrayList) Interceptor(org.mule.runtime.extension.api.runtime.operation.Interceptor) ExceptionUtils.extractConnectionException(org.mule.runtime.core.api.util.ExceptionUtils.extractConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException)

Example 2 with Interceptor

use of org.mule.runtime.extension.api.runtime.operation.Interceptor in project mule by mulesoft.

the class DefaultExecutionMediatorTestCase method retry.

@Test
public void retry() throws Throwable {
    stubException();
    Interceptor interceptor = mock(Interceptor.class);
    setInterceptors((Interceptable) configurationInstance, interceptor);
    setInterceptors((Interceptable) operationExecutor);
    defineOrder(interceptor);
    assertException(exception -> {
        assertThat(exception, instanceOf(ConnectionException.class));
        try {
            verify(interceptor, times(RETRY_COUNT + 1)).before(operationContext);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        verify(interceptor, times(RETRY_COUNT + 1)).onError(same(operationContext), anyVararg());
        verify(interceptor, times(RETRY_COUNT + 1)).after(operationContext, null);
    });
}
Also used : Interceptor(org.mule.runtime.extension.api.runtime.operation.Interceptor) ConnectionException(org.mule.runtime.api.connection.ConnectionException) HeisenbergException(org.mule.test.heisenberg.extension.exception.HeisenbergException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) MuleException(org.mule.runtime.api.exception.MuleException) ExpectedException(org.junit.rules.ExpectedException) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ConnectionException (org.mule.runtime.api.connection.ConnectionException)2 Interceptor (org.mule.runtime.extension.api.runtime.operation.Interceptor)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 ExceptionUtils.extractConnectionException (org.mule.runtime.core.api.util.ExceptionUtils.extractConnectionException)1 SmallTest (org.mule.tck.size.SmallTest)1 HeisenbergException (org.mule.test.heisenberg.extension.exception.HeisenbergException)1