use of javax.validation.ValidatorFactory in project torodb by torodb.
the class ConfigUtils method validateBean.
public static <T> void validateBean(T config) {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<T>> constraintViolations = validator.validate(config);
if (!constraintViolations.isEmpty()) {
IllegalArgumentException illegalArgumentException = transformConstraintsValidation(constraintViolations);
throw illegalArgumentException;
}
}
use of javax.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class TypeSafeActivator method activate.
@SuppressWarnings("UnusedDeclaration")
public static void activate(ActivationContext activationContext) {
final ValidatorFactory factory;
try {
factory = getValidatorFactory(activationContext);
} catch (IntegrationException e) {
if (activationContext.getValidationModes().contains(ValidationMode.CALLBACK)) {
throw new IntegrationException("Bean Validation provider was not available, but 'callback' validation was requested", e);
}
if (activationContext.getValidationModes().contains(ValidationMode.DDL)) {
throw new IntegrationException("Bean Validation provider was not available, but 'ddl' validation was requested", e);
}
LOG.debug("Unable to acquire Bean Validation ValidatorFactory, skipping activation");
return;
}
applyRelationalConstraints(factory, activationContext);
applyCallbackListeners(factory, activationContext);
}
use of javax.validation.ValidatorFactory in project hibernate-orm by hibernate.
the class TypeSafeActivator method getValidatorFactory.
private static ValidatorFactory getValidatorFactory(ActivationContext activationContext) {
// IMPL NOTE : We can either be provided a ValidatorFactory or make one. We can be provided
// a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory in the following order:
// 1) Look into SessionFactoryOptions.getValidatorFactoryReference()
// 2) Look into ConfigurationService
// 3) build a new ValidatorFactory
// 1 - look in SessionFactoryOptions.getValidatorFactoryReference()
ValidatorFactory factory = resolveProvidedFactory(activationContext.getSessionFactory().getSessionFactoryOptions());
if (factory != null) {
return factory;
}
// 2 - look in ConfigurationService
factory = resolveProvidedFactory(activationContext.getServiceRegistry().getService(ConfigurationService.class));
if (factory != null) {
return factory;
}
// 3 - build our own
try {
return Validation.buildDefaultValidatorFactory();
} catch (Exception e) {
throw new IntegrationException("Unable to build the default ValidatorFactory", e);
}
}
use of javax.validation.ValidatorFactory in project fb-botmill by BotMill.
the class FbBotMillBean method validate.
/**
* Validates the {@link FbBotMillResponse}.
*
* @param response
* the response
* @return true if the response is valid, false otherwise.
*/
protected boolean validate(FbBotMillResponse response) {
// If validations are not enabled, returns true.
if (!FbBotMillContext.getInstance().isValidationEnabled()) {
return true;
}
boolean valid = true;
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<FbBotMillResponse>> violations = validator.validate(response);
for (ConstraintViolation<FbBotMillResponse> v : violations) {
valid = false;
logger.error("FbBotMillResponse validation error. Message: [{}] Value: [{}], Class: [{}], Field: [{}]", v.getMessage(), v.getInvalidValue(), v.getRootBean(), v.getPropertyPath());
}
if (valid == false) {
// Sends the constraint violations through the callback.
List<FbBotMillMonitor> registeredMonitors = FbBotMillContext.getInstance().getRegisteredMonitors();
for (FbBotMillMonitor monitor : registeredMonitors) {
monitor.onValidationError(response, violations);
}
}
return valid;
}
use of javax.validation.ValidatorFactory in project ORCID-Source by ORCID.
the class ChangeSecurityDetailsValidatorTest method resetValidator.
@Before
public void resetValidator() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
}
Aggregations