java.lang.Object
io.helidon.config.ValueResolvingFilter
- All Implemented Interfaces:
ConfigFilter
A config filter that replaces all placeholders in a config value String with
their corresponding values looked up from the config.
For example:
message = "Hello ${name}!"
name = "Joachim"
will be resolved as:
message = "Hello Joachim!"
How to Activate This Filter
Use any of the following techniques to create aValueResolvingFilter
and
use it for config look-ups.
- Programmatically:
- Invoke
ConfigFilters.valueResolving()
to get a builder for the filter. - Optionally, invoke the filter builder's
failOnMissingReference
method (see below). - Invoke the builder's
build
method to create the filter. - Then, on the
Config.Builder
being used to construct theConfig
instance, invokeConfig.Builder#addFilter
passing the just-created filter.
- Invoke
- Implicitly: Create or edit the file
io.helidon.config.ConfigFilter
on the application's runtime classpath to contain this line:io.helidon.config.ValueResolvingFilter
Config.Builder
automatically.
Handling Missing References
By default, references to tokens that are not present do not cause retrievals to fail. You can customize this behavior in several ways.- If you use
ConfigFilters.valueResolving()
to get a builder for the filter, invoke thefailOnMissingReference
method on that builder before invoking the filter builder'sbuild
method. - If you use
ConfigFilters.ValueResolvingBuilder.create(io.helidon.config.Config)
to get the filter's builder, define this setting in theConfig
instance you pass to thefrom
method:"config.value-resolving-filter.fail-on-missing-reference" = true
orfalse
which is the default. This sets the behavior for the single filter created from that builder. - If you use the Java service loader mechanism to create
ValueResolvingFilter
s for everyConfig.Builder
, specify the following config setting in one of the config sources that composes the default config:"config.value-resolving-filter.fail-on-missing-reference" = true
orfalse
which is the default. This sets the behavior for everyValueResolvingFilter
created for which thefailOnMissingReference
value has not already been set, for example by invoking theConfigFilters.valueResolving().failOnMissingReference()
method.
-
Constructor Summary
ConstructorDescriptionCreates an instance of the filter with no explicit failOnMissing behavior set.ValueResolvingFilter
(boolean failOnMissingReference) Creates an instance of filter with the specified behavior on missing references. -
Method Summary
Modifier and TypeMethodDescriptionapply
(Config.Key key, String stringValue) Filters an elementary config value before it is made available to the application via theConfig
API.void
Initializes the filter using theConfig
instance which the filter will affect onceConfig.Builder.build
completes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.helidon.config.spi.ConfigFilter
apply
-
Constructor Details
-
ValueResolvingFilter
public ValueResolvingFilter(boolean failOnMissingReference) Creates an instance of filter with the specified behavior on missing references.- Parameters:
failOnMissingReference
- whether to fail when a referenced key is missing
-
ValueResolvingFilter
public ValueResolvingFilter()Creates an instance of the filter with no explicit failOnMissing behavior set.
-
-
Method Details
-
init
Description copied from interface:ConfigFilter
Initializes the filter using theConfig
instance which the filter will affect onceConfig.Builder.build
completes.The config system propagates any thrown exception to the application so its invocation of
Config.Builder#build
fails.- Specified by:
init
in interfaceConfigFilter
- Parameters:
config
-Config
instance under construction
-
apply
Description copied from interface:ConfigFilter
Filters an elementary config value before it is made available to the application via theConfig
API.- Specified by:
apply
in interfaceConfigFilter
- Parameters:
key
- configurationkey
associated with theConfig
nodestringValue
- original value to be filtered, nevernull
- Returns:
- original value or filtered (changed) value, never
null
-