Interface Interceptor<T extends org.mule.runtime.api.meta.model.ComponentModel>
public interface Interceptor<T extends org.mule.runtime.api.meta.model.ComponentModel>
Taps into different phases of the execution of an extension's operation allowing to take different actions depending on the
phase.
One instance of each implementation will be created per
ConfigurationInstance. Those instances can have lifecycle, can
be stateful and can use JSR-330 annotations for dependency injection. However, they MUST be thread-safe and
reusable.- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidafter(ExecutionContext<T> executionContext, Object result) Executes after the execution of an operation is finished, regardless of it being successful or not.default voidbefore(ExecutionContext<T> executionContext) Executes before the operation is executed.default ThrowableonError(ExecutionContext<T> executionContext, Throwable exception) Executes when the execution of an operation threw exception.default voidonSuccess(ExecutionContext<T> executionContext, Object result) Executes when an operation was successfully executed.
-
Method Details
-
before
Executes before the operation is executed. If this method fails, the exception will be bubbled up right away. No other method in this interceptor will be executed (not even theafter(ExecutionContext, Object), nor any other of the interceptors in line will be executed either. Because of this, no implementation should rely on the execution of any other method in this or other interceptor- Parameters:
executionContext- theExecutionContextfor the operation to be executed- Throws:
Exception- in case of error
-
onSuccess
Executes when an operation was successfully executed. Implementations of this method should not fail. If they do throw any exception, it will be logged and ignored. Theafter(ExecutionContext, Object)method is guaranteed to be executed regardless of this method's outcome inthisor other involved instances- Parameters:
executionContext- theExecutionContextthat was used to execute the operationresult- the result of the operation. Can benullif the operation itself returned that.
-
onError
Executes when the execution of an operation threw exception. This method returnsExceptionto allow implementations to decorate, enrich or even replace the exception that will be bubbled up. Implementations however are not obligated to do such thing in which case they should return the sameexceptionsupplied. Notice however that: Implementations of this method should not fail. If they do throw any exception, it will be logged and ignored. The-
The next interceptor in line will receive the exception returned by this method, which might not be the same one supplied in
this invokation.
-
There's no guarantee that the exception returned by this method will be the one bubbled up, since the next interceptor in
line might also change it.
after(ExecutionContext, Object)method is guaranteed to be executed regardless of this method's outcome inthisor other involved instances- Parameters:
executionContext- theExecutionContextthat was used to execute the operationexception- theExceptionthat was thrown by the failing operation- Returns:
- the
Exceptionthat should be propagated forward
-
after
Executes after the execution of an operation is finished, regardless of it being successful or not. In practical terms, it executes after theonSuccess(ExecutionContext, Object)oronError(ExecutionContext, Throwable)but it doesn't execute ifbefore(ExecutionContext)threw exception. Theresultargument holds the return value of the operation. Because this method is invoked even if the operation failed, then theresultwill be anullin such a case. However, notice that testingresultfor beingnullis not an indicator of the operation having failed or not, since the operation might have successfully returnednull. This method should be used for actions that should take place "no matter what". Actions that should depend on the operation's outcome are to be implemented usingonSuccess(ExecutionContext, Object)oronError(ExecutionContext, Throwable)- Parameters:
executionContext- theExecutionContextthat was used to execute the operationresult- the result of the operation. Can benullif the operation itself returned that or failed.
-