use of javax.validation.Validator in project tomee by apache.
the class BeanValidationTest method lookupValidator.
@Test
public void lookupValidator() throws Exception {
final Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator");
assertNotNull(validator);
}
use of javax.validation.Validator in project tomee by apache.
the class BeanValidationTest method injectionValidator.
@Test
public void injectionValidator() {
final Validator validator = persistManager.getValidator();
assertNotNull(validator);
}
use of javax.validation.Validator in project opennms by OpenNMS.
the class EventRestService method publishEvent.
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_ATOM_XML })
@Transactional
public Response publishEvent(final org.opennms.netmgt.xml.event.Event event) {
if (event.getSource() == null) {
event.setSource("ReST");
}
if (event.getTime() == null) {
event.setTime(new Date());
}
try {
final Validator validator = factory.getValidator();
final Set<ConstraintViolation<org.opennms.netmgt.xml.event.Event>> errors = validator.validate(event);
LOG.debug("got errors: {}", errors);
if (errors.size() > 0) {
final StringBuilder sb = new StringBuilder("Error validating event:\n");
for (final ConstraintViolation<?> error : errors) {
sb.append(error.toString()).append("\n");
}
LOG.debug(sb.toString());
throw getException(Status.BAD_REQUEST, errors.size() + " errors found while validating event.");
}
m_eventForwarder.sendNow(event);
return Response.accepted().build();
} catch (final Exception e) {
throw getException(Status.BAD_REQUEST, e.getMessage());
}
}
use of javax.validation.Validator in project dropwizard by dropwizard.
the class ConfigurationValidationExceptionTest method setUp.
@Before
public void setUp() throws Exception {
assumeThat(Locale.getDefault().getLanguage(), is("en"));
final Validator validator = BaseValidator.newValidator();
final Set<ConstraintViolation<Example>> violations = validator.validate(new Example());
this.e = new ConfigurationValidationException("config.yml", violations);
}
use of javax.validation.Validator in project JessMA by ldcsaa.
the class HibernateBeanValidator method validate.
@Override
public Set<ConstraintViolation<Object>> validate(final Object bean, final Class<?>[] groups, final String bundle, final Locale locale) {
ValidatorKey key = new ValidatorKey(groups, bundle, locale);
Validator validator = validatorMap.get(key);
if (validator == null)
validator = tryCreateValidator(bundle, locale, key);
return validator.validate(bean, groups);
}
Aggregations