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") 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 Modifier and Type Method Description void
addLocation(String location)
void
addLocation(PropertiesLocation location)
void
addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.void
addPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)
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()
Gets the functions registered in this properties component.Properties
getInitialProperties()
String
getLocation()
List<String>
getLocations()
Properties
getOverrideProperties()
PropertiesParser
getPropertiesParser()
List<org.apache.camel.spi.PropertiesSource>
getSources()
int
getSystemPropertiesMode()
boolean
hasFunction(String name)
Is there aPropertiesFunction
with the given name?boolean
isAutoDiscoverPropertiesSources()
boolean
isDefaultFallbackEnabled()
boolean
isIgnoreMissingLocation()
Properties
loadProperties()
Properties
loadProperties(Predicate<String> filter)
String
parseUri(String uri)
protected String
parseUri(String uri, PropertiesLookup properties)
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
setLocation(String location)
A list of locations to load properties.void
setLocations(String[] locationStrings)
A list of locations to load properties.void
setLocations(Collection<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 exist.void
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, doBuild, 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
-
-
-
-
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
-
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
-
parseUri
protected String parseUri(String uri, PropertiesLookup properties)
-
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.
-
setLocations
public void setLocations(Collection<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
-
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
-
getOverrideProperties
public Properties getOverrideProperties()
- Returns:
- a list of properties that take precedence and will use first, if a property exist (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 exist.- Specified by:
setOverrideProperties
in interfaceorg.apache.camel.spi.PropertiesComponent
-
getFunctions
public Map<String,org.apache.camel.spi.PropertiesFunction> getFunctions()
Gets the functions registered in this properties component.
-
addPropertiesFunction
public void addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
Registers thePropertiesFunction
as a function to this component.- Specified by:
addPropertiesFunction
in interfaceorg.apache.camel.spi.PropertiesComponent
-
hasFunction
public boolean hasFunction(String name)
Is 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
-
getSources
public List<org.apache.camel.spi.PropertiesSource> getSources()
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
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
-
-