@Test public void testInterceptorWithMissingMandatory() { InterceptorResult result = interceptor.invoke(null, mockOperationKey1, new Object[] {null, "2" } ); assertNotNull(result); assertEquals(InterceptorState.FORCE_ON_EXCEPTION, result.getState()); assertTrue(result.getResult() instanceof CougarValidationException); }
@Override public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { OperationDefinition operationDefinition = bev.getOperationDefinition(key); Parameter[] parms = operationDefinition.getParameters(); 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)); } } } return SUCCESS; }
MandatoryCheckInterceptor implements ExecutionPreProcessor { @Override public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { OperationDefinition operationDefinition = bev.getOperationDefinition(key); Parameter[] parms = operationDefinition.getParameters(); 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)); } } } return SUCCESS; } }
MandatoryCheckInterceptor implements ExecutionPreProcessor { @Override public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { OperationDefinition operationDefinition = bev.getOperationDefinition(key); Parameter[] parms = operationDefinition.getParameters(); 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)); } } } return SUCCESS; } MandatoryCheckInterceptor(ExecutionVenue bev); }
MandatoryCheckInterceptor implements ExecutionPreProcessor { @Override public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { OperationDefinition operationDefinition = bev.getOperationDefinition(key); Parameter[] parms = operationDefinition.getParameters(); 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)); } } } return SUCCESS; } MandatoryCheckInterceptor(ExecutionVenue bev); @Override InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args); String getName(); @Override ExecutionRequirement getExecutionRequirement(); }
MandatoryCheckInterceptor implements ExecutionPreProcessor { @Override public InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args) { OperationDefinition operationDefinition = bev.getOperationDefinition(key); Parameter[] parms = operationDefinition.getParameters(); 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)); } } } return SUCCESS; } MandatoryCheckInterceptor(ExecutionVenue bev); @Override InterceptorResult invoke(ExecutionContext ctx, OperationKey key, Object[] args); String getName(); @Override ExecutionRequirement getExecutionRequirement();  }