Class PropertiesComponent
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.component.properties.PropertiesComponent
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.PropertiesComponent
,org.apache.camel.StatefulService
,org.apache.camel.StaticService
,org.apache.camel.SuspendableService
@ManagedResource(description="Managed PropertiesComponent") @JdkService("properties-component-factory") @Configurer(bootstrap=true) public class PropertiesComponent extends org.apache.camel.support.service.ServiceSupport implements org.apache.camel.spi.PropertiesComponent, org.apache.camel.StaticService, org.apache.camel.CamelContextAware
The properties component allows you to use property placeholders in Camel.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ENVIRONMENT_VARIABLES_MODE_FALLBACK
Check OS environment variables if not resolvable in the specified properties.static int
ENVIRONMENT_VARIABLES_MODE_NEVER
Never check OS environment variables.static int
ENVIRONMENT_VARIABLES_MODE_OVERRIDE
Check OS environment variables first, before trying the specified properties.static String
OVERRIDE_PROPERTIES
Key for stores special override properties that containers such as OSGi can store in the OSGi service registrystatic int
SYSTEM_PROPERTIES_MODE_FALLBACK
Check system properties if not resolvable in the specified properties.static int
SYSTEM_PROPERTIES_MODE_NEVER
Never check system properties.static int
SYSTEM_PROPERTIES_MODE_OVERRIDE
Check system properties variables) first, before trying the specified properties.
-
Constructor Summary
Constructors Constructor Description PropertiesComponent()
PropertiesComponent(String location)
A list of locations to load properties.PropertiesComponent(String... locations)
A list of locations to load properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addInitialProperty(String key, String value)
void
addLocation(String location)
void
addLocation(PropertiesLocation location)
void
addOverrideProperty(String key, String value)
void
addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
void
addPropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
void
addPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)
protected void
doBuild()
protected void
doInit()
protected void
doShutdown()
protected void
doStart()
protected void
doStop()
org.apache.camel.CamelContext
getCamelContext()
String
getEncoding()
int
getEnvironmentVariableMode()
Map<String,org.apache.camel.spi.PropertiesFunction>
getFunctions()
Deprecated.Properties
getInitialProperties()
Properties
getLocalProperties()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.String
getLocation()
List<String>
getLocations()
Properties
getOverrideProperties()
org.apache.camel.spi.PropertiesFunction
getPropertiesFunction(String name)
PropertiesFunctionResolver
getPropertiesFunctionResolver()
List<org.apache.camel.PropertiesLookupListener>
getPropertiesLookupListeners()
Gets thePropertiesLookupListener
PropertiesParser
getPropertiesParser()
org.apache.camel.spi.PropertiesSource
getPropertiesSource(String name)
List<org.apache.camel.spi.PropertiesSource>
getPropertiesSources()
int
getSystemPropertiesMode()
boolean
hasFunction(String name)
Deprecated.use hasPropertiesFunctionboolean
hasPropertiesFunction(String name)
boolean
isAutoDiscoverPropertiesSources()
boolean
isDefaultFallbackEnabled()
boolean
isIgnoreMissingLocation()
Properties
loadProperties()
Properties
loadProperties(Predicate<String> filter)
Properties
loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
String
parseUri(String uri)
String
parseUri(String uri, boolean keepUnresolvedOptional)
protected String
parseUri(String uri, PropertiesLookup properties, boolean keepUnresolvedOptional)
boolean
reloadProperties(String pattern)
void
removePropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
RemovePropertiesLookupListener
Optional<String>
resolveProperty(String key)
void
setAutoDiscoverPropertiesSources(boolean autoDiscoverPropertiesSources)
Whether to automatically discovery instances ofPropertiesSource
from registry and service factory.void
setCamelContext(org.apache.camel.CamelContext camelContext)
void
setDefaultFallbackEnabled(boolean defaultFallbackEnabled)
If false, the component does not attempt to find a default for the key by looking after the colon separator.void
setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath.void
setEnvironmentVariableMode(int environmentVariableMode)
Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override).void
setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.void
setInitialProperties(Properties initialProperties)
Sets initial properties which will be used before any locations are resolved.void
setLocalProperties(Properties localProperties)
Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exists.void
setLocation(String location)
A list of locations to load properties.void
setLocations(String[] locationStrings)
A list of locations to load properties.void
setLocations(List<PropertiesLocation> locations)
A list of locations to load properties.void
setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exists.void
setPropertiesFunctionResolver(PropertiesFunctionResolver propertiesFunctionResolver)
To use a custom PropertiesFunctionResolvervoid
setPropertiesParser(PropertiesParser propertiesParser)
To use a custom PropertiesParservoid
setSystemPropertiesMode(int systemPropertiesMode)
Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override).-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doFail, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.camel.spi.PropertiesComponent
getLocalPropertiesAsMap, loadPropertiesAsMap, loadPropertiesAsMap
-
-
-
-
Field Detail
-
SYSTEM_PROPERTIES_MODE_NEVER
public static final int SYSTEM_PROPERTIES_MODE_NEVER
Never check system properties.- See Also:
- Constant Field Values
-
SYSTEM_PROPERTIES_MODE_FALLBACK
public static final int SYSTEM_PROPERTIES_MODE_FALLBACK
Check system properties if not resolvable in the specified properties.- See Also:
- Constant Field Values
-
SYSTEM_PROPERTIES_MODE_OVERRIDE
public static final int SYSTEM_PROPERTIES_MODE_OVERRIDE
Check system properties variables) first, before trying the specified properties. This allows system properties to override any other property source (environment variable and then system properties takes precedence). This is the default.- See Also:
- Constant Field Values
-
ENVIRONMENT_VARIABLES_MODE_NEVER
public static final int ENVIRONMENT_VARIABLES_MODE_NEVER
Never check OS environment variables.- See Also:
- Constant Field Values
-
ENVIRONMENT_VARIABLES_MODE_FALLBACK
public static final int ENVIRONMENT_VARIABLES_MODE_FALLBACK
Check OS environment variables if not resolvable in the specified properties. This is the default.- See Also:
- Constant Field Values
-
ENVIRONMENT_VARIABLES_MODE_OVERRIDE
public static final int ENVIRONMENT_VARIABLES_MODE_OVERRIDE
Check OS environment variables first, before trying the specified properties. This allows environment variables to override any other property source (environment variable and then system properties takes precedence).- See Also:
- Constant Field Values
-
OVERRIDE_PROPERTIES
public static final String OVERRIDE_PROPERTIES
Key for stores special override properties that containers such as OSGi can store in the OSGi service registry
-
-
Constructor Detail
-
PropertiesComponent
public PropertiesComponent()
-
PropertiesComponent
public PropertiesComponent(String location)
A list of locations to load properties. You can use comma to separate multiple locations.
-
PropertiesComponent
public PropertiesComponent(String... locations)
A list of locations to load properties.
-
-
Method Detail
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
parseUri
public String parseUri(String uri)
- Specified by:
parseUri
in interfaceorg.apache.camel.spi.PropertiesComponent
-
parseUri
public String parseUri(String uri, boolean keepUnresolvedOptional)
- Specified by:
parseUri
in interfaceorg.apache.camel.spi.PropertiesComponent
-
resolveProperty
public Optional<String> resolveProperty(String key)
- Specified by:
resolveProperty
in interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties()
- Specified by:
loadProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties(Predicate<String> filter)
- Specified by:
loadProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
- Specified by:
loadProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
parseUri
protected String parseUri(String uri, PropertiesLookup properties, boolean keepUnresolvedOptional)
-
getLocations
public List<String> getLocations()
- Specified by:
getLocations
in interfaceorg.apache.camel.spi.PropertiesComponent
-
setLocations
public void setLocations(List<PropertiesLocation> locations)
A list of locations to load properties. This option will override any default locations and only use the locations from this option.
-
setLocations
public void setLocations(String[] locationStrings)
A list of locations to load properties. This option will override any default locations and only use the locations from this option.
-
addLocation
public void addLocation(PropertiesLocation location)
-
addLocation
public void addLocation(String location)
- Specified by:
addLocation
in interfaceorg.apache.camel.spi.PropertiesComponent
-
setLocation
public void setLocation(String location)
A list of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and only use the locations from this option.- Specified by:
setLocation
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getLocation
public String getLocation()
-
getEncoding
@ManagedAttribute(description="Encoding to use when loading properties file from the file system or classpath") public String getEncoding()
-
setEncoding
public void setEncoding(String encoding)
Encoding to use when loading properties file from the file system or classpath. If no encoding has been set, then the properties files is loaded using ISO-8859-1 encoding (latin-1) as documented byProperties.load(java.io.InputStream)
- Specified by:
setEncoding
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getPropertiesParser
public PropertiesParser getPropertiesParser()
-
setPropertiesParser
public void setPropertiesParser(PropertiesParser propertiesParser)
To use a custom PropertiesParser
-
getPropertiesFunctionResolver
public PropertiesFunctionResolver getPropertiesFunctionResolver()
-
setPropertiesFunctionResolver
public void setPropertiesFunctionResolver(PropertiesFunctionResolver propertiesFunctionResolver)
To use a custom PropertiesFunctionResolver
-
isDefaultFallbackEnabled
@ManagedAttribute(description="Whether to support using fallback values if a property cannot be found") public boolean isDefaultFallbackEnabled()
-
setDefaultFallbackEnabled
public void setDefaultFallbackEnabled(boolean defaultFallbackEnabled)
If false, the component does not attempt to find a default for the key by looking after the colon separator.
-
isIgnoreMissingLocation
@ManagedAttribute(description="Ignore missing location") public boolean isIgnoreMissingLocation()
-
setIgnoreMissingLocation
public void setIgnoreMissingLocation(boolean ignoreMissingLocation)
Whether to silently ignore if a location cannot be located, such as a properties file not found.- Specified by:
setIgnoreMissingLocation
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getInitialProperties
public Properties getInitialProperties()
- Returns:
- a list of properties which will be used before any locations are resolved (can't be null).
-
setInitialProperties
public void setInitialProperties(Properties initialProperties)
Sets initial properties which will be used before any locations are resolved.- Specified by:
setInitialProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
addInitialProperty
public void addInitialProperty(String key, String value)
- Specified by:
addInitialProperty
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getOverrideProperties
public Properties getOverrideProperties()
- Returns:
- a list of properties that take precedence and will use first, if a property exists (can't be null).
-
setOverrideProperties
public void setOverrideProperties(Properties overrideProperties)
Sets a special list of override properties that take precedence and will use first, if a property exists.- Specified by:
setOverrideProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
addOverrideProperty
public void addOverrideProperty(String key, String value)
- Specified by:
addOverrideProperty
in interfaceorg.apache.camel.spi.PropertiesComponent
-
setLocalProperties
public void setLocalProperties(Properties localProperties)
Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exists.- Specified by:
setLocalProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getLocalProperties
public Properties getLocalProperties()
Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.- Specified by:
getLocalProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getFunctions
@Deprecated public Map<String,org.apache.camel.spi.PropertiesFunction> getFunctions()
Deprecated.Gets the functions registered in this properties component.
-
getPropertiesFunction
public org.apache.camel.spi.PropertiesFunction getPropertiesFunction(String name)
- Specified by:
getPropertiesFunction
in interfaceorg.apache.camel.spi.PropertiesComponent
-
addPropertiesFunction
public void addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
- Specified by:
addPropertiesFunction
in interfaceorg.apache.camel.spi.PropertiesComponent
-
hasPropertiesFunction
public boolean hasPropertiesFunction(String name)
- Specified by:
hasPropertiesFunction
in interfaceorg.apache.camel.spi.PropertiesComponent
-
hasFunction
@Deprecated public boolean hasFunction(String name)
Deprecated.use hasPropertiesFunctionIs there aPropertiesFunction
with the given name?
-
getSystemPropertiesMode
@ManagedAttribute(description="System properties mode") public int getSystemPropertiesMode()
-
setSystemPropertiesMode
public void setSystemPropertiesMode(int systemPropertiesMode)
Sets the JVM system property mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use system properties if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode.
-
getEnvironmentVariableMode
@ManagedAttribute(description="Environment variable mode") public int getEnvironmentVariableMode()
-
setEnvironmentVariableMode
public void setEnvironmentVariableMode(int environmentVariableMode)
Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override). The default mode (override) is to use OS environment variables if present, and override any existing properties. OS environment variable mode is checked before JVM system property mode.
-
isAutoDiscoverPropertiesSources
public boolean isAutoDiscoverPropertiesSources()
-
setAutoDiscoverPropertiesSources
public void setAutoDiscoverPropertiesSources(boolean autoDiscoverPropertiesSources)
Whether to automatically discovery instances ofPropertiesSource
from registry and service factory.
-
addPropertiesSource
public void addPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)
- Specified by:
addPropertiesSource
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getPropertiesSource
public org.apache.camel.spi.PropertiesSource getPropertiesSource(String name)
- Specified by:
getPropertiesSource
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getPropertiesSources
public List<org.apache.camel.spi.PropertiesSource> getPropertiesSources()
- Specified by:
getPropertiesSources
in interfaceorg.apache.camel.spi.PropertiesComponent
-
addPropertiesLookupListener
public void addPropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
- Specified by:
addPropertiesLookupListener
in interfaceorg.apache.camel.spi.PropertiesComponent
-
removePropertiesLookupListener
public void removePropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
RemovePropertiesLookupListener
-
getPropertiesLookupListeners
public List<org.apache.camel.PropertiesLookupListener> getPropertiesLookupListeners()
Gets thePropertiesLookupListener
-
reloadProperties
@ManagedOperation(description="Reload properties from the given location patterns") public boolean reloadProperties(String pattern)
- Specified by:
reloadProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doBuild
protected void doBuild() throws Exception
- Overrides:
doBuild
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
-