Modified: websites/production/camel/content/properties.html ============================================================================== --- websites/production/camel/content/properties.html (original) +++ websites/production/camel/content/properties.html Thu Sep 8 17:19:22 2016 @@ -89,7 +89,7 @@ <div class="wiki-content maincontent"><h2 id="Properties-PropertiesComponent">Properties Component</h2><p><strong>Available as of Camel 2.3</strong></p><h3 id="Properties-URIformat">URI format</h3><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:key[?options] ]]></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="confluen ceTd"><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:</strong> 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 th e augmented property name is searched.</p></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 list 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 an d 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></td></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-ico n-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 have a limitation which prevents 3rd party frameworks to leverage Spring property placeholders to the fullest.</p><p>For more details see: <a shape="rect" href="how-do-i-use-spr ing-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:</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>@Prope rtyInject</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 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:/so me/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.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="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 with comma such as:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</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="confluen ceTd"><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:</strong> 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 th e augmented property name is searched.</p></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 list 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 an d 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></td></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-ico n-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 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-pro perty-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 <stron g><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 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><cod e>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.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="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 with comma 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[pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties"); ]]></script> </div></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"> @@ -201,7 +201,7 @@ bar.quote=Beer tastes good from("direct:start") .transform().simple("Hi ${body}. ${properties:com/mycompany/bar.properties:bar.quote}."); ]]></script> -</div></div><h3 id="Properties-AdditionalPropertyPlaceholderSupportinSpringXML">Additional Property Placeholder Support in Spring XML</h3><p>The property placeholders is also supported in many of the Camel Spring XML tags such as <code><strong><package></strong>, <strong><packageScan></strong>, <strong><contextScan></strong>, <strong><jmxAgent></strong>, <strong><endpoint></strong>, <strong><routeBuilder></strong>, <strong><proxy></strong></code> and the others.</p><p>The example below has property placeholder in the <strong><code><jmxAgent></code></strong> tag:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="Properties-AdditionalPropertyPlaceholderSupportinSpringXML">Additional Property Placeholder Support in Spring XML</h3><p>The property placeholders is also supported in many of the Camel Spring XML tags such as <code><strong><package></strong>, <strong><packageScan></strong>, <strong><contextScan></strong>, <strong><jmxAgent></strong>, <strong><endpoint></strong>, <strong><routeBuilder></strong>, <strong><proxy></strong></code> and the others.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using property placeholders in the <jmxAgent> tag</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="org/apache/camel/spring/jmx.properties"/> @@ -217,7 +217,7 @@ from("direct:start") <to uri="mock:result"/> </route> </camelContext>]]></script> -</div></div><p>You can also define property placeholders in the various attributes on the <strong><code><camelContext></code></strong> tag such as <strong><code>trace</code></strong> as shown here:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using property placeholders in the attributes of <camelContext></b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="org/apache/camel/spring/processor/myprop.properties"/> @@ -257,14 +257,12 @@ System.clearProperty("cool.result&q assertMockEndpointsSatisfied(); ]]></script> -</div></div><h3 id="Properties-UsingPropertyPlaceholdersforAnyKindofAttributeintheXMLDSL">Using Property Placeholders for Any Kind of Attribute in the XML DSL</h3><p><strong>Available as of Camel 2.7</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>If you use OSGi Blueprint then this only works from <strong>2.11.1</strong> or <strong>2.10.5</strong> on.</p></div></div><p>Previously it was only the <strong><code>xs:string</code></strong> type attributes in the XML DSL that support placeholders. For example often a timeout attribute would be a <strong><code>xs:int</code></strong> type and thus you cannot set a string value as the placeholder key. This is now possible from Camel 2.7 on using a special placeholder namespace.</p><p>In the example below we use the <code>prop</code> prefix for the na mespace <code><a shape="rect" class="external-link" href="http://camel.apache.org/schema/placeholder">http://camel.apache.org/schema/placeholder</a></code> by which we can use the <strong><code>prop</code></strong> prefix in the attributes in the XML DSLs. Notice how we use that in the <a shape="rect" href="multicast.html">Multicast</a> to indicate that the option <strong><code>stopOnException</code></strong> should be the value of the placeholder with the key <strong><code>stop</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="Properties-UsingPropertyPlaceholdersforAnyKindofAttributeintheXMLDSL">Using Property Placeholders for Any Kind of Attribute in the XML DSL</h3><p><strong>Available as of Camel 2.7</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>If you use OSGi Blueprint then this only works from <strong>2.11.1</strong> or <strong>2.10.5</strong> on.</p></div></div><p>Previously it was only the <strong><code>xs:string</code></strong> type attributes in the XML DSL that support placeholders. For example often a timeout attribute would be a <strong><code>xs:int</code></strong> type and thus you cannot set a string value as the placeholder key. This is now possible from Camel 2.7 on using a special placeholder namespace.</p><p>In the example below we use the <strong><code>prop</code></strong> prefix for the namespace <code><a shape="rect" class="external-link" href="http://camel.apache.org/schema/placeholder">http://camel.apache.org/schema/placeholder</a></code> by which we can use the <strong><code>prop</code></strong> prefix in the attributes in the XML DSLs. Notice how we use that in the <a shape="rect" href="multicast.html">Multicast</a> to indicate that the option <strong><code>stopOnException</code></strong> should be the value of the placeholder with the key <strong><code>stop</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[<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:prop="http://camel.apache.org/schema/placeholder" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd - "> + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <!-- Notice in the declaration above, we have defined the prop prefix as the Camel placeholder namespace --> @@ -273,7 +271,6 @@ assertMockEndpointsSatisfied(); </bean> <camelContext xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="classpath:org/apache/camel/component/properties/myprop.properties" xmlns="http://camel.apache.org/schema/spring"/> @@ -306,8 +303,7 @@ assertMockEndpointsSatisfied(); <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" - xsi:schemaLocation=" - http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <!-- OSGI blueprint property placeholder --> <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint"> @@ -331,8 +327,7 @@ assertMockEndpointsSatisfied(); <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" - xsi:schemaLocation=" - http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <!-- OSGI blueprint property placeholder --> <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint"> @@ -384,7 +379,7 @@ assertMockEndpointsSatisfied(); </camelContext> ]]></script> -</div></div>Notice that we have a <strong><code><bean></code></strong> which refers to one of the properties. And in the Camel route we refer to the other using the <strong><code>{{ }}</code></strong> notation.<p>Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice that we have a <strong><code><bean></code></strong> which refers to one of the properties. And in the Camel route we refer to the other using the <strong><code>{{ }}</code></strong> notation.</p><p>Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:</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[ @Override protected String useOverridePropertiesWithConfigAdmin(Dictionary props) { @@ -395,7 +390,7 @@ protected String useOverridePropertiesWi return "my-placeholders"; } ]]></script> -</div></div>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.<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 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"> <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"/> @@ -415,7 +410,7 @@ protected String useOverridePropertiesWi </camelContext> ]]></script> -</div></div>Now if you want to unit test this blueprint XML file, then you can override the <strong><code>loadConfigAdminConfigurationFile</code></strong> and tell Camel which file to load as shown below:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Now if you want to unit test this blueprint XML file, then you can override the <strong><code>loadConfigAdminConfigurationFile</code></strong> and tell Camel which file to load as shown below:</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[ @Override protected String[] loadConfigAdminConfigurationFile() { @@ -424,7 +419,7 @@ protected String[] loadConfigAdminConfig return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; } ]]></script> -</div></div>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>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 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"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[## this is a comment greeting=Bye ]]></script> @@ -466,7 +461,7 @@ greeting=Bye </blueprint> ]]></script> -</div></div>And in the unit test class we do as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>And in the unit test class we do as follows:</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 example will load a Blueprint .cfg file (which will initialize configadmin), and also override its property @@ -511,7 +506,7 @@ public class ConfigAdminLoadConfiguratio } ]]></script> -</div></div>And the <strong><code>etc/stuff.cfg</code></strong> configuration file contains:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>And the <strong><code>etc/stuff.cfg</code></strong> configuration file contains:</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[greeting=Bye echo=Yay destination=mock:result @@ -526,7 +521,7 @@ destination=mock:result </bean> ]]></script> -</div></div>You <strong>must not</strong> use the spring <strong><code><context:property-placeholder></code></strong> namespace at the same time; this is not possible.<p>After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <strong><code><camelContext></code></strong> tag as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using bridge property placeholders</b></div><div class="codeContent panelContent pdl"> +</div></div> <p>You <strong>must not</strong> use the spring <strong><code><context:property-placeholder></code></strong> namespace at the same time; this is not possible.</p><p>After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <strong><code><camelContext></code></strong> tag as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using bridge property placeholders</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- a bean that uses Spring property placeholder --> @@ -545,7 +540,7 @@ destination=mock:result </camelContext> ]]></script> -</div></div>Notice how the hello bean is using pure Spring property placeholders using the <strong><code>${}</code></strong> notation. And in the Camel routes we use the Camel placeholder notation with <strong><code>{{ }}</code></strong>.<h4 id="Properties-ClashingSpringPropertyPlaceholderswithCamelsLanguage">Clashing Spring Property Placeholders with Camels <a shape="rect" href="simple.html">Simple</a> Language</h4><p>Take notice when using Spring bridging placeholder then the spring <strong><code>${}</code></strong> syntax clashes with the <a shape="rect" href="simple.html">Simple</a> in Camel, and therefore take care.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice how the hello bean is using pure Spring property placeholders using the <strong><code>${}</code></strong> notation. And in the Camel routes we use the Camel placeholder notation with <strong><code>{{ }}</code></strong>.</p><h4 id="Properties-ClashingSpringPropertyPlaceholderswithCamelsLanguage">Clashing Spring Property Placeholders with Camels <a shape="rect" href="simple.html">Simple</a> Language</h4><p>Take notice when using Spring bridging placeholder then the spring <strong><code>${}</code></strong> syntax clashes with the <a shape="rect" href="simple.html">Simple</a> in Camel, and therefore take care.</p><p>Example:</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[<setHeader headerName="Exchange.FILE_NAME"> <simple>{{file.rootdir}}/${in.header.CamelFileName}</simple> </setHeader> @@ -566,7 +561,7 @@ protected Properties useOverrideProperti return extra; } ]]></script> -</div></div>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>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 <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"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends RouteBuilder { @PropertyInject("hello") @@ -641,7 +636,8 @@ export $FOO_SERVICE_PORT=8888]]></script public String getName() { return "beer"; } - @Override + + Â @Override public String apply(String remainder) { return "mock:" + remainder.toLowerCase(); }
Modified: websites/production/camel/content/using-propertyplaceholder.html ============================================================================== --- websites/production/camel/content/using-propertyplaceholder.html (original) +++ websites/production/camel/content/using-propertyplaceholder.html Thu Sep 8 17:19:22 2016 @@ -86,7 +86,7 @@ <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 have a limitation which prevents 3rd party frameworks to leverage Spring property placeholders to the fullest.</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:</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 au i-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 loa d 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 <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"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties"); ]]></script> </div></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"> @@ -198,7 +198,7 @@ bar.quote=Beer tastes good from("direct:start") .transform().simple("Hi ${body}. ${properties:com/mycompany/bar.properties:bar.quote}."); ]]></script> -</div></div><h3 id="UsingPropertyPlaceholder-AdditionalPropertyPlaceholderSupportinSpringXML">Additional Property Placeholder Support in Spring XML</h3><p>The property placeholders is also supported in many of the Camel Spring XML tags such as <code><strong><package></strong>, <strong><packageScan></strong>, <strong><contextScan></strong>, <strong><jmxAgent></strong>, <strong><endpoint></strong>, <strong><routeBuilder></strong>, <strong><proxy></strong></code> and the others.</p><p>The example below has property placeholder in the <strong><code><jmxAgent></code></strong> tag:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="UsingPropertyPlaceholder-AdditionalPropertyPlaceholderSupportinSpringXML">Additional Property Placeholder Support in Spring XML</h3><p>The property placeholders is also supported in many of the Camel Spring XML tags such as <code><strong><package></strong>, <strong><packageScan></strong>, <strong><contextScan></strong>, <strong><jmxAgent></strong>, <strong><endpoint></strong>, <strong><routeBuilder></strong>, <strong><proxy></strong></code> and the others.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using property placeholders in the <jmxAgent> tag</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="org/apache/camel/spring/jmx.properties"/> @@ -214,7 +214,7 @@ from("direct:start") <to uri="mock:result"/> </route> </camelContext>]]></script> -</div></div><p>You can also define property placeholders in the various attributes on the <strong><code><camelContext></code></strong> tag such as <strong><code>trace</code></strong> as shown here:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using property placeholders in the attributes of <camelContext></b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<camelContext trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/spring"> <propertyPlaceholder id="properties" location="org/apache/camel/spring/processor/myprop.properties"/> @@ -254,14 +254,12 @@ System.clearProperty("cool.result&q assertMockEndpointsSatisfied(); ]]></script> -</div></div><h3 id="UsingPropertyPlaceholder-UsingPropertyPlaceholdersforAnyKindofAttributeintheXMLDSL">Using Property Placeholders for Any Kind of Attribute in the XML DSL</h3><p><strong>Available as of Camel 2.7</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>If you use OSGi Blueprint then this only works from <strong>2.11.1</strong> or <strong>2.10.5</strong> on.</p></div></div><p>Previously it was only the <strong><code>xs:string</code></strong> type attributes in the XML DSL that support placeholders. For example often a timeout attribute would be a <strong><code>xs:int</code></strong> type and thus you cannot set a string value as the placeholder key. This is now possible from Camel 2.7 on using a special placeholder namespace.</p><p>In the example below we use the <code>prop</code> pre fix for the namespace <code><a shape="rect" class="external-link" href="http://camel.apache.org/schema/placeholder">http://camel.apache.org/schema/placeholder</a></code> by which we can use the <strong><code>prop</code></strong> prefix in the attributes in the XML DSLs. Notice how we use that in the <a shape="rect" href="multicast.html">Multicast</a> to indicate that the option <strong><code>stopOnException</code></strong> should be the value of the placeholder with the key <strong><code>stop</code></strong>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><h3 id="UsingPropertyPlaceholder-UsingPropertyPlaceholdersforAnyKindofAttributeintheXMLDSL">Using Property Placeholders for Any Kind of Attribute in the XML DSL</h3><p><strong>Available as of Camel 2.7</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>If you use OSGi Blueprint then this only works from <strong>2.11.1</strong> or <strong>2.10.5</strong> on.</p></div></div><p>Previously it was only the <strong><code>xs:string</code></strong> type attributes in the XML DSL that support placeholders. For example often a timeout attribute would be a <strong><code>xs:int</code></strong> type and thus you cannot set a string value as the placeholder key. This is now possible from Camel 2.7 on using a special placeholder namespace.</p><p>In the example below we use the <strong><code>prop</c ode></strong> prefix for the namespace <code><a shape="rect" class="external-link" href="http://camel.apache.org/schema/placeholder">http://camel.apache.org/schema/placeholder</a></code> by which we can use the <strong><code>prop</code></strong> prefix in the attributes in the XML DSLs. Notice how we use that in the <a shape="rect" href="multicast.html">Multicast</a> to indicate that the option <strong><code>stopOnException</code></strong> should be the value of the placeholder with the key <strong><code>stop</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[<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:prop="http://camel.apache.org/schema/placeholder" - xsi:schemaLocation=" - http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd - http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd - "> + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <!-- Notice in the declaration above, we have defined the prop prefix as the Camel placeholder namespace --> @@ -270,7 +268,6 @@ assertMockEndpointsSatisfied(); </bean> <camelContext xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="classpath:org/apache/camel/component/properties/myprop.properties" xmlns="http://camel.apache.org/schema/spring"/> @@ -303,8 +300,7 @@ assertMockEndpointsSatisfied(); <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" - xsi:schemaLocation=" - http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <!-- OSGI blueprint property placeholder --> <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint"> @@ -328,8 +324,7 @@ assertMockEndpointsSatisfied(); <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" - xsi:schemaLocation=" - http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> + xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> <!-- OSGI blueprint property placeholder --> <cm:property-placeholder id="myblueprint.placeholder" persistent-id="camel.blueprint"> @@ -381,7 +376,7 @@ assertMockEndpointsSatisfied(); </camelContext> ]]></script> -</div></div>Notice that we have a <strong><code><bean></code></strong> which refers to one of the properties. And in the Camel route we refer to the other using the <strong><code>{{ }}</code></strong> notation.<p>Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice that we have a <strong><code><bean></code></strong> which refers to one of the properties. And in the Camel route we refer to the other using the <strong><code>{{ }}</code></strong> notation.</p><p>Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:</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[ @Override protected String useOverridePropertiesWithConfigAdmin(Dictionary props) { @@ -392,7 +387,7 @@ protected String useOverridePropertiesWi return "my-placeholders"; } ]]></script> -</div></div>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.<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</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="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"> <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"/> @@ -412,7 +407,7 @@ protected String useOverridePropertiesWi </camelContext> ]]></script> -</div></div>Now if you want to unit test this blueprint XML file, then you can override the <strong><code>loadConfigAdminConfigurationFile</code></strong> and tell Camel which file to load as shown below:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Now if you want to unit test this blueprint XML file, then you can override the <strong><code>loadConfigAdminConfigurationFile</code></strong> and tell Camel which file to load as shown below:</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[ @Override protected String[] loadConfigAdminConfigurationFile() { @@ -421,7 +416,7 @@ protected String[] loadConfigAdminConfig return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"}; } ]]></script> -</div></div>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>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 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"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[## this is a comment greeting=Bye ]]></script> @@ -463,7 +458,7 @@ greeting=Bye </blueprint> ]]></script> -</div></div>And in the unit test class we do as follows:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>And in the unit test class we do as follows:</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 example will load a Blueprint .cfg file (which will initialize configadmin), and also override its property @@ -508,7 +503,7 @@ public class ConfigAdminLoadConfiguratio } ]]></script> -</div></div>And the <strong><code>etc/stuff.cfg</code></strong> configuration file contains:<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>And the <strong><code>etc/stuff.cfg</code></strong> configuration file contains:</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[greeting=Bye echo=Yay destination=mock:result @@ -523,7 +518,7 @@ destination=mock:result </bean> ]]></script> -</div></div>You <strong>must not</strong> use the spring <strong><code><context:property-placeholder></code></strong> namespace at the same time; this is not possible.<p>After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <strong><code><camelContext></code></strong> tag as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using bridge property placeholders</b></div><div class="codeContent panelContent pdl"> +</div></div> <p>You <strong>must not</strong> use the spring <strong><code><context:property-placeholder></code></strong> namespace at the same time; this is not possible.</p><p>After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <strong><code><camelContext></code></strong> tag as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using bridge property placeholders</b></div><div class="codeContent panelContent pdl"> <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[ <!-- a bean that uses Spring property placeholder --> @@ -542,7 +537,7 @@ destination=mock:result </camelContext> ]]></script> -</div></div>Notice how the hello bean is using pure Spring property placeholders using the <strong><code>${}</code></strong> notation. And in the Camel routes we use the Camel placeholder notation with <strong><code>{{ }}</code></strong>.<h4 id="UsingPropertyPlaceholder-ClashingSpringPropertyPlaceholderswithCamelsLanguage">Clashing Spring Property Placeholders with Camels <a shape="rect" href="simple.html">Simple</a> Language</h4><p>Take notice when using Spring bridging placeholder then the spring <strong><code>${}</code></strong> syntax clashes with the <a shape="rect" href="simple.html">Simple</a> in Camel, and therefore take care.</p><p>Example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div> <p>Notice how the hello bean is using pure Spring property placeholders using the <strong><code>${}</code></strong> notation. And in the Camel routes we use the Camel placeholder notation with <strong><code>{{ }}</code></strong>.</p><h4 id="UsingPropertyPlaceholder-ClashingSpringPropertyPlaceholderswithCamelsLanguage">Clashing Spring Property Placeholders with Camels <a shape="rect" href="simple.html">Simple</a> Language</h4><p>Take notice when using Spring bridging placeholder then the spring <strong><code>${}</code></strong> syntax clashes with the <a shape="rect" href="simple.html">Simple</a> in Camel, and therefore take care.</p><p>Example:</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[<setHeader headerName="Exchange.FILE_NAME"> <simple>{{file.rootdir}}/${in.header.CamelFileName}</simple> </setHeader> @@ -563,7 +558,7 @@ protected Properties useOverrideProperti return extra; } ]]></script> -</div></div>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>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 <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"> <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends RouteBuilder { @PropertyInject("hello") @@ -638,7 +633,8 @@ export $FOO_SERVICE_PORT=8888]]></script public String getName() { return "beer"; } - @Override + + Â @Override public String apply(String remainder) { return "mock:" + remainder.toLowerCase(); }