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;
  }
 @SuppressWarnings({"unchecked", "rawtypes"})
 @Override
 public Configuration<?> configure() {
   return new ConfigurationWrapper(bootstrap.configure());
 }
 @Override
 public GenericBootstrap providerResolver(ValidationProviderResolver resolver) {
   this.bootstrap = bootstrap.providerResolver(resolver);
   return this;
 }