Search in sources :

Example 1 with ValidationProviderResolver

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();
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) ValidationProvider(javax.validation.spi.ValidationProvider) ValidationProviderResolver(javax.validation.ValidationProviderResolver) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) LinkedList(java.util.LinkedList)

Example 2 with ValidationProviderResolver

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);
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider) ValidationProvider(javax.validation.spi.ValidationProvider) ConstraintViolation(javax.validation.ConstraintViolation) ValidationProviderResolver(javax.validation.ValidationProviderResolver) ConstraintViolationException(javax.validation.ConstraintViolationException) ArrayList(java.util.ArrayList) List(java.util.List) BeanValidationProvider(org.apache.cxf.validation.BeanValidationProvider) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with ValidationProviderResolver

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();
}
Also used : ValidationProviderResolver(javax.validation.ValidationProviderResolver) GenericBootstrap(javax.validation.bootstrap.GenericBootstrap)

Aggregations

ValidationProviderResolver (javax.validation.ValidationProviderResolver)3 ValidationProvider (javax.validation.spi.ValidationProvider)2 HibernateValidator (org.hibernate.validator.HibernateValidator)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ConstraintViolation (javax.validation.ConstraintViolation)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 GenericBootstrap (javax.validation.bootstrap.GenericBootstrap)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 BeanValidationProvider (org.apache.cxf.validation.BeanValidationProvider)1 HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)1