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.CamelContextAwareThe properties component allows you to use property placeholders in Camel.
-
-
Field Summary
Fields Modifier and Type Field Description static intENVIRONMENT_VARIABLES_MODE_FALLBACKCheck OS environment variables if not resolvable in the specified properties.static intENVIRONMENT_VARIABLES_MODE_NEVERNever check OS environment variables.static intENVIRONMENT_VARIABLES_MODE_OVERRIDECheck OS environment variables first, before trying the specified properties.static StringOVERRIDE_PROPERTIESKey for stores special override properties that containers such as OSGi can store in the OSGi service registrystatic intSYSTEM_PROPERTIES_MODE_FALLBACKCheck system properties if not resolvable in the specified properties.static intSYSTEM_PROPERTIES_MODE_NEVERNever check system properties.static intSYSTEM_PROPERTIES_MODE_OVERRIDECheck 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 voidaddInitialProperty(String key, String value)voidaddLocation(String location)voidaddLocation(PropertiesLocation location)voidaddOverrideProperty(String key, String value)voidaddPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)Registers thePropertiesFunctionas a function to this component.voidaddPropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)voidaddPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)protected voiddoBuild()protected voiddoInit()protected voiddoShutdown()protected voiddoStart()protected voiddoStop()org.apache.camel.CamelContextgetCamelContext()StringgetEncoding()intgetEnvironmentVariableMode()Map<String,org.apache.camel.spi.PropertiesFunction>getFunctions()Deprecated.PropertiesgetInitialProperties()PropertiesgetLocalProperties()Gets a list of properties that are local for the current thread only (ie thread local), or null if not currently in use.StringgetLocation()List<String>getLocations()PropertiesgetOverrideProperties()org.apache.camel.spi.PropertiesFunctiongetPropertiesFunction(String name)Gets the function by the given namePropertiesFunctionResolvergetPropertiesFunctionResolver()List<org.apache.camel.PropertiesLookupListener>getPropertiesLookupListeners()Gets thePropertiesLookupListenerPropertiesParsergetPropertiesParser()org.apache.camel.spi.PropertiesSourcegetPropertiesSource(String name)List<org.apache.camel.spi.PropertiesSource>getSources()intgetSystemPropertiesMode()booleanhasFunction(String name)Is there aPropertiesFunctionwith the given name?booleanisAutoDiscoverPropertiesSources()booleanisDefaultFallbackEnabled()booleanisIgnoreMissingLocation()PropertiesloadProperties()PropertiesloadProperties(Predicate<String> filter)PropertiesloadProperties(Predicate<String> filter, Function<String,String> keyMapper)StringparseUri(String uri)StringparseUri(String uri, boolean keepUnresolvedOptional)protected StringparseUri(String uri, PropertiesLookup properties, boolean keepUnresolvedOptional)booleanreloadProperties(String pattern)voidremovePropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)RemovePropertiesLookupListenerOptional<String>resolveProperty(String key)voidsetAutoDiscoverPropertiesSources(boolean autoDiscoverPropertiesSources)Whether to automatically discovery instances ofPropertiesSourcefrom registry and service factory.voidsetCamelContext(org.apache.camel.CamelContext camelContext)voidsetDefaultFallbackEnabled(boolean defaultFallbackEnabled)If false, the component does not attempt to find a default for the key by looking after the colon separator.voidsetEncoding(String encoding)Encoding to use when loading properties file from the file system or classpath.voidsetEnvironmentVariableMode(int environmentVariableMode)Sets the OS environment variables mode (0 = never, 1 = fallback, 2 = override).voidsetIgnoreMissingLocation(boolean ignoreMissingLocation)Whether to silently ignore if a location cannot be located, such as a properties file not found.voidsetInitialProperties(Properties initialProperties)Sets initial properties which will be used before any locations are resolved.voidsetLocalProperties(Properties localProperties)Sets a special list of local properties (ie thread local) that take precedence and will use first, if a property exists.voidsetLocation(String location)A list of locations to load properties.voidsetLocations(String[] locationStrings)A list of locations to load properties.voidsetLocations(Collection<String> locationStrings)A list of locations to load properties.voidsetLocations(List<PropertiesLocation> locations)A list of locations to load properties.voidsetOverrideProperties(Properties overrideProperties)Sets a special list of override properties that take precedence and will use first, if a property exists.voidsetPropertiesFunctionResolver(PropertiesFunctionResolver propertiesFunctionResolver)To use a custom PropertiesFunctionResolvervoidsetPropertiesParser(PropertiesParser propertiesParser)To use a custom PropertiesParservoidsetSystemPropertiesMode(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:
getCamelContextin interfaceorg.apache.camel.CamelContextAware
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContextin interfaceorg.apache.camel.CamelContextAware
-
parseUri
public String parseUri(String uri)
- Specified by:
parseUriin interfaceorg.apache.camel.spi.PropertiesComponent
-
parseUri
public String parseUri(String uri, boolean keepUnresolvedOptional)
- Specified by:
parseUriin interfaceorg.apache.camel.spi.PropertiesComponent
-
resolveProperty
public Optional<String> resolveProperty(String key)
- Specified by:
resolvePropertyin interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties()
- Specified by:
loadPropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties(Predicate<String> filter)
- Specified by:
loadPropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
loadProperties
public Properties loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
- Specified by:
loadPropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
parseUri
protected String parseUri(String uri, PropertiesLookup properties, boolean keepUnresolvedOptional)
-
getLocations
public List<String> getLocations()
- Specified by:
getLocationsin 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:
addLocationin 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:
setLocationin 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:
setEncodingin 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:
setIgnoreMissingLocationin 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:
setInitialPropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
addInitialProperty
public void addInitialProperty(String key, String value)
- Specified by:
addInitialPropertyin 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:
setOverridePropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
addOverrideProperty
public void addOverrideProperty(String key, String value)
- Specified by:
addOverridePropertyin 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:
setLocalPropertiesin 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:
getLocalPropertiesin 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)
Gets the function by the given name- Parameters:
name- the function name- Returns:
- the function or null if no function exists
-
addPropertiesFunction
public void addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
Registers thePropertiesFunctionas a function to this component.- Specified by:
addPropertiesFunctionin interfaceorg.apache.camel.spi.PropertiesComponent
-
hasFunction
public boolean hasFunction(String name)
Is there aPropertiesFunctionwith 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 ofPropertiesSourcefrom registry and service factory.
-
addPropertiesSource
public void addPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)
- Specified by:
addPropertiesSourcein interfaceorg.apache.camel.spi.PropertiesComponent
-
getPropertiesSource
public org.apache.camel.spi.PropertiesSource getPropertiesSource(String name)
- Specified by:
getPropertiesSourcein interfaceorg.apache.camel.spi.PropertiesComponent
-
getSources
public List<org.apache.camel.spi.PropertiesSource> getSources()
-
addPropertiesLookupListener
public void addPropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
- Specified by:
addPropertiesLookupListenerin 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:
reloadPropertiesin interfaceorg.apache.camel.spi.PropertiesComponent
-
doInit
protected void doInit() throws Exception- Overrides:
doInitin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doBuild
protected void doBuild() throws Exception- Overrides:
doBuildin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStart
protected void doStart() throws Exception- Overrides:
doStartin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
doStop
protected void doStop() throws Exception- Overrides:
doStopin classorg.apache.camel.support.service.BaseService- Throws:
Exception
-
-