use of javax.validation.ValidationProviderResolver 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.ValidationProviderResolver 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);
}
use of javax.validation.ValidationProviderResolver in project camel by apache.
the class ValidatorFactories method buildValidatorFactory.
public static ValidatorFactory buildValidatorFactory(boolean osgi, ValidationProviderResolver validationProviderResolver, MessageInterpolator messageInterpolator, TraversableResolver traversableResolver, ConstraintValidatorFactory constraintValidatorFactory) {
ValidationProviderResolver resolvedValidationProviderResolver = resolveValidationProviderResolver(osgi, validationProviderResolver);
GenericBootstrap bootstrap = Validation.byDefaultProvider();
if (resolvedValidationProviderResolver != null) {
bootstrap.providerResolver(resolvedValidationProviderResolver);
}
Configuration<?> configuration = bootstrap.configure();
if (messageInterpolator != null) {
configuration.messageInterpolator(messageInterpolator);
}
if (traversableResolver != null) {
configuration.traversableResolver(traversableResolver);
}
if (constraintValidatorFactory != null) {
configuration.constraintValidatorFactory(constraintValidatorFactory);
}
return configuration.buildValidatorFactory();
}
Aggregations