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.HasCamelContext, 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 Details

    • SYSTEM_PROPERTIES_MODE_NEVER

      public static final int SYSTEM_PROPERTIES_MODE_NEVER
      Never check system properties.
      See Also:
    • SYSTEM_PROPERTIES_MODE_FALLBACK

      public static final int SYSTEM_PROPERTIES_MODE_FALLBACK
      Check system properties if not resolvable in the specified properties.
      See Also:
    • 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:
    • ENVIRONMENT_VARIABLES_MODE_NEVER

      public static final int ENVIRONMENT_VARIABLES_MODE_NEVER
      Never check OS environment variables.
      See Also:
    • 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:
    • 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:
    • 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 Details

    • 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 Details

    • getCamelContext

      public org.apache.camel.CamelContext getCamelContext()
      Specified by:
      getCamelContext in interface org.apache.camel.spi.HasCamelContext
    • setCamelContext

      public void setCamelContext(org.apache.camel.CamelContext camelContext)
      Specified by:
      setCamelContext in interface org.apache.camel.CamelContextAware
    • parseUri

      public String parseUri(String uri)
      Specified by:
      parseUri in interface org.apache.camel.spi.PropertiesComponent
    • parseUri

      public String parseUri(String uri, boolean keepUnresolvedOptional)
      Specified by:
      parseUri in interface org.apache.camel.spi.PropertiesComponent
    • resolveProperty

      public Optional<String> resolveProperty(String key)
      Specified by:
      resolveProperty in interface org.apache.camel.spi.PropertiesComponent
    • loadProperties

      public Properties loadProperties()
      Specified by:
      loadProperties in interface org.apache.camel.spi.PropertiesComponent
    • loadProperties

      public Properties loadProperties(Predicate<String> filter)
      Specified by:
      loadProperties in interface org.apache.camel.spi.PropertiesComponent
    • loadProperties

      public Properties loadProperties(Predicate<String> filter, Function<String,String> keyMapper)
      Specified by:
      loadProperties in interface org.apache.camel.spi.PropertiesComponent
    • parseUri

      protected String parseUri(String uri, PropertiesLookup properties, boolean keepUnresolvedOptional)
    • getLocations

      public List<String> getLocations()
      Specified by:
      getLocations in interface org.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.
    • getPropertiesSourceFactory

      public org.apache.camel.spi.PropertiesSourceFactory getPropertiesSourceFactory()
      Specified by:
      getPropertiesSourceFactory in interface org.apache.camel.spi.PropertiesComponent
    • addLocation

      public void addLocation(PropertiesLocation location)
    • addLocation

      public void addLocation(String location)
      Specified by:
      addLocation in interface org.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 interface org.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 by Properties.load(java.io.InputStream)

      Specified by:
      setEncoding in interface org.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)
      Specified by:
      setIgnoreMissingLocation in interface org.apache.camel.spi.PropertiesComponent
    • isIgnoreMissingProperty

      @ManagedAttribute(description="Ignore missing location") public boolean isIgnoreMissingProperty()
    • setIgnoreMissingProperty

      public void setIgnoreMissingProperty(boolean ignoreMissingProperty)
      Specified by:
      setIgnoreMissingProperty in interface org.apache.camel.spi.PropertiesComponent
    • isNestedPlaceholder

      @ManagedAttribute(description="Nested placeholder") public boolean isNestedPlaceholder()
    • setNestedPlaceholder

      public void setNestedPlaceholder(boolean nestedPlaceholder)
      Specified by:
      setNestedPlaceholder in interface org.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)
      Specified by:
      setInitialProperties in interface org.apache.camel.spi.PropertiesComponent
    • addInitialProperty

      public void addInitialProperty(String key, String value)
      Specified by:
      addInitialProperty in interface org.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)
      Specified by:
      setOverrideProperties in interface org.apache.camel.spi.PropertiesComponent
    • addOverrideProperty

      public void addOverrideProperty(String key, String value)
      Specified by:
      addOverrideProperty in interface org.apache.camel.spi.PropertiesComponent
    • setLocalProperties

      public void setLocalProperties(Properties localProperties)
      Specified by:
      setLocalProperties in interface org.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 interface org.apache.camel.spi.PropertiesComponent
    • getPropertiesFunction

      public org.apache.camel.spi.PropertiesFunction getPropertiesFunction(String name)
      Specified by:
      getPropertiesFunction in interface org.apache.camel.spi.PropertiesComponent
    • addPropertiesFunction

      public void addPropertiesFunction(org.apache.camel.spi.PropertiesFunction function)
      Specified by:
      addPropertiesFunction in interface org.apache.camel.spi.PropertiesComponent
    • hasPropertiesFunction

      public boolean hasPropertiesFunction(String name)
      Specified by:
      hasPropertiesFunction in interface org.apache.camel.spi.PropertiesComponent
    • 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.
      See Also:
    • 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.
      See Also:
    • isAutoDiscoverPropertiesSources

      public boolean isAutoDiscoverPropertiesSources()
    • setAutoDiscoverPropertiesSources

      public void setAutoDiscoverPropertiesSources(boolean autoDiscoverPropertiesSources)
      Whether to automatically discovery instances of PropertiesSource from registry and service factory.
    • addPropertiesSource

      public void addPropertiesSource(org.apache.camel.spi.PropertiesSource propertiesSource)
      Specified by:
      addPropertiesSource in interface org.apache.camel.spi.PropertiesComponent
    • getPropertiesSource

      public org.apache.camel.spi.PropertiesSource getPropertiesSource(String name)
      Specified by:
      getPropertiesSource in interface org.apache.camel.spi.PropertiesComponent
    • getPropertiesSources

      public List<org.apache.camel.spi.PropertiesSource> getPropertiesSources()
      Specified by:
      getPropertiesSources in interface org.apache.camel.spi.PropertiesComponent
    • addPropertiesLookupListener

      public void addPropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
      Specified by:
      addPropertiesLookupListener in interface org.apache.camel.spi.PropertiesComponent
    • removePropertiesLookupListener

      public void removePropertiesLookupListener(org.apache.camel.PropertiesLookupListener propertiesLookupListener)
      Remove PropertiesLookupListener
    • getPropertiesLookupListeners

      public List<org.apache.camel.PropertiesLookupListener> getPropertiesLookupListeners()
      Gets the PropertiesLookupListener
    • reloadProperties

      @ManagedOperation(description="Reload properties from the given location patterns") public boolean reloadProperties(String pattern)
      Specified by:
      reloadProperties in interface org.apache.camel.spi.PropertiesComponent
    • keepOnlyChangeProperties

      public void keepOnlyChangeProperties(Properties properties)
      Specified by:
      keepOnlyChangeProperties in interface org.apache.camel.spi.PropertiesComponent
    • doInit

      protected void doInit() throws Exception
      Overrides:
      doInit in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doBuild

      protected void doBuild() throws Exception
      Overrides:
      doBuild in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.apache.camel.support.service.BaseService
      Throws:
      Exception
    • doShutdown

      protected void doShutdown() throws Exception
      Overrides:
      doShutdown in class org.apache.camel.support.service.BaseService
      Throws:
      Exception