use of javax.validation.spi.ValidationProvider in project jo-client-platform by jo-source.
the class HibernateBeanValidatorFactory method create.
@Override
public Validator create() {
final ValidationProviderResolver validationProviderResolver = new ValidationProviderResolver() {
@Override
public List<ValidationProvider<?>> getValidationProviders() {
final List<ValidationProvider<?>> result = new LinkedList<ValidationProvider<?>>();
result.add(new HibernateValidator());
return result;
}
};
final ProviderSpecificBootstrap<HibernateValidatorConfiguration> bootstrap = Validation.byProvider(HibernateValidator.class);
bootstrap.providerResolver(validationProviderResolver);
final HibernateValidatorConfiguration validatorConfiguration = bootstrap.configure();
return validatorConfiguration.buildValidatorFactory().getValidator();
}
use of javax.validation.spi.ValidationProvider in project cxf by apache.
the class BookStore method createBookValidate.
@POST
@Path("/books-validate")
public Response createBookValidate(Book book) {
assertInjections();
BeanValidationProvider prov = new BeanValidationProvider(new ValidationProviderResolver() {
@Override
public List<ValidationProvider<?>> getValidationProviders() {
ValidationProvider<HibernateValidatorConfiguration> prov = new HibernateValidator();
List<ValidationProvider<?>> provs = new ArrayList<>();
provs.add(prov);
return provs;
}
}, HibernateValidator.class);
try {
prov.validateBean(book);
} catch (ConstraintViolationException cve) {
StringBuilder violationMessages = new StringBuilder();
for (ConstraintViolation<?> constraintViolation : cve.getConstraintViolations()) {
violationMessages.append(constraintViolation.getPropertyPath()).append(": ").append(constraintViolation.getMessage()).append("\n");
}
return Response.status(Response.Status.BAD_REQUEST).type("text/plain").entity(violationMessages.toString()).build();
}
return createBook(book);
}
Aggregations