/** * Deserializes the given message. * * @param action * @return * @throws Exception */ public T deserialize(WebSocketAction action) throws Exception { // first deserialize T message = null; if (messageClass != null) { message = serDe.deserialize(new ByteBufferBackedInputStream(rawData), messageClass); } // then validate if (message != null && action.shouldValidatePayload()) { SpringValidatorAdapter validatorAdapter = new SpringValidatorAdapter(messageValidator); BeanPropertyBindingResult result = new BeanPropertyBindingResult(message, messageClass.getName()); validatorAdapter.validate(message, result); if (result.hasErrors()) { throw new MethodArgumentNotValidException(new MethodParameter(action.getMethod(), action.getPayloadParameterIndex()), result); } } return message; }
@Test public void testValidationErrorCanBeSuppressed() throws Exception { this.validator = new SpringValidatorAdapter( Validation.buildDefaultValidatorFactory().getValidator()); setupFactory(); this.factory.setExceptionIfInvalid(false); bindFoo("bar: blah"); }
private BindException validate(SignupForm form) { BindException errors; errors = new BindException(form, "signupForm"); LazyValidatorFactory lvf = new LazyValidatorFactory(); Validator validator = new SpringValidatorAdapter(lvf.getValidator()); ValidationUtils.invokeValidator(validator, form, errors); return errors; }
@Test(expected = BindException.class) public void testMissingPropertyCausesValidationError() throws Exception { this.validator = new SpringValidatorAdapter( Validation.buildDefaultValidatorFactory().getValidator()); createFoo("bar: blah"); }
@Test(expected = BindException.class) public void missingPropertyCausesValidationError() throws Exception { this.validator = new SpringValidatorAdapter( Validation.buildDefaultValidatorFactory().getValidator()); createFoo("bar: blah"); }
private ValidatorWrapper(Validator validator) { super(); this.validator = validator; this.adapter = new SpringValidatorAdapter(validator); }
@InitBinder public void initBinder(WebDataBinder binder) { binder.setValidator(new SpringValidatorAdapter(messageValidator)); }
/** * <p>Constructor for CustomValidator.</p> * * @param validator a {@link javax.validation.Validator} object. */ public CustomValidator(javax.validation.Validator validator) { this.springValidator = new SpringValidatorAdapter(validator); }