use of javax.validation.ValidatorFactory in project java-chassis by ServiceComb.
the class ParameterValidator method beforeMethodInvoke.
@Override
public <T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation, Object[] args) throws ConstraintViolationException {
if (paramValidationEnabled.get()) {
if (null == executableValidator) {
ValidatorFactory factory = Validation.byDefaultProvider().configure().parameterNameProvider(new DefaultParameterNameProvider()).messageInterpolator(messageInterpolator()).buildValidatorFactory();
executableValidator = factory.getValidator().forExecutables();
}
Set<ConstraintViolation<Object>> violations = executableValidator.validateParameters(producerOperation.getProducerInstance(), producerOperation.getProducerMethod(), args, Default.class);
if (violations.size() > 0) {
LOGGER.warn("Parameter validation failed : " + violations.toString());
throw new ConstraintViolationException(violations);
}
}
}
use of javax.validation.ValidatorFactory in project dropwizard by dropwizard.
the class BootstrapTest method canUseCustomValidatorFactory.
@Test
void canUseCustomValidatorFactory() throws Exception {
ValidatorFactory factory = Validation.byProvider(HibernateValidator.class).configure().buildValidatorFactory();
bootstrap.setValidatorFactory(factory);
assertThat(bootstrap.getValidatorFactory()).isSameAs(factory);
}
use of javax.validation.ValidatorFactory in project c4sg-services by Code4SocialGood.
the class CategoryCustomListTest method setUp.
@BeforeClass
public static void setUp() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
use of javax.validation.ValidatorFactory in project AngularBeans by bessemHmidi.
the class BeanValidator method validate.
public Set validate(Object bean) {
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Validator validator = vf.getValidator();
Set<ConstraintViolation<Object>> errors = validator.validate(bean);
for (ConstraintViolation<Object> violation : errors) {
System.out.println((violation.getInvalidValue()) + ":" + violation.getMessage());
// System.out.println(violation.getClass());
}
return errors;
}
use of javax.validation.ValidatorFactory in project chassis by Kixeye.
the class TransportConfiguration method messageValidator.
@Bean
public Validator messageValidator() {
// force hibernate validator to log to slf4j
System.setProperty("org.jboss.logging.provider", "slf4j");
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
return factory.getValidator();
}
Aggregations