@Override public void onFinish(ConfigurationPropertyName name, Bindable<?> target, BindContext context, Object result) throws Exception { if (context.getDepth() == 0) { checkNoUnboundElements(name, context); } }
private BindHandler getBindHandler() { BindHandler handler = BindHandler.DEFAULT; if (isIgnoreInvalidFields()) { handler = new IgnoreErrorsBindHandler(handler); } if (!isIgnoreUnknownFields()) { UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); handler = new NoUnboundElementsBindHandler(handler, filter); } return handler; } }
private void collectUnbound(ConfigurationPropertyName name, Set<ConfigurationProperty> unbound, IterableConfigurationPropertySource source) { IterableConfigurationPropertySource filtered = source .filter((candidate) -> isUnbound(name, candidate)); for (ConfigurationPropertyName unboundName : filtered) { try { unbound.add(source.filter((candidate) -> isUnbound(name, candidate)) .getConfigurationProperty(unboundName)); } catch (Exception ex) { } } }
private BindHandler getBindHandler(ConfigurationProperties annotation, List<Validator> validators) { BindHandler handler = new IgnoreTopLevelConverterNotFoundBindHandler(); if (annotation.ignoreInvalidFields()) { handler = new IgnoreErrorsBindHandler(handler); } if (!annotation.ignoreUnknownFields()) { UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); handler = new NoUnboundElementsBindHandler(handler, filter); } if (!validators.isEmpty()) { handler = new ValidationBindHandler(handler, validators.toArray(new Validator[0])); } for (ConfigurationPropertiesBindHandlerAdvisor advisor : getBindHandlerAdvisors()) { handler = advisor.apply(handler); } return handler; }
public <T> BindResult<T> bind(String prefix, Bindable<T> target) { UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); NoUnboundElementsBindHandler handler = new NoUnboundElementsBindHandler(new IgnoreTopLevelConverterNotFoundBindHandler(), filter); return binder.bind(prefix, target, handler); }
@Override public void preInit(SpringProcessEngineConfiguration springProcessEngineConfiguration) { GenericProperties genericProperties = camundaBpmProperties.getGenericProperties(); final Map<String, Object> properties = genericProperties.getProperties(); if (!CollectionUtils.isEmpty(properties)) { ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); Binder binder = new Binder(source); try { if (genericProperties.isIgnoreUnknownFields()) { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration)); } else { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration), new NoUnboundElementsBindHandler(BindHandler.DEFAULT)); } } catch (Exception e) { throw LOG.exceptionDuringBinding(e.getMessage()); } logger.debug("properties bound to configuration: {}", genericProperties); } }
@Bean(name = CONFIG_SINGLETON) public Singleton<JasyptEncryptorConfigurationProperties> configProps( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") final EnvCopy envCopy, final ConfigurableBeanFactory bf) { return new Singleton<>(() -> { final BindHandler handler = new IgnoreErrorsBindHandler(BindHandler.DEFAULT); final MutablePropertySources propertySources = envCopy.get().getPropertySources(); final Binder binder = new Binder(ConfigurationPropertySources.from(propertySources), new PropertySourcesPlaceholdersResolver(propertySources), ApplicationConversionService.getSharedInstance(), bf::copyRegisteredEditorsTo); final JasyptEncryptorConfigurationProperties config = new JasyptEncryptorConfigurationProperties(); final ResolvableType type = ResolvableType.forClass(JasyptEncryptorConfigurationProperties.class); final Annotation annotation = AnnotationUtils.findAnnotation(JasyptEncryptorConfigurationProperties.class, ConfigurationProperties.class); final Annotation[] annotations = new Annotation[] {annotation}; final Bindable<?> target = Bindable.of(type).withExistingValue(config).withAnnotations(annotations); binder.bind("jasypt.encryptor", target, handler); return config; }); }
public void bind(String configPrefix, Bindable<?> bean) { BindHandler handler = new IgnoreTopLevelConverterNotFoundBindHandler(); this.binder.bind(configPrefix, bean, handler); }
private void checkNoUnboundElements(ConfigurationPropertyName name, BindContext context) { Set<ConfigurationProperty> unbound = new TreeSet<>(); for (ConfigurationPropertySource source : context.getSources()) { if (source instanceof IterableConfigurationPropertySource && this.filter.apply(source)) { collectUnbound(name, unbound, (IterableConfigurationPropertySource) source); } } if (!unbound.isEmpty()) { throw new UnboundConfigurationPropertiesException(unbound); } }
private BindHandler getBindHandler() { BindHandler handler = BindHandler.DEFAULT; if (isIgnoreInvalidFields()) { handler = new IgnoreErrorsBindHandler(handler); } if (!isIgnoreUnknownFields()) { UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter(); handler = new NoUnboundElementsBindHandler(handler, filter); } return handler; } }
@Override public void preInit(SpringProcessEngineConfiguration springProcessEngineConfiguration) { GenericProperties genericProperties = camundaBpmProperties.getGenericProperties(); final Map<String, Object> properties = genericProperties.getProperties(); if (!CollectionUtils.isEmpty(properties)) { ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); Binder binder = new Binder(source); try { if (genericProperties.isIgnoreUnknownFields()) { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration)); } else { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration), new NoUnboundElementsBindHandler(BindHandler.DEFAULT)); } } catch (Exception e) { throw LOG.exceptionDuringBinding(e.getMessage()); } logger.debug("properties bound to configuration: {}", genericProperties); } }
@Bean(name = CONFIG_SINGLETON) public Singleton<JasyptEncryptorConfigurationProperties> configProps( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") final EnvCopy envCopy, final ConfigurableBeanFactory bf) { return new Singleton<>(() -> { final BindHandler handler = new IgnoreErrorsBindHandler(BindHandler.DEFAULT); final MutablePropertySources propertySources = envCopy.get().getPropertySources(); final Binder binder = new Binder(ConfigurationPropertySources.from(propertySources), new PropertySourcesPlaceholdersResolver(propertySources), ApplicationConversionService.getSharedInstance(), bf::copyRegisteredEditorsTo); final JasyptEncryptorConfigurationProperties config = new JasyptEncryptorConfigurationProperties(); final ResolvableType type = ResolvableType.forClass(JasyptEncryptorConfigurationProperties.class); final Annotation annotation = AnnotationUtils.findAnnotation(JasyptEncryptorConfigurationProperties.class, ConfigurationProperties.class); final Annotation[] annotations = new Annotation[] {annotation}; final Bindable<?> target = Bindable.of(type).withExistingValue(config).withAnnotations(annotations); binder.bind("jasypt.encryptor", target, handler); return config; }); }