private final static CougarLogger logger = CougarLoggingUtils.getLogger(InterceptingExecutableWrapper.class);
public static void execute(List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPreProcessor> unexecutedPreExecutionInterceptorList, ExecutionRequirement phase, Runnable executionBody, ExecutionContext ctx, OperationKey key, Object[] args,
ExecutionObserver observer) {
InterceptorResult result = invokePreProcessingInterceptors(preExecutionInterceptorList, unexecutedPreExecutionInterceptorList, phase, ctx, key, args);
/**
* Pre-processors can force ON_EXCEPTION or ON_RESULT without execution.
* The shouldInvoke will indicate whether actual invocation should take place.
*/
if (result.getState().shouldInvoke()) {
executionBody.run();
} else {
if (InterceptorState.FORCE_ON_EXCEPTION.equals(result.getState())) {
Object interceptorResult = result.getResult();
ExecutionResult executionResult;
if (interceptorResult instanceof CougarException) {
executionResult = new ExecutionResult((CougarException)interceptorResult);
} else if (interceptorResult instanceof CougarApplicationException) {
executionResult = new ExecutionResult((CougarApplicationException)interceptorResult);
} else if (result.getResult() instanceof Exception) {
executionResult = new ExecutionResult(
new CougarServiceException(ServerFaultCode.ServiceRuntimeException,
"Interceptor forced exception", (Exception)result.getResult()));
} else {
// onException forced, but result is not an exception
executionResult = new ExecutionResult(
new CougarServiceException(ServerFaultCode.ServiceRuntimeException,
"Interceptor forced exception, but result was not an exception - I found a " +
result.getResult()));
}
observer.onResult(executionResult);
} else if (InterceptorState.FORCE_ON_RESULT.equals(result.getState())) {
observer.onResult(new ExecutionResult(result.getResult()));
}
}
}