Search in sources :

Example 1 with Configuration

use of javax.validation.Configuration 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;
}
Also used : Configuration(javax.validation.Configuration) ValidatorFactory(javax.validation.ValidatorFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ValidatorContext(javax.validation.ValidatorContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GenericBootstrap(javax.validation.bootstrap.GenericBootstrap) Validator(javax.validation.Validator) PrintWriter(java.io.PrintWriter)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 PrintWriter (java.io.PrintWriter)1 Configuration (javax.validation.Configuration)1 Validator (javax.validation.Validator)1 ValidatorContext (javax.validation.ValidatorContext)1 ValidatorFactory (javax.validation.ValidatorFactory)1 GenericBootstrap (javax.validation.bootstrap.GenericBootstrap)1