예제 #1
0
  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 (null == validator) {
      factory = Validation.byDefaultProvider().configure().buildValidatorFactory();
      validator = factory.getValidator();
    }

    out.print("<p>");
    out.print("Obtained ValidatorFactory: " + factory + ".");
    out.print("</p>");

    return validator;
  }
예제 #2
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 @Override
 public Configuration<?> configure() {
   return new ConfigurationWrapper(bootstrap.configure());
 }
예제 #3
0
 @Override
 public GenericBootstrap providerResolver(ValidationProviderResolver resolver) {
   this.bootstrap = bootstrap.providerResolver(resolver);
   return this;
 }