/** * Validate the payload if applicable. * <p>The default implementation checks for {@code @javax.validation.Valid}, * Spring's {@link org.springframework.validation.annotation.Validated}, * and custom annotations whose name starts with "Valid". * @param message the currently processed message * @param parameter the method parameter * @param target the target payload object * @throws MethodArgumentNotValidException in case of binding errors */ protected void validate(Message<?> message, MethodParameter parameter, Object target) { if (this.validator == null) { return; } for (Annotation ann : parameter.getParameterAnnotations()) { Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class); if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) { Object hints = (validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann)); Object[] validationHints = (hints instanceof Object[] ? (Object[]) hints : new Object[] {hints}); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(target, getParameterName(parameter)); if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator) { ((SmartValidator) this.validator).validate(target, bindingResult, validationHints); } else { this.validator.validate(target, bindingResult); } if (bindingResult.hasErrors()) { throw new MethodArgumentNotValidException(message, parameter, bindingResult); } break; } } }
protected void validate(Message<?> message, MethodParameter parameter, Object target) { if (this.validator == null) { return; } for (Annotation ann : parameter.getParameterAnnotations()) { Validated validatedAnn = AnnotationUtils.getAnnotation(ann, Validated.class); if (validatedAnn != null || ann.annotationType().getSimpleName().startsWith("Valid")) { Object hints = validatedAnn != null ? validatedAnn.value() : AnnotationUtils.getValue(ann); Object[] validationHints = hints instanceof Object[] ? (Object[]) hints : new Object[] { hints }; BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult( target, getParameterName(parameter)); if (!ObjectUtils.isEmpty(validationHints) && this.validator instanceof SmartValidator) { ((SmartValidator) this.validator).validate(target, bindingResult, validationHints); } else { this.validator.validate(target, bindingResult); } if (bindingResult.hasErrors()) { throw new MethodArgumentNotValidException(message, parameter, bindingResult); } break; } } }
public InitiativeServiceImpl(InitiativeDao initiativeDao, ReviewHistoryDao reviewHistoryDao, UserService userService, EmailService emailService, EncryptionService encryptionService, SmartValidator validator, InitiativeSettings initiativeSettings, HashCreator hashCreator) { this.initiativeDao = initiativeDao; this.reviewHistoryDao = reviewHistoryDao; this.userService = userService; this.emailService = emailService; this.encryptionService = encryptionService; this.validator = validator; this.initiativeSettings = initiativeSettings; this.hashCreator = hashCreator; }
public SmartValidator getSmartValidator() { return smartValidator; }
protected EntityValidatorImpl(SmartValidator smartValidator){ this.smartValidator = smartValidator; }