use of javax.validation.metadata.BeanDescriptor in project jersey by jersey.
the class DefaultConfiguredValidator method validateResult.
@Override
public void validateResult(final Object resource, final Invocable resourceMethod, final Object result) {
if (configuration.getBootstrapConfiguration().isExecutableValidationEnabled()) {
final Set<ConstraintViolation<Object>> constraintViolations = new HashSet<>();
final Method handlingMethod = resourceMethod.getHandlingMethod();
final BeanDescriptor beanDescriptor = getConstraintsForClass(resource.getClass());
final MethodDescriptor methodDescriptor = beanDescriptor.getConstraintsForMethod(handlingMethod.getName(), handlingMethod.getParameterTypes());
final Method definitionMethod = resourceMethod.getDefinitionMethod();
if (methodDescriptor != null && methodDescriptor.hasConstrainedReturnValue() && validateOnExecutionHandler.validateMethod(resource.getClass(), definitionMethod, handlingMethod)) {
constraintViolations.addAll(forExecutables().validateReturnValue(resource, handlingMethod, result));
if (result instanceof Response) {
constraintViolations.addAll(forExecutables().validateReturnValue(resource, handlingMethod, ((Response) result).getEntity()));
}
}
if (!constraintViolations.isEmpty()) {
throw new ConstraintViolationException(constraintViolations);
}
}
}
use of javax.validation.metadata.BeanDescriptor in project cuba by cuba-platform.
the class WebAbstractField method initBeanValidator.
protected void initBeanValidator() {
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
MetaClass propertyEnclosingMetaClass = metadataTools.getPropertyEnclosingMetaClass(metaPropertyPath);
Class enclosingJavaClass = propertyEnclosingMetaClass.getJavaClass();
if (enclosingJavaClass != KeyValueEntity.class && !DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
BeanValidation beanValidation = AppBeans.get(BeanValidation.NAME);
javax.validation.Validator validator = beanValidation.getValidator();
BeanDescriptor beanDescriptor = validator.getConstraintsForClass(enclosingJavaClass);
if (beanDescriptor.isBeanConstrained()) {
addValidator(new BeanValidator(enclosingJavaClass, metaProperty.getName()));
}
}
}
use of javax.validation.metadata.BeanDescriptor in project minijax by minijax.
the class MinijaxValidator method validate.
@Override
public <T> Set<ConstraintViolation<T>> validate(final T object, final Class<?>... groups) {
final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
for (final PropertyDescriptor propertyDescriptor : descriptor.getConstrainedProperties()) {
final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
validateProperty(context, propertyDescriptor, value);
}
return context.getResult();
}
use of javax.validation.metadata.BeanDescriptor in project minijax by minijax.
the class MinijaxValidator method validateProperty.
@Override
public <T> Set<ConstraintViolation<T>> validateProperty(final T object, final String propertyName, final Class<?>... groups) {
final MinijaxConstraintValidatorContext<T> context = new MinijaxConstraintValidatorContext<>(object);
final BeanDescriptor descriptor = getConstraintsForClass(object.getClass());
final PropertyDescriptor propertyDescriptor = descriptor.getConstraintsForProperty(propertyName);
final Object value = ((MinijaxPropertyDescriptor) propertyDescriptor).getValue(object);
validateProperty(context, propertyDescriptor, value);
return context.getResult();
}
use of javax.validation.metadata.BeanDescriptor in project dropwizard by dropwizard.
the class DropwizardConfiguredValidator method validateResourceAndInputParams.
@Override
public void validateResourceAndInputParams(Object resource, final Invocable invocable, Object[] objects) throws ConstraintViolationException {
final Class<?>[] groups = getGroup(invocable);
final Set<ConstraintViolation<Object>> violations = new HashSet<>();
final BeanDescriptor beanDescriptor = getConstraintsForClass(resource.getClass());
if (beanDescriptor.isBeanConstrained()) {
violations.addAll(validate(resource, groups));
}
violations.addAll(forExecutables().validateParameters(resource, invocable.getHandlingMethod(), objects, groups));
if (!violations.isEmpty()) {
throw new JerseyViolationException(violations, invocable);
}
}
Aggregations