Package com.betfair.cougar.core.api.ev

Examples of com.betfair.cougar.core.api.ev.InterceptorResult


    for (int i = 0 ; i < args.length; i++) {

        if (args[i] == null) {
              if (parms[i].isMandatory()) {
                return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                    new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                        "Mandatory attributes not defined for parameter '"+parms[i].getName() + "'"));
              }
          } else {
                try {
                    ValidationUtils.validateMandatory(args[i]);
                } catch (IllegalArgumentException e) {
                    return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                            new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                                    "Embedded fields not defined for parameter '"+parms[i].getName() + "'", e));
                }
          }
    }
View Full Code Here


    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(interceptorResult);
                } else if (interceptorResult instanceof CougarApplicationException) {
                    executionResult = new ExecutionResult(interceptorResult);
                } else if (result.getResult() instanceof Exception) {
                    executionResult = new ExecutionResult(
                            new CougarFrameworkException(ServerFaultCode.ServiceRuntimeException,
                                    "Interceptor forced exception", (Exception)result.getResult()));
                } else {
                    // onException forced, but result is not an exception
                    executionResult = new ExecutionResult(
                            new CougarFrameworkException(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()));
            }
        }
    }
View Full Code Here

        }
    }


    private static InterceptorResult invokePreProcessingInterceptors(List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPreProcessor> unexecutedPreExecutionInterceptorList, ExecutionRequirement phase, ExecutionContext ctx, OperationKey key, Object[] args) {
        InterceptorResult result = CONTINUE;

        List<ExecutionPreProcessor> toIterateOver = new ArrayList<>(preExecutionInterceptorList);
        for (ExecutionPreProcessor pre : toIterateOver) {
            ExecutionRequirement req = pre.getExecutionRequirement();
            if (req == ExecutionRequirement.EVERY_OPPORTUNITY || req == phase || (req == ExecutionRequirement.EXACTLY_ONCE && unexecutedPreExecutionInterceptorList.contains(pre))) {
                try {
                    result = pre.invoke(ctx, key, args);
                    unexecutedPreExecutionInterceptorList.remove(pre);
                    if (result == null || result.getState() == null) {
                        // defensive
                        throw new IllegalStateException(pre.getName() +" did not return a valid InterceptorResult");
                    }
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "Pre Processor " + pre.getName() + " has failed.");
                    logger.log(e);
                    result = new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION, e);
                    break;
                }
                if (result.getState().shouldAbortInterceptorChain()) {
                    break;
                }
            }
        }
        return result;
View Full Code Here

    @Override
    public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) {
        if (trigger.getStatus().ordinal() >= triggeringStatus.ordinal()) {
            return processor.invoke(ctx, key, args);
        }
        return new InterceptorResult(InterceptorState.CONTINUE);
    }
View Full Code Here

    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()));
            }
        }
    }
View Full Code Here

        }
    }


    private static InterceptorResult invokePreProcessingInterceptors(List<ExecutionPreProcessor> preExecutionInterceptorList, List<ExecutionPreProcessor> unexecutedPreExecutionInterceptorList, ExecutionRequirement phase, ExecutionContext ctx, OperationKey key, Object[] args) {
        InterceptorResult result = CONTINUE;

        List<ExecutionPreProcessor> toIterateOver = new ArrayList<>(preExecutionInterceptorList);
        for (ExecutionPreProcessor pre : toIterateOver) {
            ExecutionRequirement req = pre.getExecutionRequirement();
            if (req == ExecutionRequirement.EVERY_OPPORTUNITY || req == phase || (req == ExecutionRequirement.EXACTLY_ONCE && unexecutedPreExecutionInterceptorList.contains(pre))) {
                try {
                    result = pre.invoke(ctx, key, args);
                    unexecutedPreExecutionInterceptorList.remove(pre);
                    if (result == null || result.getState() == null) {
                        // defensive
                        throw new IllegalStateException(pre.getName() +" did not return a valid InterceptorResult");
                    }
                } catch (Exception e) {
                    logger.log(Level.SEVERE, "Pre Processor " + pre.getName() + " has failed.");
                    logger.log(e);
                    result = new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION, e);
                    break;
                }
                if (result.getState().shouldAbortInterceptorChain()) {
                    break;
                }
            }
        }
        return result;
View Full Code Here

    @Override
    public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) {
        GeoLocationDetails gld = ctx.getLocation();

        if (addressClassifier.isPrivateAddress(gld.getRemoteAddr()) || addressClassifier.isLocalAddress(gld.getRemoteAddr())) {
            return new InterceptorResult(InterceptorState.CONTINUE);
        }

        return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION, new CougarServiceException(ServerFaultCode.BannedLocation, "Access not being made from private network location"));
    }
View Full Code Here

    for (int i = 0 ; i < args.length; i++) {
     
        if (args[i] == null) {
              if (parms[i].isMandatory()) {
                return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                    new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                        "Mandatory attributes not defined for parameter '"+parms[i].getName() + "'"));
              }
          } else {
                try {
                    ValidationUtils.validateMandatory(args[i]);
                } catch (IllegalArgumentException e) {
                    return new InterceptorResult(InterceptorState.FORCE_ON_EXCEPTION,
                            new CougarValidationException(ServerFaultCode.MandatoryNotDefined,
                                    "Embedded fields not defined for parameter '"+parms[i].getName() + "'", e));
                }
          }
    }
View Full Code Here

    @Override
    public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) {
        if (matcher == null || matcher.matches(ctx, key, args)) {
            return preProcessor.invoke(ctx, key, args);
        }
        return new InterceptorResult(InterceptorState.CONTINUE);
    }
View Full Code Here

    @Override
    public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args, ExecutionResult result) {
        if (matcher == null || matcher.matches(ctx, key, args)) {
            return postProcessor.invoke(ctx, key, args, result);
        }
        return new InterceptorResult(InterceptorState.CONTINUE);
    }
View Full Code Here

TOP

Related Classes of com.betfair.cougar.core.api.ev.InterceptorResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.