use of jakarta.validation.Validator in project gocd-groovy-dsl-config-plugin by gocd-contrib.
the class TestBase method validate.
protected static void validate(Object object, Consumer<Set<ConstraintViolation<Object>>> errorHandler) {
ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
Validator validator = validatorFactory.getValidator();
Set<ConstraintViolation<Object>> violations = validator.validate(object);
if (!violations.isEmpty()) {
errorHandler.accept(violations);
}
}
use of jakarta.validation.Validator in project resteasy by resteasy.
the class GeneralValidatorImpl method getValidator.
protected Validator getValidator(HttpRequest request) {
Validator v = Validator.class.cast(request.getAttribute(Validator.class.getName()));
if (v == null) {
Locale locale = getLocale(request);
if (locale == null) {
v = validatorFactory.getValidator();
} else {
MessageInterpolator interpolator = new LocaleSpecificMessageInterpolator(validatorFactory.getMessageInterpolator(), locale);
v = validatorFactory.usingContext().messageInterpolator(interpolator).getValidator();
}
request.setAttribute(Validator.class.getName(), v);
}
return v;
}
use of jakarta.validation.Validator in project resteasy by resteasy.
the class GeneralValidatorImpl method validateAllParameters.
@Override
public void validateAllParameters(HttpRequest request, Object object, Method method, Object[] parameterValues, Class<?>... groups) {
if (method.getParameterCount() == 0) {
checkViolations(request);
return;
}
Validator validator = getValidator(request);
SimpleViolationsContainer violationsContainer = getViolationsContainer(request, object);
Set<ConstraintViolation<Object>> cvs = null;
try {
cvs = validator.forExecutables().validateParameters(object, method, parameterValues, groups);
} catch (Exception e) {
violationsContainer.setException(e);
throw toValidationException(e, violationsContainer);
}
violationsContainer.addViolations(cvs);
if ((violationsContainer.isFieldsValidated() || !GetRestful.isRootResource(object.getClass()) || hasApplicationScope(object)) && violationsContainer.size() > 0) {
throw new ResteasyViolationExceptionImpl(violationsContainer, request.getHttpHeaders().getAcceptableMediaTypes());
}
}
use of jakarta.validation.Validator in project resteasy by resteasy.
the class GeneralValidatorImpl method validate.
@Override
public void validate(HttpRequest request, Object object, Class<?>... groups) {
Validator validator = getValidator(request);
Set<ConstraintViolation<Object>> cvs = null;
SimpleViolationsContainer violationsContainer = getViolationsContainer(request, object);
if (alreadyFoundClassOrPropertyConstraint(violationsContainer)) {
return;
}
try {
cvs = validator.validate(object, groups);
} catch (Exception e) {
violationsContainer.setException(e);
violationsContainer.setFieldsValidated(true);
throw toValidationException(e, violationsContainer);
}
violationsContainer.addViolations(cvs);
violationsContainer.setFieldsValidated(true);
}
use of jakarta.validation.Validator in project resteasy by resteasy.
the class GeneralValidatorImpl method validateReturnValue.
@Override
public void validateReturnValue(HttpRequest request, Object object, Method method, Object returnValue, Class<?>... groups) {
Validator validator = getValidator(request);
SimpleViolationsContainer violationsContainer = getViolationsContainer(request, object);
Set<ConstraintViolation<Object>> cvs = null;
try {
cvs = validator.forExecutables().validateReturnValue(object, method, returnValue, groups);
} catch (Exception e) {
violationsContainer.setException(e);
throw toValidationException(e, violationsContainer);
}
violationsContainer.addViolations(cvs);
if (violationsContainer.size() > 0) {
throw new ResteasyViolationExceptionImpl(violationsContainer, request.getHttpHeaders().getAcceptableMediaTypes());
}
}
Aggregations