/** * Create a new MethodValidationInterceptor using a default JSR-303 validator underneath. */ public MethodValidationInterceptor() { this(Validation.buildDefaultValidatorFactory()); }
@Override public void afterPropertiesSet() { if (this.validator == null) { this.validator = Validation.buildDefaultValidatorFactory().getValidator(); } }
/** * Create a new MethodValidationInterceptor using a default JSR-303 validator underneath. */ public MethodValidationInterceptor() { this(Validation.buildDefaultValidatorFactory()); }
@Override public void afterPropertiesSet() { if (this.validator == null) { this.validator = Validation.buildDefaultValidatorFactory().getValidator(); } }
public static Validator getValidator() { if (validator == null) { synchronized (BeanValidator.class) { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); return validator = factory.getValidator(); } } return validator; }
@Bean(name = "validator") @ConditionalOnMissingBean(Validator.class) public Validator validator() { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); return factory.getValidator(); }
@Override public void configure(Binder binder) { binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator()); binder.bind(JsonConfigurator.class).in(LazySingleton.class); }
@Override protected void configure() { // Validator instances are thread-safe and can be reused. // See: http://hibernate.org/validator/documentation/getting-started/ // // The Validator instance creation is quite expensive. // Making this a Singleton reduced the CPU load by 50% and reduced the GC load from 5 GCs per second to 2 GCs // per second when running a load test of the collector registration endpoint. bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator()); } }
public void initialize(Map settings, ClassLoaderService classLoaderService) { if ( !initialized ) { ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); init( factory, settings, classLoaderService ); } }
@Override public void configure(Binder binder) { binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator()); binder.bind(JsonConfigurator.class).in(LazySingleton.class); binder.bind(Properties.class).toInstance(props); } },
@SuppressWarnings({"unchecked", "rawtypes"}) public JValidator(URL url) { this.clazz = ReflectUtils.forName(url.getServiceInterface()); String jvalidation = url.getParameter("jvalidation"); ValidatorFactory factory; if (jvalidation != null && jvalidation.length() > 0) { factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory(); } else { factory = Validation.buildDefaultValidatorFactory(); } this.validator = factory.getValidator(); this.methodClassMap = new ConcurrentHashMap<String, Class>(); }
@SuppressWarnings({"unchecked", "rawtypes"}) public JValidator(URL url) { this.clazz = ReflectUtils.forName(url.getServiceInterface()); String jvalidation = url.getParameter("jvalidation"); ValidatorFactory factory; if (jvalidation != null && jvalidation.length() > 0) { factory = Validation.byProvider((Class) ReflectUtils.forName(jvalidation)).configure().buildValidatorFactory(); } else { factory = Validation.buildDefaultValidatorFactory(); } this.validator = factory.getValidator(); this.methodClassMap = new ConcurrentHashMap<String, Class>(); }
@Override public void configure(Binder binder) { binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator()); binder.bind(JsonConfigurator.class).in(LazySingleton.class); binder.bind(Properties.class).toInstance(props); } },
@Override public void configure(Binder binder) { Properties props = new Properties(); props.put("druid.emitter.composing.emitters", "[\"" + testEmitterType + "\"]"); binder.bind(Properties.class).toInstance(props); binder.bind(Validator.class).toInstance(Validation.buildDefaultValidatorFactory().getValidator()); binder.bind(Emitter.class).annotatedWith(Names.named(testEmitterType)).toInstance(emitter); } },
@Override public void afterPropertiesSet() { if (this.validatorFactory == null) { this.validatorFactory = Validation.buildDefaultValidatorFactory(); } ValidatorContext validatorContext = this.validatorFactory.usingContext(); MessageInterpolator targetInterpolator = this.messageInterpolator; if (targetInterpolator == null) { targetInterpolator = this.validatorFactory.getMessageInterpolator(); } validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator)); if (this.traversableResolver != null) { validatorContext.traversableResolver(this.traversableResolver); } setTargetValidator(validatorContext.getValidator()); }
@Test public void testNoLoggerAtAll() { final Properties properties = new Properties(); properties.setProperty("dummy", "unrelated"); final JsonConfigurator configurator = new JsonConfigurator( mapper, Validation.buildDefaultValidatorFactory() .getValidator() ); final RequestLoggerProvider provider = configurator.configurate( properties, "log", RequestLoggerProvider.class, NoopRequestLoggerProvider.class ); Assert.assertThat(provider, CoreMatchers.instanceOf(NoopRequestLoggerProvider.class)); }
@Test public void testInvalidDelegateType() { final Properties properties = new Properties(); properties.setProperty("log.type", "filtered"); properties.setProperty("log.queryTimeThresholdMs", "100"); properties.setProperty("log.delegate.type", "nope"); final JsonConfigurator configurator = new JsonConfigurator( mapper, Validation.buildDefaultValidatorFactory() .getValidator() ); expectedException.expect(ProvisionException.class); expectedException.expectMessage("Could not resolve type id 'nope'"); configurator.configurate(properties, "log", RequestLoggerProvider.class); }
@Test public void testNoDelegate() { final Properties properties = new Properties(); properties.setProperty("log.type", "filtered"); properties.setProperty("log.queryTimeThresholdMs", "100"); final JsonConfigurator configurator = new JsonConfigurator( mapper, Validation.buildDefaultValidatorFactory() .getValidator() ); expectedException.expect(ProvisionException.class); expectedException.expectMessage("log.delegate - may not be null"); configurator.configurate(properties, "log", RequestLoggerProvider.class); } }
@Test public void testLoggerPropertiesWithNoType() { final Properties properties = new Properties(); properties.setProperty("dummy", "unrelated"); properties.setProperty("log.foo", "bar"); final JsonConfigurator configurator = new JsonConfigurator( mapper, Validation.buildDefaultValidatorFactory() .getValidator() ); expectedException.expect(ProvisionException.class); expectedException.expectMessage("missing property 'type'"); configurator.configurate( properties, "log", RequestLoggerProvider.class, NoopRequestLoggerProvider.class ); } }
@Override public void afterPropertiesSet() { if (this.validatorFactory == null) { this.validatorFactory = Validation.buildDefaultValidatorFactory(); } ValidatorContext validatorContext = this.validatorFactory.usingContext(); MessageInterpolator targetInterpolator = this.messageInterpolator; if (targetInterpolator == null) { targetInterpolator = this.validatorFactory.getMessageInterpolator(); } validatorContext.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator)); if (this.traversableResolver != null) { validatorContext.traversableResolver(this.traversableResolver); } setTargetValidator(validatorContext.getValidator()); }