Modified: websites/production/camel/content/properties.html ============================================================================== --- websites/production/camel/content/properties.html (original) +++ websites/production/camel/content/properties.html Wed Feb 1 18:19:58 2017 @@ -91,26 +91,26 @@ ]]></script> </div></div><p>Where <strong><code>key</code></strong> is the key for the property to be looked up.</p><h3 id="Properties-Options">Options</h3><div class="confluenceTableSmall"><div class="table-wrap"> <table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>cache</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Whether or not to cache loaded properties.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>encoding</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.14.3/2.15.1:</str ong> To use a specific charset to load the properties, such as UTF-8. By default <code>ISO-8859-1</code> (<code>latin1</code>) is used.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>fallbackToUnaugmentedProperty</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong> If <strong><code>true</code></strong>, first attempt resolution of property name augmented with <strong><code>propertyPrefix</code></strong> and <strong><code>propertySuffix</code></strong> before falling back the plain property name specified.</p><p>If <strong><code>false</code></strong>, only the augmented property name is searched.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd">defaultFallbackEnabled</td><td colspan="1" rowspan="1" class="confluenceTd">boolean</td><td col span="1" rowspan="1" class="confluenceTd">true</td><td colspan="1" rowspan="1" class="confluenceTd"><strong>Camel 2.19</strong> If false the component does not attempt to find a default for the key by looking after the colon separator.</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>ignoreMissingLocation</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.10:</strong> Whether to silently ignore if a location cannot be located, such as a properties file not found.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>locations</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>A lis t of locations to load properties. You can use comma to separate multiple locations. This option will override any default locations and <strong>only</strong> use the locations from this option.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>prefixToken</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>{{</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong> The token to indicate the beginning of a property token.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>propertyPrefix</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong> Optional prefix prepended to property names before resolution.</p> </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>propertySuffix</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong> Optional suffix appended to property names before resolution.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>suffixToken</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>}}<br clear="none"></code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.9</strong> The token to indicate the end of a property token.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>systemPropertiesMode</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>int</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>2</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.16</strong> The mode to use for whether to resolve and use system properties:</p><p><strong><code>0</code></strong> = never - JVM system properties are never used.<br clear="none"><strong><code>1</code></strong> = fallback - JVM system properties are only used as fallback if no regular property with the key exists.<br clear="none"><strong><code>2</code></strong> = override - JVM system properties are used if exists, otherwise the regular property will be used.</p><p><strong>Note</strong>: when bridging to Spring's property placeholder using <strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong> the configuration on <strong><code>BridgePropertyPlaceholderConfigurer</code></strong> will take precedence over the configuration on the <strong><code>PropertiesComponent</code></strong>. </p></t d></tr></tbody></table> -</div></div><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Resolving property from Java code</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>You can use the method <strong><code>resolvePropertyPlaceholders</code></strong> on the <strong><code>CamelContext</code></strong> to resolve a property from any Java code.</p></div></div><p></p><h2 id="Properties-UsingPropertyPlaceholder">Using <code>PropertyPlaceholder</code></h2><p><strong>Available as of Camel 2.3</strong></p><p>Camel now provides a new <strong><code>PropertiesComponent</code></strong> in <strong>camel-core</strong> which allows you to use property placeholders when defining Camel <a shape="rect" href="endpoint.html">Endpoint</a> URIs. This works much like you would do if using Spring's <strong><code><property-placeholder></code></strong> tag. However Spring has a l imitation that prevents 3rd party frameworks from fully leveraging Spring property placeholders.</p><p>For more details see: <a shape="rect" href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I use Spring Property Placeholder with Camel XML</a>.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Bridging Spring and Camel property placeholders</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.10</strong>: Spring's property placeholder can be bridged with Camel's. See below for more details.</p></div></div><p>The property placeholder is generally in use when doing any of the following:</p><ul class="alternate"><li>lookup or creating endpoints.</li><li>lookup of beans in the <a shape="rect" href="registry.html">Registry.</a></li><li>additional supported in Spring XML (see below in examples).</li>< li>using Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a shape="rect" href="properties.html">Properties</a> component.</li><li>using <strong><code>@PropertyInject</code></strong> to inject a property in a POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box functions, to lookup property values from OS environment variables, JVM system properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using custom functions, which can be plugged into the property component.</li></ul><h3 id="Properties-Syntax">Syntax</h3><p>The syntax to use Camel's property placeholder is to use <strong>{{<code>key</code>}}</strong> for example <strong>{{<code>file.uri</code>}}</strong> where <strong><code>file.uri</code></strong> is the property key. You can use property placeholders in parts of the endpoint URI's which for example you can use placeholders for pa rameters in the URIs.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a default value to use if a property with the key does not exists, e.g., <strong><code>file.url:/some/path</code></strong> where the default value is the text after the colon, e.g., <strong><code>/some/path</code></strong>.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.14.1</strong>: do <em>not</em> use a colon in the property key. The colon character is used as a token separator when providing a default value.</p></div></div><h3 id="Properties-UsingPropertyResolver">Using <code>PropertyResolver</code></h3><p>Camel provides a pluggable mechanism which allows 3rd part to provide their own resolver to lookup properties. Camel provides a default implementation <strong><code>org.apache.camel.co mponent.properties.DefaultPropertiesResolver</code></strong> which is capable of loading properties from the file system, classpath or <a shape="rect" href="registry.html">Registry</a>. You can prefix the locations with either:</p><ul class="alternate"><li><strong><code>ref:</code> Camel 2.4:</strong> to lookup in the <a shape="rect" href="registry.html">Registry.</a></li><li><strong><code>file:</code></strong> to load the from file system.</li><li><strong><code>classpath:</code></strong> to load from classpath (this is also the default if no prefix is provided).</li><li><strong><code>blueprint:</code> Camel 2.7:</strong> to use a specific OSGi blueprint placeholder service.</li></ul><h3 id="Properties-DefiningLocation">Defining Location</h3><p>The <strong><code>PropertiesResolver</code></strong> need to know a location(s) where to resolve the properties. You can define 1 to many locations. If you define the location in a single String property you can separate multiple locations wi th comma such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Resolving property from Java code</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>You can use the method <strong><code>resolvePropertyPlaceholders</code></strong> on the <strong><code>CamelContext</code></strong> to resolve a property from any Java code.</p></div></div><p></p><h2 id="Properties-UsingPropertyPlaceholder">Using <strong><code>PropertyPlaceholder</code></strong></h2><p><strong>Available as of Camel 2.3</strong></p><p>Camel now provides a new <strong><code>PropertiesComponent</code></strong> in <strong><code>camel-core</code></strong> which allows you to use property placeholders when defining Camel <a shape="rect" href="endpoint.html">Endpoint</a> URIs. This works much like you would do if using Spring's <strong><code><property-placeholder></code></ strong> tag. However Spring has a limitation that prevents third-party frameworks from fully leveraging Spring property placeholders.</p><p>For more details see: <a shape="rect" href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I use Spring Property Placeholder with Camel XML</a>.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Bridging Spring and Camel property placeholders</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.10</strong>: Spring's property placeholder can be bridged with Camel's. See below for more details.</p></div></div><p>The property placeholder is typically used when trying to do any of the following:</p><ul class="alternate"><li>Lookup or creating endpoints.</li><li>Lookup of beans in the <a shape="rect" href="registry.html">Registry.</a></li><li>Additional supported in Spring XML (see below in examples).</li><li>Using Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a shape="rect" href="properties.html">Properties</a> component.</li><li>Using <strong><code>@PropertyInject</code></strong> to inject a property in a POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box functions, to lookup property values from OS environment variables, JVM system properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using custom functions, which can be plugged into the property component.</li></ul><h3 id="Properties-Format">Format</h3><p>The value of a Camel property can be obtained by specifying its key name within a property placeholder, using the following format: <strong>{{<code>key</code>}}</strong>.</p><p>For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl "> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[{{file.uri}}]]></script> +</div></div><p>where <strong><code>file.uri</code></strong> is the property key.</p><p>Property placeholders can be used to specify parts, or all, of an endpoint's URI by embedding one or more placeholders in the URI's string definition.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a default value to use if a property with the key does not exists, e.g., <strong><code>file.url:/some/path</code></strong> where the default value is the text after the colon, e.g., <strong><code>/some/path</code></strong>.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.14.1</strong>: do <em>not</em> use a colon in the property key. The colon character is used as a token separator when providing a default value.</p></div></div><h3 id="Properties-UsingPropertyResolver">Using <code >PropertyResolver</code></h3><p>Camel provides a pluggable mechanism that >allows third-parties to specify their own resolver to use for the lookup of >properties.</p><p>Camel provides a default implementation ><strong><code>org.apache.camel.component.properties.DefaultPropertiesResolver</code></strong> > which is capable of loading properties from the file system, classpath or <a >shape="rect" href="registry.html">Registry</a>. To indicate which source to >use the location must contain the appropriate prefix.</p><p>The list of >prefixes is:</p><div class="table-wrap"><table >class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" >class="confluenceTh"><p>Prefix</p></th><th colspan="1" rowspan="1" >class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" >rowspan="1" class="confluenceTd"><p><code>ref:</code></p></td><td colspan="1" >rowspan="1" class="confluenceTd"><p>Lookup in the <a shape="rect" >href="registry.html">Registry.</a></p></td></tr><tr><td colspan="1" >rowspan="1" class="confluenceTd"><p><code>file:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Load the from file system.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>classpath:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Load from the classpath (this is also the default if no prefix is provided).</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>blueprint:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Use a specific OSGi blueprint placeholder service.</p></td></tr></tbody></table></div><h3 id="Properties-DefiningLocation">Defining Location</h3><p>The <strong><code>PropertiesResolver</code></strong> must be configured with the location(s) to use when resolving properties. One or more locations can be given. Specifying multiple locations can be done a couple of ways: using either a single comma separated string, or an array of strings.</p><div class="code panel pdl" style="borde r-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties"); -]]></script> -</div></div><div><p><span><br clear="none"></span></p><p><strong>Available as of Camel 2.19.0</strong></p><p>You can set which location can be discarded if missing by by setting the <code>optional</code> attribute, which is false by default, i.e:</p></div><div><h4 id="Properties-ConfiguringinSpringXML">Configuring in Spring XML</h4><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocations( - "com/mycompany/override.properties;optional=true" - "com/mycompany/defaults.properties");]]></script> +pc.setLocation(new String[] {"com/mycompany/myprop.properties", "com/mycompany/other.properties"});Â ]]></script> +</div></div><div><p> </p><p>From<strong> Camel 2.19.0</strong>: you can set which location can be discarded if missing by setting  <strong><code>optional=true</code></strong>, (<strong><code>false</code></strong> by default).</p><p>Example:</p></div><div><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocations("com/mycompany/override.properties;optional=true,com/mycompany/defaults.properties");]]></script> </div></div><p> </p></div><h4 id="Properties-UsingSystemandEnvironmentVariablesinLocations">Using System and Environment Variables in Locations</h4><p><strong>Available as of Camel 2.7</strong></p><p>The location now supports using placeholders for JVM system properties and OS environments variables.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${karaf.home}/etc/foo.properties ]]></script> </div></div><p>In the location above we defined a location using the file scheme using the JVM system property with key <strong><code>karaf.home</code></strong>.</p><p>To use an OS environment variable instead you would have to prefix with <strong><code>env</code></strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/foo.properties ]]></script> -</div></div><p>Where <strong><code>APP_HOME</code></strong> is an OS environment.</p><p>You can have multiple placeholders in the same location, such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>Where <strong><code>APP_HOME</code></strong> is an OS environment variable.</p><p>You can have multiple placeholders in the same location, such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/${prop.name}.properties ]]></script> -</div></div><h4 id="Properties-UsingSystemandEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using System and Environment Variables to Configure Property Prefixes and Suffixes</h4><p><strong>Available as of Camel 2.12.5, 2.13.3, 2.14.0</strong></p><p><strong><code>propertyPrefix</code></strong>, <strong><code>propertySuffix</code></strong> configuration properties support using placeholders for JVM system properties and OS environments variables.</p><p>For example, if <strong><code>PropertiesComponent</code></strong> is configured with the following properties file:</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent"> -<pre>dev.endpoint = result1 -test.endpoint = result2</pre> -</div></div><p>Then with the following route definition:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h4 id="Properties-UsingSystemorEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using System or Environment Variables to Configure Property Prefixes and Suffixes</h4><p>From<strong> Camel 2.12.5, 2.13.3, 2.14.0</strong>:<strong><code> propertyPrefix</code></strong>, <strong><code>propertySuffix</code></strong> configuration properties support the use of placeholders for de-referencing JVM system properties and OS environments variables.</p><p>Example:</p><p>Assume the <strong><code>PropertiesComponent</code></strong> is configured with the following properties file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: text; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[dev.endpoint = result1 +test.endpoint = result2]]></script> +</div></div><p>The same properties file is then referenced from a route definition:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); pc.setPropertyPrefix("${stage}."); @@ -122,12 +122,12 @@ context.addRoutes(new RouteBuilder() { .to("properties:mock:{{endpoint}}"); } });]]></script> -</div></div><p>it is possible to change the target endpoint by changing system property <strong><code>stage</code></strong> either to <strong><code>dev</code></strong> (the message will be routed to <strong><code>mock:result1</code></strong>) or <strong><code>test</code></strong> (the message will be routed to <strong><code>mock:result2</code></strong>).</p><h3 id="Properties-ConfiguringinJavaDSL">Configuring in Java DSL</h3><p>You have to create and register the <strong><code>PropertiesComponent</code></strong> under the name <strong><code>properties</code></strong> such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>By using the configuration options <strong><code>propertyPrefix</code></strong> it's possible to change the target endpoint simply by changing the value of the system property <strong><code>stage</code></strong> either to <strong><code>dev</code></strong> (the message will be routed to <strong><code>mock:result1</code></strong>) or <strong><code>test</code></strong> (the message will be routed to <strong><code>mock:result2</code></strong>).</p><h3 id="Properties-ConfiguringinJavaDSL">Configuring in Java DSL</h3><p>You have to create and register the <strong><code>PropertiesComponent</code></strong> under the name <strong><code>properties</code></strong> such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[PropertiesComponent pc = new PropertiesComponent(); pc.setLocation("classpath:com/mycompany/myprop.properties"); context.addComponent("properties", pc); ]]></script> -</div></div><h3 id="Properties-ConfiguringinSpringXML.1">Configuring in Spring XML</h3><p>Spring XML offers two variations to configure. You can define a spring bean as a <strong><code>PropertiesComponent</code></strong> which resembles the way done in Java DSL. Or you can use the <strong><code><propertyPlaceholder></code></strong> tag.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="Properties-ConfiguringinSpringXML">Configuring in Spring XML</h3><p>Spring XML offers two variations to configure. You can define a spring bean as a <strong><code>PropertiesComponent</code></strong> which resembles the way done in Java DSL. Or you can use the <strong><code><propertyPlaceholder></code></strong> tag.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"> <property name="location" value="classpath:com/mycompany/myprop.properties"/> </bean> @@ -137,7 +137,7 @@ context.addComponent("properties&qu <propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/> </camelContext> ]]></script> -</div></div><p><span>Setting the properties location through the location tag works just fine but sometime you have a number of resources to take into account and starting from </span><strong>Camel 2.19.0</strong><span> you can set the properties location with a dedicated propertiesLocation:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p><span>Setting the properties location through the location tag works just fine but sometime you have a number of resources to take into account and starting from </span><strong>Camel 2.19.0</strong><span> you can set the properties location with a dedicated <strong><code>propertiesLocation</code></strong>:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext ...> <propertyPlaceholder id="myPropertyPlaceholder"> <propertiesLocation @@ -173,7 +173,7 @@ cool.foo=result from("direct:start") .to("properties:mock:{{cool.foo}}"); ]]></script> -</div></div><p>In the example above the to endpoint will be resolved to <code>mock:result</code>.</p><p>You can also have properties with refer to each other such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>In the example above the to endpoint will be resolved to <strong><code>mock:result</code></strong>.</p><p>You can also have properties with refer to each other such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[// properties cool.foo=result cool.concat=mock:{{cool.foo}} @@ -413,7 +413,7 @@ protected String useOverridePropertiesWi return "my-placeholders"; } ]]></script> -</div></div> <p>To do this we override and implement the <strong><code>useOverridePropertiesWithConfigAdmin</code></strong> method. We can then put the properties we want to override on the given props parameter. And the return value <em>must</em> be the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag, which you define in the blueprint XML file.</p><h4 id="Properties-Usinga.cfgor.propertiesFileforBlueprintPropertyPlaceholders">Using a <code>.cfg</code> or <code>.properties</code> File for Blueprint Property Placeholders</h4><p><strong>Available as of Camel 2.10.4</strong></p><p>When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties in a .properties or <strong><code>.cfg</code></strong> file. If you use Apache ServieMix/Karaf then this container has a convention that it loads the properties from a file in the etc directory with the naming <strong><code>etc/pid.cfg</code></strong>, where <strong><code>pid</code></strong> is the persistence-id.</p><p>For example in the blueprint XML file we have the <strong><code>persistence-id="stuff"</code></strong>, which mean it will load the configuration file as <strong><code>etc/stuff.cfg</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>To do this we override and implement the <strong><code>useOverridePropertiesWithConfigAdmin</code></strong> method. We can then put the properties we want to override on the given props parameter. And the return value <em>must</em> be the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag, which you define in the blueprint XML file.</p><h4 id="Properties-Usinga.cfgor.propertiesFileforBlueprintPropertyPlaceholders">Using a <code>.cfg</code> or <code>.properties</code> File for Blueprint Property Placeholders</h4><p><strong>Available as of Camel 2.10.4</strong></p><p>When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties in a .properties or <strong><code>.cfg</code></strong> file. If you use Apache ServiceMix/Karaf then this container has a convention that it loads the properties from a file in the etc directory with the naming <strong><code>etc/pid.cfg</code></strong> , where <strong><code>pid</code></strong> is the persistence-id.</p><p>For example in the blueprint XML file we have the <strong><code>persistence-id="stuff"</code></strong>, which mean it will load the configuration file as <strong><code>etc/stuff.cfg</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- blueprint property placeholders, that will use etc/stuff.cfg as the properties file --> <cm:property-placeholder persistent-id="stuff" update-strategy="reload"/> @@ -442,7 +442,7 @@ protected String[] loadConfigAdminConfig return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; } ]]></script> -</div></div> <p>Notice that this method requires to return a <strong><code>String[]</code></strong> with 2 values. The 1st value is the path for the configuration file to load. The 2nd value is the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag.</p><p>The <strong><code>stuff.cfg</code></strong> file is just a plain properties file with the property placeholders such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice that this method requires to return a <strong><code>String[]</code></strong> with 2 values. The 1st value is the path for the configuration file to load. The second value is the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag.</p><p>The <strong><code>stuff.cfg</code></strong> file is just a plain properties file with the property placeholders such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[## this is a comment greeting=Bye ]]></script> @@ -534,7 +534,7 @@ public class ConfigAdminLoadConfiguratio echo=Yay destination=mock:result ]]></script> -</div></div><h3 id="Properties-BridgingSpringandCamelPropertyPlaceholders">Bridging Spring and Camel Property Placeholders</h3><p><strong>Available as of Camel 2.10</strong></p><p>The Spring Framework does not allow 3rd party frameworks such as Apache Camel to seamless hook into the Spring property placeholder mechanism. However you can easily bridge Spring and Camel by declaring a Spring bean with the type <strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>, which is a Spring <strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong> type.</p><p>To bridge Spring and Camel you must define a single bean as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Bridging Spring and Camel property placeholders</b></div><div class="codeContent panelContent pdl"> +</div></div><h3 id="Properties-BridgingSpringandCamelPropertyPlaceholders">Bridging Spring and Camel Property Placeholders</h3><p><strong>Available as of Camel 2.10</strong></p><p>The Spring Framework does not allow third-party frameworks such as Apache Camel to seamless hook into the Spring property placeholder mechanism. However you can easily bridge Spring and Camel by declaring a Spring bean with the type <strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>, which is a Spring <strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong> type.</p><p>To bridge Spring and Camel you must define a single bean as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Bridging Spring and Camel property placeholders</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- bridge spring property placeholder with Camel --> @@ -584,7 +584,7 @@ protected Properties useOverrideProperti return extra; } ]]></script> -</div></div> <p>This can be done from any of the Camel Test kits, such as <code>camel-test</code>, <code>camel-test-spring</code> and <code>camel-test-blueprint</code>.</p><p>The <strong><code>ignoreMissingLocationWithPropertiesComponent</code></strong> can be used to instruct Camel to ignore any locations which was not discoverable. For example if you run the unit test, in an environment that does not have access to the location of the properties.</p><h3 id="Properties-Using@PropertyInject">Using <code>@PropertyInject</code></h3><p><strong>Available as of Camel 2.12</strong></p><p>Camel allows to inject property placeholders in POJOs using the <strong><code>@PropertyInject</code></strong> annotation which can be set on fields and setter methods. For example you can use that with <strong><code>RouteBuilder</code></strong> classes, such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>This can be done from any of the Camel Test kits, such as <strong><code>camel-test</code></strong>, <strong><code>camel-test-spring</code></strong> and <strong><code>camel-test-blueprint</code></strong>.</p><p>The <strong><code>ignoreMissingLocationWithPropertiesComponent</code></strong> can be used to instruct Camel to ignore any locations which was not discoverable. For example if you run the unit test, in an environment that does not have access to the location of the properties.</p><h3 id="Properties-Using@PropertyInject">Using <code>@PropertyInject</code></h3><p><strong>Available as of Camel 2.12</strong></p><p>Camel allows to inject property placeholders in POJOs using the <strong><code>@PropertyInject</code></strong> annotation which can be set on fields and setter methods. For example you can use that with <strong><code>RouteBuilder</code></strong> classes, such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div clas s="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends RouteBuilder { @PropertyInject("hello") @@ -606,7 +606,7 @@ private String greeting; <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@PropertyInject(value = "myTimeout", defaultValue = "5000") private int timeout; ]]></script> -</div></div><h3 id="Properties-UsingOutoftheBoxFunctions">Using Out of the Box Functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The <a shape="rect" href="properties.html">Properties</a> component includes the following functions out of the box</p><ul><li><code>env</code> - A function to lookup the property from OS environment variables.</li><li><code>sys</code> - A function to lookup the property from Java JVM system properties.</li><li><code>service</code> - A function to lookup the property from OS environment variables using the service naming idiom.</li><li><code>service.host</code> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the hostname part only.</li><li><code>service.port</code> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the port part only. </li></ul><p>As you can see these functions is intended to make it easy to lookup values from the environment. As they are provided out of the box, they can easily be used as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="Properties-UsingOutoftheBoxFunctions">Using Out of the Box Functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The <a shape="rect" href="properties.html">Properties</a> component includes the following functions out of the box</p><ul><li><strong><code>env</code></strong> - A function to lookup the property from OS environment variables.</li><li><strong><code>sys</code></strong> - A function to lookup the property from Java JVM system properties.</li><li><strong><code>service</code></strong> - A function to lookup the property from OS environment variables using the service naming idiom.</li><li><strong><code>service.host</code></strong> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the hostname part only.</li><li><strong><code>service.port</code></strong> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the port part only.</li></ul><p>As you can see these functions is intended to make it easy to lookup values from the environment. As they are provided out of the box, they can easily be used as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:start"/>
Modified: websites/production/camel/content/using-propertyplaceholder.html ============================================================================== --- websites/production/camel/content/using-propertyplaceholder.html (original) +++ websites/production/camel/content/using-propertyplaceholder.html Wed Feb 1 18:19:58 2017 @@ -86,26 +86,26 @@ <tbody> <tr> <td valign="top" width="100%"> -<div class="wiki-content maincontent"><h2 id="UsingPropertyPlaceholder-UsingPropertyPlaceholder">Using <code>PropertyPlaceholder</code></h2><p><strong>Available as of Camel 2.3</strong></p><p>Camel now provides a new <strong><code>PropertiesComponent</code></strong> in <strong>camel-core</strong> which allows you to use property placeholders when defining Camel <a shape="rect" href="endpoint.html">Endpoint</a> URIs. This works much like you would do if using Spring's <strong><code><property-placeholder></code></strong> tag. However Spring has a limitation that prevents 3rd party frameworks from fully leveraging Spring property placeholders.</p><p>For more details see: <a shape="rect" href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I use Spring Property Placeholder with Camel XML</a>.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Bridging Spring and Camel property placeholders</p><span class="aui-i con aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.10</strong>: Spring's property placeholder can be bridged with Camel's. See below for more details.</p></div></div><p>The property placeholder is generally in use when doing any of the following:</p><ul class="alternate"><li>lookup or creating endpoints.</li><li>lookup of beans in the <a shape="rect" href="registry.html">Registry.</a></li><li>additional supported in Spring XML (see below in examples).</li><li>using Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a shape="rect" href="properties.html">Properties</a> component.</li><li>using <strong><code>@PropertyInject</code></strong> to inject a property in a POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box functions, to lookup property values from OS environment variables, JVM system properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using custom functions, which can be plugged into the property component.</li></ul><h3 id="UsingPropertyPlaceholder-Syntax">Syntax</h3><p>The syntax to use Camel's property placeholder is to use <strong>{{<code>key</code>}}</strong> for example <strong>{{<code>file.uri</code>}}</strong> where <strong><code>file.uri</code></strong> is the property key. You can use property placeholders in parts of the endpoint URI's which for example you can use placeholders for parameters in the URIs.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a default value to use if a property with the key does not exists, e.g., <strong><code>file.url:/some/path</code></strong> where the default value is the text after the colon, e.g., <strong><code>/some/path</code></strong>.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui -icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.14.1</strong>: do <em>not</em> use a colon in the property key. The colon character is used as a token separator when providing a default value.</p></div></div><h3 id="UsingPropertyPlaceholder-UsingPropertyResolver">Using <code>PropertyResolver</code></h3><p>Camel provides a pluggable mechanism which allows 3rd part to provide their own resolver to lookup properties. Camel provides a default implementation <strong><code>org.apache.camel.component.properties.DefaultPropertiesResolver</code></strong> which is capable of loading properties from the file system, classpath or <a shape="rect" href="registry.html">Registry</a>. You can prefix the locations with either:</p><ul class="alternate"><li><strong><code>ref:</code> Camel 2.4:</strong> to lookup in the <a shape="rect" href="registry.html">Registry.</a></li><li><strong><code>file:</code>< /strong> to load the from file system.</li><li><strong><code>classpath:</code></strong> to load from classpath (this is also the default if no prefix is provided).</li><li><strong><code>blueprint:</code> Camel 2.7:</strong> to use a specific OSGi blueprint placeholder service.</li></ul><h3 id="UsingPropertyPlaceholder-DefiningLocation">Defining Location</h3><p>The <strong><code>PropertiesResolver</code></strong> need to know a location(s) where to resolve the properties. You can define 1 to many locations. If you define the location in a single String property you can separate multiple locations with comma such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<div class="wiki-content maincontent"><h2 id="UsingPropertyPlaceholder-UsingPropertyPlaceholder">Using <strong><code>PropertyPlaceholder</code></strong></h2><p><strong>Available as of Camel 2.3</strong></p><p>Camel now provides a new <strong><code>PropertiesComponent</code></strong> in <strong><code>camel-core</code></strong> which allows you to use property placeholders when defining Camel <a shape="rect" href="endpoint.html">Endpoint</a> URIs. This works much like you would do if using Spring's <strong><code><property-placeholder></code></strong> tag. However Spring has a limitation that prevents third-party frameworks from fully leveraging Spring property placeholders.</p><p>For more details see: <a shape="rect" href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I use Spring Property Placeholder with Camel XML</a>.</p><div class="confluence-information-macro confluence-information-macro-tip"><p class="title">Bridging Spring and Camel proper ty placeholders</p><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.10</strong>: Spring's property placeholder can be bridged with Camel's. See below for more details.</p></div></div><p>The property placeholder is typically used when trying to do any of the following:</p><ul class="alternate"><li>Lookup or creating endpoints.</li><li>Lookup of beans in the <a shape="rect" href="registry.html">Registry.</a></li><li>Additional supported in Spring XML (see below in examples).</li><li>Using Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a shape="rect" href="properties.html">Properties</a> component.</li><li>Using <strong><code>@PropertyInject</code></strong> to inject a property in a POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box functions, to lookup property values from OS environment variables, JVM system properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using custom functions, which can be plugged into the property component.</li></ul><h3 id="UsingPropertyPlaceholder-Format">Format</h3><p>The value of a Camel property can be obtained by specifying its key name within a property placeholder, using the following format: <strong>{{<code>key</code>}}</strong>.</p><p>For example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[{{file.uri}}]]></script> +</div></div><p>where <strong><code>file.uri</code></strong> is the property key.</p><p>Property placeholders can be used to specify parts, or all, of an endpoint's URI by embedding one or more placeholders in the URI's string definition.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a default value to use if a property with the key does not exists, e.g., <strong><code>file.url:/some/path</code></strong> where the default value is the text after the colon, e.g., <strong><code>/some/path</code></strong>.</p><div class="confluence-information-macro confluence-information-macro-information"><span class="aui-icon aui-icon-small aui-iconfont-info confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>From <strong>Camel 2.14.1</strong>: do <em>not</em> use a colon in the property key. The colon character is used as a token separator when providing a default value.</p></div></div><h3 id="UsingPropertyPlaceholder-UsingPropertyResolver">Us ing <code>PropertyResolver</code></h3><p>Camel provides a pluggable mechanism that allows third-parties to specify their own resolver to use for the lookup of properties.</p><p>Camel provides a default implementation <strong><code>org.apache.camel.component.properties.DefaultPropertiesResolver</code></strong> which is capable of loading properties from the file system, classpath or <a shape="rect" href="registry.html">Registry</a>. To indicate which source to use the location must contain the appropriate prefix.</p><p>The list of prefixes is:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Prefix</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>ref:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Lookup in the <a shape="rect" href="registry.html">Registry.</a></p></td></tr><tr><td colspan="1 " rowspan="1" class="confluenceTd"><p><code>file:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Load the from file system.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>classpath:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Load from the classpath (this is also the default if no prefix is provided).</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>blueprint:</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Use a specific OSGi blueprint placeholder service.</p></td></tr></tbody></table></div><h3 id="UsingPropertyPlaceholder-DefiningLocation">Defining Location</h3><p>The <strong><code>PropertiesResolver</code></strong> must be configured with the location(s) to use when resolving properties. One or more locations can be given. Specifying multiple locations can be done a couple of ways: using either a single comma separated string, or an array of strings.</p><div class=" code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties"); -]]></script> -</div></div><div><p><span><br clear="none"></span></p><p><strong>Available as of Camel 2.19.0</strong></p><p>You can set which location can be discarded if missing by by setting the <code>optional</code> attribute, which is false by default, i.e:</p></div><div><h4 id="UsingPropertyPlaceholder-ConfiguringinSpringXML">Configuring in Spring XML</h4><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> -<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocations( - "com/mycompany/override.properties;optional=true" - "com/mycompany/defaults.properties");]]></script> +pc.setLocation(new String[] {"com/mycompany/myprop.properties", "com/mycompany/other.properties"});Â ]]></script> +</div></div><div><p> </p><p>From<strong> Camel 2.19.0</strong>: you can set which location can be discarded if missing by setting  <strong><code>optional=true</code></strong>, (<strong><code>false</code></strong> by default).</p><p>Example:</p></div><div><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocations("com/mycompany/override.properties;optional=true,com/mycompany/defaults.properties");]]></script> </div></div><p> </p></div><h4 id="UsingPropertyPlaceholder-UsingSystemandEnvironmentVariablesinLocations">Using System and Environment Variables in Locations</h4><p><strong>Available as of Camel 2.7</strong></p><p>The location now supports using placeholders for JVM system properties and OS environments variables.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${karaf.home}/etc/foo.properties ]]></script> </div></div><p>In the location above we defined a location using the file scheme using the JVM system property with key <strong><code>karaf.home</code></strong>.</p><p>To use an OS environment variable instead you would have to prefix with <strong><code>env</code></strong>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/foo.properties ]]></script> -</div></div><p>Where <strong><code>APP_HOME</code></strong> is an OS environment.</p><p>You can have multiple placeholders in the same location, such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>Where <strong><code>APP_HOME</code></strong> is an OS environment variable.</p><p>You can have multiple placeholders in the same location, such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/${prop.name}.properties ]]></script> -</div></div><h4 id="UsingPropertyPlaceholder-UsingSystemandEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using System and Environment Variables to Configure Property Prefixes and Suffixes</h4><p><strong>Available as of Camel 2.12.5, 2.13.3, 2.14.0</strong></p><p><strong><code>propertyPrefix</code></strong>, <strong><code>propertySuffix</code></strong> configuration properties support using placeholders for JVM system properties and OS environments variables.</p><p>For example, if <strong><code>PropertiesComponent</code></strong> is configured with the following properties file:</p><div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent panelContent"> -<pre>dev.endpoint = result1 -test.endpoint = result2</pre> -</div></div><p>Then with the following route definition:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h4 id="UsingPropertyPlaceholder-UsingSystemorEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using System or Environment Variables to Configure Property Prefixes and Suffixes</h4><p>From<strong> Camel 2.12.5, 2.13.3, 2.14.0</strong>:<strong><code> propertyPrefix</code></strong>, <strong><code>propertySuffix</code></strong> configuration properties support the use of placeholders for de-referencing JVM system properties and OS environments variables.</p><p>Example:</p><p>Assume the <strong><code>PropertiesComponent</code></strong> is configured with the following properties file:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="brush: text; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[dev.endpoint = result1 +test.endpoint = result2]]></script> +</div></div><p>The same properties file is then referenced from a route definition:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[PropertiesComponent pc = context.getComponent("properties", PropertiesComponent.class); pc.setPropertyPrefix("${stage}."); @@ -117,12 +117,12 @@ context.addRoutes(new RouteBuilder() { .to("properties:mock:{{endpoint}}"); } });]]></script> -</div></div><p>it is possible to change the target endpoint by changing system property <strong><code>stage</code></strong> either to <strong><code>dev</code></strong> (the message will be routed to <strong><code>mock:result1</code></strong>) or <strong><code>test</code></strong> (the message will be routed to <strong><code>mock:result2</code></strong>).</p><h3 id="UsingPropertyPlaceholder-ConfiguringinJavaDSL">Configuring in Java DSL</h3><p>You have to create and register the <strong><code>PropertiesComponent</code></strong> under the name <strong><code>properties</code></strong> such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>By using the configuration options <strong><code>propertyPrefix</code></strong> it's possible to change the target endpoint simply by changing the value of the system property <strong><code>stage</code></strong> either to <strong><code>dev</code></strong> (the message will be routed to <strong><code>mock:result1</code></strong>) or <strong><code>test</code></strong> (the message will be routed to <strong><code>mock:result2</code></strong>).</p><h3 id="UsingPropertyPlaceholder-ConfiguringinJavaDSL">Configuring in Java DSL</h3><p>You have to create and register the <strong><code>PropertiesComponent</code></strong> under the name <strong><code>properties</code></strong> such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[PropertiesComponent pc = new PropertiesComponent(); pc.setLocation("classpath:com/mycompany/myprop.properties"); context.addComponent("properties", pc); ]]></script> -</div></div><h3 id="UsingPropertyPlaceholder-ConfiguringinSpringXML.1">Configuring in Spring XML</h3><p>Spring XML offers two variations to configure. You can define a spring bean as a <strong><code>PropertiesComponent</code></strong> which resembles the way done in Java DSL. Or you can use the <strong><code><propertyPlaceholder></code></strong> tag.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="UsingPropertyPlaceholder-ConfiguringinSpringXML">Configuring in Spring XML</h3><p>Spring XML offers two variations to configure. You can define a spring bean as a <strong><code>PropertiesComponent</code></strong> which resembles the way done in Java DSL. Or you can use the <strong><code><propertyPlaceholder></code></strong> tag.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"> <property name="location" value="classpath:com/mycompany/myprop.properties"/> </bean> @@ -132,7 +132,7 @@ context.addComponent("properties&qu <propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/> </camelContext> ]]></script> -</div></div><p><span>Setting the properties location through the location tag works just fine but sometime you have a number of resources to take into account and starting from </span><strong>Camel 2.19.0</strong><span> you can set the properties location with a dedicated propertiesLocation:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p><span>Setting the properties location through the location tag works just fine but sometime you have a number of resources to take into account and starting from </span><strong>Camel 2.19.0</strong><span> you can set the properties location with a dedicated <strong><code>propertiesLocation</code></strong>:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext ...> <propertyPlaceholder id="myPropertyPlaceholder"> <propertiesLocation @@ -168,7 +168,7 @@ cool.foo=result from("direct:start") .to("properties:mock:{{cool.foo}}"); ]]></script> -</div></div><p>In the example above the to endpoint will be resolved to <code>mock:result</code>.</p><p>You can also have properties with refer to each other such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>In the example above the to endpoint will be resolved to <strong><code>mock:result</code></strong>.</p><p>You can also have properties with refer to each other such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[// properties cool.foo=result cool.concat=mock:{{cool.foo}} @@ -408,7 +408,7 @@ protected String useOverridePropertiesWi return "my-placeholders"; } ]]></script> -</div></div> <p>To do this we override and implement the <strong><code>useOverridePropertiesWithConfigAdmin</code></strong> method. We can then put the properties we want to override on the given props parameter. And the return value <em>must</em> be the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag, which you define in the blueprint XML file.</p><h4 id="UsingPropertyPlaceholder-Usinga.cfgor.propertiesFileforBlueprintPropertyPlaceholders">Using a <code>.cfg</code> or <code>.properties</code> File for Blueprint Property Placeholders</h4><p><strong>Available as of Camel 2.10.4</strong></p><p>When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties in a .properties or <strong><code>.cfg</code></strong> file. If you use Apache ServieMix/Karaf then this container has a convention that it loads the properties from a file in the etc directory with the naming <strong><code>etc/pid.cfg</c ode></strong>, where <strong><code>pid</code></strong> is the persistence-id.</p><p>For example in the blueprint XML file we have the <strong><code>persistence-id="stuff"</code></strong>, which mean it will load the configuration file as <strong><code>etc/stuff.cfg</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>To do this we override and implement the <strong><code>useOverridePropertiesWithConfigAdmin</code></strong> method. We can then put the properties we want to override on the given props parameter. And the return value <em>must</em> be the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag, which you define in the blueprint XML file.</p><h4 id="UsingPropertyPlaceholder-Usinga.cfgor.propertiesFileforBlueprintPropertyPlaceholders">Using a <code>.cfg</code> or <code>.properties</code> File for Blueprint Property Placeholders</h4><p><strong>Available as of Camel 2.10.4</strong></p><p>When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties in a .properties or <strong><code>.cfg</code></strong> file. If you use Apache ServiceMix/Karaf then this container has a convention that it loads the properties from a file in the etc directory with the naming <strong><code>etc/pid.cfg</ code></strong>, where <strong><code>pid</code></strong> is the persistence-id.</p><p>For example in the blueprint XML file we have the <strong><code>persistence-id="stuff"</code></strong>, which mean it will load the configuration file as <strong><code>etc/stuff.cfg</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- blueprint property placeholders, that will use etc/stuff.cfg as the properties file --> <cm:property-placeholder persistent-id="stuff" update-strategy="reload"/> @@ -437,7 +437,7 @@ protected String[] loadConfigAdminConfig return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; } ]]></script> -</div></div> <p>Notice that this method requires to return a <strong><code>String[]</code></strong> with 2 values. The 1st value is the path for the configuration file to load. The 2nd value is the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag.</p><p>The <strong><code>stuff.cfg</code></strong> file is just a plain properties file with the property placeholders such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice that this method requires to return a <strong><code>String[]</code></strong> with 2 values. The 1st value is the path for the configuration file to load. The second value is the persistence-id of the <strong><code><cm:property-placeholder></code></strong> tag.</p><p>The <strong><code>stuff.cfg</code></strong> file is just a plain properties file with the property placeholders such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[## this is a comment greeting=Bye ]]></script> @@ -529,7 +529,7 @@ public class ConfigAdminLoadConfiguratio echo=Yay destination=mock:result ]]></script> -</div></div><h3 id="UsingPropertyPlaceholder-BridgingSpringandCamelPropertyPlaceholders">Bridging Spring and Camel Property Placeholders</h3><p><strong>Available as of Camel 2.10</strong></p><p>The Spring Framework does not allow 3rd party frameworks such as Apache Camel to seamless hook into the Spring property placeholder mechanism. However you can easily bridge Spring and Camel by declaring a Spring bean with the type <strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>, which is a Spring <strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong> type.</p><p>To bridge Spring and Camel you must define a single bean as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Bridging Spring and Camel property placeholders</b></div><div class="codeContent panelContent pdl"> +</div></div><h3 id="UsingPropertyPlaceholder-BridgingSpringandCamelPropertyPlaceholders">Bridging Spring and Camel Property Placeholders</h3><p><strong>Available as of Camel 2.10</strong></p><p>The Spring Framework does not allow third-party frameworks such as Apache Camel to seamless hook into the Spring property placeholder mechanism. However you can easily bridge Spring and Camel by declaring a Spring bean with the type <strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>, which is a Spring <strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong> type.</p><p>To bridge Spring and Camel you must define a single bean as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Bridging Spring and Camel property placeholders</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- bridge spring property placeholder with Camel --> @@ -579,7 +579,7 @@ protected Properties useOverrideProperti return extra; } ]]></script> -</div></div> <p>This can be done from any of the Camel Test kits, such as <code>camel-test</code>, <code>camel-test-spring</code> and <code>camel-test-blueprint</code>.</p><p>The <strong><code>ignoreMissingLocationWithPropertiesComponent</code></strong> can be used to instruct Camel to ignore any locations which was not discoverable. For example if you run the unit test, in an environment that does not have access to the location of the properties.</p><h3 id="UsingPropertyPlaceholder-Using@PropertyInject">Using <code>@PropertyInject</code></h3><p><strong>Available as of Camel 2.12</strong></p><p>Camel allows to inject property placeholders in POJOs using the <strong><code>@PropertyInject</code></strong> annotation which can be set on fields and setter methods. For example you can use that with <strong><code>RouteBuilder</code></strong> classes, such as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>This can be done from any of the Camel Test kits, such as <strong><code>camel-test</code></strong>, <strong><code>camel-test-spring</code></strong> and <strong><code>camel-test-blueprint</code></strong>.</p><p>The <strong><code>ignoreMissingLocationWithPropertiesComponent</code></strong> can be used to instruct Camel to ignore any locations which was not discoverable. For example if you run the unit test, in an environment that does not have access to the location of the properties.</p><h3 id="UsingPropertyPlaceholder-Using@PropertyInject">Using <code>@PropertyInject</code></h3><p><strong>Available as of Camel 2.12</strong></p><p>Camel allows to inject property placeholders in POJOs using the <strong><code>@PropertyInject</code></strong> annotation which can be set on fields and setter methods. For example you can use that with <strong><code>RouteBuilder</code></strong> classes, such as shown below:</p><div class="code panel pdl" style="border-width: 1 px;"><div class="codeContent panelContent pdl"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends RouteBuilder { @PropertyInject("hello") @@ -601,7 +601,7 @@ private String greeting; <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[@PropertyInject(value = "myTimeout", defaultValue = "5000") private int timeout; ]]></script> -</div></div><h3 id="UsingPropertyPlaceholder-UsingOutoftheBoxFunctions">Using Out of the Box Functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The <a shape="rect" href="properties.html">Properties</a> component includes the following functions out of the box</p><ul><li><code>env</code> - A function to lookup the property from OS environment variables.</li><li><code>sys</code> - A function to lookup the property from Java JVM system properties.</li><li><code>service</code> - A function to lookup the property from OS environment variables using the service naming idiom.</li><li><code>service.host</code> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the hostname part only.</li><li><code>service.port</code> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the p ort part only.</li></ul><p>As you can see these functions is intended to make it easy to lookup values from the environment. As they are provided out of the box, they can easily be used as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="UsingPropertyPlaceholder-UsingOutoftheBoxFunctions">Using Out of the Box Functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The <a shape="rect" href="properties.html">Properties</a> component includes the following functions out of the box</p><ul><li><strong><code>env</code></strong> - A function to lookup the property from OS environment variables.</li><li><strong><code>sys</code></strong> - A function to lookup the property from Java JVM system properties.</li><li><strong><code>service</code></strong> - A function to lookup the property from OS environment variables using the service naming idiom.</li><li><strong><code>service.host</code></strong> - <strong>Camel 2.16.1: </strong>A function to lookup the property from OS environment variables using the service naming idiom returning the hostname part only.</li><li><strong><code>service.port</code></strong> - <strong>Camel 2.16.1: </strong>A function to lookup the prope rty from OS environment variables using the service naming idiom returning the port part only.</li></ul><p>As you can see these functions is intended to make it easy to lookup values from the environment. As they are provided out of the box, they can easily be used as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:start"/>