use of javax.validation.bootstrap.GenericBootstrap 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();
}
use of javax.validation.bootstrap.GenericBootstrap in project Payara by payara.
the class BVIntegrationTestServlet method configureValidation.
private Validator configureValidation(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
GenericBootstrap bootstrap = Validation.byDefaultProvider();
Configuration config = bootstrap.configure();
InputStream mappingsXml = new ByteArrayInputStream(validationXml.getBytes());
config.addMapping(mappingsXml);
ValidatorFactory factory = config.buildValidatorFactory();
ValidatorContext validatorContext = factory.usingContext();
Validator validator = validatorContext.getValidator();
if (validator == null) {
factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
validator = factory.getValidator();
}
out.print("<p>");
out.print("Obtained ValidatorFactory: " + factory + ".");
out.print("</p>");
return validator;
}
use of javax.validation.bootstrap.GenericBootstrap in project Payara by payara.
the class ConnectorDeployer method registerBeanValidator.
private void registerBeanValidator(String rarName, ReadableArchive archive, ClassLoader classLoader) {
ClassLoader contextCL = null;
try {
contextCL = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(classLoader);
Validator beanValidator = null;
ValidatorFactory validatorFactory = null;
try {
List<String> mappingsList = getValidationMappingDescriptors(archive);
if (mappingsList.size() > 0) {
GenericBootstrap bootstrap = Validation.byDefaultProvider();
Configuration config = bootstrap.configure();
InputStream inputStream = null;
try {
for (String fileName : mappingsList) {
inputStream = archive.getEntry(fileName);
config.addMapping(inputStream);
}
validatorFactory = config.buildValidatorFactory();
ValidatorContext validatorContext = validatorFactory.usingContext();
beanValidator = validatorContext.getValidator();
} catch (IOException e) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "Exception while processing xml files for detecting " + "bean-validation-mapping", e);
}
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
// ignore ?
}
}
}
} catch (Exception e) {
Object[] params = new Object[] { rarName, e };
_logger.log(Level.WARNING, "error.processing.xml.for.bean.validation.mapping", params);
}
if (beanValidator == null) {
validatorFactory = Validation.byDefaultProvider().configure().buildValidatorFactory();
beanValidator = validatorFactory.getValidator();
}
ConnectorRegistry registry = ConnectorRegistry.getInstance();
registry.addBeanValidator(rarName, beanValidator);
} finally {
Thread.currentThread().setContextClassLoader(contextCL);
}
}
Aggregations