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
16:19:03 2016
@@ -86,62 +86,66 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="UsingPropertyPlaceholder-UsingPropertyPlaceholder">Using
PropertyPlaceholder</h2><p><strong>Available as of Camel
2.3</strong></p><p>Camel now provides a new <code>PropertiesComponent</code> in
<strong>camel-core</strong> which allows you to use property placeholders when
defining Camel <a shape="rect" href="endpoint.html">Endpoint</a> URIs. <br
clear="none"> This works much like you would do if using Spring's
<code><property-placeholder></code> tag. However Spring have a limitation
which prevents 3rd party frameworks to leverage Spring property placeholders to
the fullest. See more at <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 con
fluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From Camel 2.10 onwards, you can
bridge the Spring property placeholder with Camel, see further 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 PropertyPlaceholder with Camel
<a shape="rect" href="properties.html">Properties</a> component</li><li>using
<code>@PropertyInject</code> 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 f
unctions, 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 {{<code>key</code>}} for example
{{<code>file.uri</code>}} where <code>file.uri</code> is the property key.<br
clear="none"> 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> onwards you can specify a
default value to use if a property with the key does not exists,
eg <code>file.url:/some/path</code> where the default value is the text
after the colon (eg /some/path).</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>Do not use colon in the property
key. The colon is used as a separator toke
n when you are providing a default value, which is supported from
<strong>Camel 2.14.1</strong> onwards.</p></div></div><h3
id="UsingPropertyPlaceholder-PropertyResolver">PropertyResolver</h3><p>Camel
provides a pluggable mechanism which allows 3rd part to provide their own
resolver to lookup properties. Camel provides a default implementation
<code>org.apache.camel.component.properties.DefaultPropertiesResolver</code>
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><code>ref:</code> <strong>Camel
2.4:</strong> to lookup in the <a shape="rect"
href="registry.html">Registry</a></li><li><code>file:</code> to load the from
file system</li><li><code>classpath:</code> to load from classpath (this is
also the default if no prefix is provided)</li><li><code>blueprint:</code>
<strong>Camel 2.7:</strong> to use a specific OSGi blueprint placehold
er service</li></ul><h3
id="UsingPropertyPlaceholder-Defininglocation">Defining location</h3><p>The
<code>PropertiesResolver</code> 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
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">
<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>For example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</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">
<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 <code>karaf.home</code>.</p><p>To
use an OS environment variable instead you would have to prefix with
env:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</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 <code>APP_HOME</code> 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.</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><code>propertyPrefix</code>, <code>propertySuffix</code>
configuration properties support using placeholders for JVM system properties
and OS environments variables.</p><p>For example.
if <code>PropertiesComponent</code> is configured with the following
properties file:</p><div class="preformatted panel" style="border-width:
1px;"><div class="preformattedContent panelContent">
+</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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
pc.setPropertyPrefix("${stage}.");
+
// ...
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
-
from("direct:start").to("properties:mock:{{endpoint}}");
+ from("direct:start")
+ .to("properties:mock:{{endpoint}}");
}
});]]></script>
-</div></div><p>it is possible to change the target endpoint by changing system
property <code>stage</code> either to <code>dev</code> (the message
will be routed to <code>mock:result1</code>) or <code>test</code>
(the message will be routed to <code>mock:result2</code>).</p><h3
id="UsingPropertyPlaceholder-ConfiguringinJavaDSL">Configuring in Java
DSL</h3><p>You have to create and register the <code>PropertiesComponent</code>
under the name <code>properties</code> such as:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</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">
<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">Configuring in Spring
XML</h3><p>Spring XML offers two variations to configure. You can define a
spring bean as a <code>PropertiesComponent</code> which resembles the way done
in Java DSL. Or you can use the <code><propertyPlaceholder></code>
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>
]]></script>
-</div></div><p>Using the <code><propertyPlaceholder></code> tag makes
the configuration a bit more fresh such as:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Using the
<strong><code><propertyPlaceholder></code></strong> tag makes the
configuration a bit more fresh such as:</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="properties"
location="com/mycompany/myprop.properties"/>
</camelContext>
]]></script>
-</div></div><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Specifying the cache option
inside XML</p><span class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Camel 2.10 onwards supports
specifying a value for the cache option both inside the Spring as well as the
Blueprint XML.</p></div></div><h3
id="UsingPropertyPlaceholder-UsingaPropertiesfromthe">Using a Properties from
the <a shape="rect" href="registry.html">Registry</a></h3><p><strong>Available
as of Camel 2.4</strong><br clear="none"> For example in OSGi you may want to
expose a service which returns the properties as a
<code>java.util.Properties</code> object.</p><p>Then you could setup the <a
shape="rect" href="properties.html">Properties</a> component as
follows:</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[ <propertyPlaceholder
id="properties" location="ref:myProperties"/>
+</div></div><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Specifying the cache option
in XML</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>:
Camel supports specifying a value for
the <strong><code>cache</code></strong> option both inside the Spring as
well as the Blueprint XML.</p></div></div><h3
id="UsingPropertyPlaceholder-UsingaPropertiesfromthe">Using a Properties from
the <a shape="rect" href="registry.html">Registry</a></h3><p><strong>Available
as of Camel 2.4</strong><br clear="none"> For example in OSGi you may want to
expose a service which returns the properties as a
<strong><code>java.util.Properties</code></strong> object.</p><p>Then you could
setup the <a shape="rect" href="properties.html">Properties</a> component as
follows:</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[<propertyPlaceholder
id="properties" location="ref:myProperties"/>
]]></script>
-</div></div><p>Where <code>myProperties</code> is the id to use for lookup in
the OSGi registry. Notice we use the <code>ref:</code> prefix to tell Camel
that it should lookup the properties for the <a shape="rect"
href="registry.html">Registry</a>.</p><h3
id="UsingPropertyPlaceholder-Examplesusingpropertiescomponent">Examples using
properties component</h3><p>When using property placeholders in the endpoint
URIs you can either use the <code>properties:</code> component or define the
placeholders directly in the URI. We will show example of both cases, starting
with the former.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>Where <strong><code>myProperties</code></strong> is the id to
use for lookup in the OSGi registry. Notice we use the
<strong><code>ref:</code></strong> prefix to tell Camel that it should lookup
the properties for the <a shape="rect"
href="registry.html">Registry</a>.</p><h3
id="UsingPropertyPlaceholder-ExamplesUsingPropertiesComponent">Examples Using
Properties Component</h3><p>When using property placeholders in the endpoint
URIs you can either use the <strong><code>properties:</code></strong> component
or define the placeholders directly in the URI. We will show example of both
cases, starting with the former.</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.end=mock:result
// route
-from("direct:start").to("properties:{{cool.end}}");
+from("direct:start")
+ .to("properties:{{cool.end}}");
]]></script>
-</div></div><p>You can also use placeholders as a part of the endpoint
uri:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>You can also use placeholders as a part of the endpoint
URI:</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
// route
-from("direct:start").to("properties:mock:{{cool.foo}}");
+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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// properties
@@ -149,17 +153,20 @@ cool.foo=result
cool.concat=mock:{{cool.foo}}
// route
-from("direct:start").to("properties:mock:{{cool.concat}}");
+from("direct:start")
+ .to("properties:mock:{{cool.concat}}");
]]></script>
-</div></div><p>Notice how <code>cool.concat</code> refer to another
property.</p><p>The <code>properties:</code> component also offers you to
override and provide a location in the given uri using the
<code>locations</code> option:</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[
from("direct:start").to("properties:bar.end?locations=com/mycompany/bar.properties");
+</div></div><p>Notice how <strong><code>cool.concat</code></strong> refer to
another property.</p><p>The <strong><code>properties:</code></strong> component
also offers you to override and provide a location in the given URI using the
<strong><code>locations</code></strong> option:</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[from("direct:start")
+ .to("properties:bar.end?locations=com/mycompany/bar.properties");
]]></script>
-</div></div><h3 id="UsingPropertyPlaceholder-Examples">Examples</h3><p>You can
also use property placeholders directly in the endpoint uris without having to
use <code>properties:</code>.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h3 id="UsingPropertyPlaceholder-Examples">Examples</h3><p>You can
also use property placeholders directly in the endpoint URIs without having to
use <strong><code>properties:</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[// properties
cool.foo=result
// route
-from("direct:start").to("mock:{{cool.foo}}");
+from("direct:start")
+ .to("mock:{{cool.foo}}");
]]></script>
</div></div><p>And you can use them in multiple wherever you want
them:</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
@@ -191,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-AdditionalpropertyplaceholdersupportedinSpringXML">Additional
property placeholder supported in Spring XML</h3><p>The property placeholders
is also supported in many of the Camel Spring XML tags such as
<code><package>, <packageScan>, <contextScan>,
<jmxAgent>, <endpoint>, <routeBuilder>, <proxy></code>
and the others.</p><p>The example below has property placeholder in the
<jmxAgent> 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>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">
<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"/>
@@ -206,9 +213,8 @@ from("direct:start")
<from uri="seda:start"/>
<to uri="mock:result"/>
</route>
-
</camelContext>]]></script>
-</div></div><p>You can also define property placeholders in the various
attributes on the <camelContext> tag such as <code>trace</code> as shown
here:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</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">
<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"/>
@@ -222,7 +228,7 @@ from("direct:start")
<to uri="mock:result"/>
</route>
</camelContext>]]></script>
-</div></div><h3
id="UsingPropertyPlaceholder-OverridingapropertysettingusingaJVMSystemProperty">Overriding
a property setting using a JVM System Property</h3><p><strong>Available as of
Camel 2.5</strong><br clear="none"> It is possible to override a property value
at runtime using a JVM System property without the need to restart the
application to pick up the change. This may also be accomplished from the
command line by creating a JVM System property of the same name as the property
it replaces with a new value. An example of this is given below</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><h3
id="UsingPropertyPlaceholder-OverridingaPropertySettingUsingaJVMSystemProperty">Overriding
a Property Setting Using a JVM System Property</h3><p><strong>Available as of
Camel 2.5</strong><br clear="none"> It is possible to override a property value
at runtime using a JVM System property without the need to restart the
application to pick up the change. This may also be accomplished from the
command line by creating a JVM System property of the same name as the property
it replaces with a new value.</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[PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
pc.setCache(false);
@@ -248,7 +254,7 @@ 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>
onwards.</p></div></div><p>Previously it was only the <code>xs:string</code>
type attributes in the XML DSL that support placeholders. For example often a
timeout attribute would be a <code>xs:int</code> type and thus you cannot set a
string value as the placeholder key. This is now possible from Camel 2.7
onwards using a special placeholder namespace.</p><p>In the example below we
use the <code>prop</code> prefix for the namespace <c
ode><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 <code>prop</code> 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
<code>stopOnException</code> should be the value of the placeholder with the
key "stop".</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
<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">
<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"
@@ -279,20 +285,21 @@ assertMockEndpointsSatisfied();
<to uri="mock:b"/>
</multicast>
</route>
-
</camelContext>
-
</beans>]]></script>
</div></div><p>In our properties file we have the value defined 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[stop=true
]]></script>
-</div></div><h3
id="UsingPropertyPlaceholder-UsingpropertyplaceholderintheJavaDSL">Using
property placeholder in the Java DSL</h3><p><strong>Available as of Camel
2.7</strong></p><p>Likewise we have added support for defining placeholders in
the Java DSL using the new <code>placeholder</code> DSL as shown in the
following equivalent 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[ from("direct:start")
- // use a property placeholder for the option
stopOnException on the Multicast EIP
- // which should have the value of {{stop}} key being
looked up in the properties file
- .multicast().placeholder("stopOnException",
"stop")
- .to("mock:a").throwException(new
IllegalAccessException("Damn")).to("mock:b");]]></script>
-</div></div><h3
id="UsingPropertyPlaceholder-UsingBlueprintpropertyplaceholderwithCamelroutes">Using
Blueprint property placeholder with Camel routes</h3><p><strong>Available as
of Camel 2.7</strong></p><p>Camel supports <a shape="rect"
href="using-osgi-blueprint-with-camel.html">Blueprint</a> which also offers a
property placeholder service. Camel supports convention over configuration, so
all you have to do is to define the OSGi Blueprint property placeholder in the
XML file as shown below:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
+</div></div><h3
id="UsingPropertyPlaceholder-UsingPropertyPlaceholderintheJavaDSL">Using
Property Placeholder in the Java DSL</h3><p><strong>Available as of Camel
2.7</strong></p><p>Likewise we have added support for defining placeholders in
the Java DSL using the new <strong><code>placeholder</code></strong> DSL as
shown in the following equivalent 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[from("direct:start")
+ // use a property placeholder for the option stopOnException on the
Multicast EIP
+ // which should have the value of {{stop}} key being looked up in the
properties file
+ .multicast()
+ .placeholder("stopOnException", "stop")
+ .to("mock:a")
+ .throwException(new IllegalAccessException("Damn"))
+ .to("mock:b");]]></script>
+</div></div><h3
id="UsingPropertyPlaceholder-UsingBlueprintPropertyPlaceholderwithCamelRoutes">Using
Blueprint Property Placeholder with Camel Routes</h3><p><strong>Available as
of Camel 2.7</strong></p><p>Camel supports <a shape="rect"
href="using-osgi-blueprint-with-camel.html">Blueprint</a> which also offers a
property placeholder service. Camel supports convention over configuration, so
all you have to do is to define the OSGi Blueprint property placeholder in the
XML file 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[<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"
@@ -317,7 +324,7 @@ assertMockEndpointsSatisfied();
</route>
</camelContext>
</blueprint>]]></script>
-</div></div><p><span style="line-height: 1.42857;"><br
clear="none"></span></p><p><span style="line-height: 1.42857;">By default Camel
detects and uses OSGi blueprint property placeholder service. You can disable
this by setting the attribute </span><code style="line-height:
1.42857;">useBlueprintPropertyResolver</code><span style="line-height:
1.42857;"> to false on the </span><code style="line-height:
1.42857;"><camelContext></code><span style="line-height: 1.42857;">
definition.</span></p><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">About placeholder
syntaxes</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Notice how we can use the Camel
syntax for placeholders {{ }} in the Camel route, which will lookup the value
from OSGi blueprint.<br clear="none"> The blueprint syntax for placeholders is
${ }. So outside the <cam
elContext> you must use the ${ } syntax. Where as inside
<camelContext> you must use {{ }} syntax.<br clear="none"> OSGi blueprint
allows you to configure the syntax, so you can actually align those if you
want.</p></div></div><p>You can also explicit refer to a specific OSGi
blueprint property placeholder by its id. For that you need to use the Camel's
<propertyPlaceholder> as shown in the example below:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p><span style="line-height: 1.42857;"><br
clear="none"></span></p><p><span style="line-height: 1.42857;">By default Camel
detects and uses OSGi blueprint property placeholder service. You can disable
this by setting the attribute </span><strong><code style="line-height:
1.42857;">useBlueprintPropertyResolver</code></strong><span style="line-height:
1.42857;"> to false on the </span><strong><code style="line-height:
1.42857;"><camelContext></code></strong><span style="line-height:
1.42857;"> definition.</span></p><div class="confluence-information-macro
confluence-information-macro-information"><p class="title">About placeholder
syntaxes</p><span class="aui-icon aui-icon-small aui-iconfont-info
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Notice how we can use the Camel
syntax for placeholders <code><strong>{{</strong>
<strong>}}</strong></code> in the Camel route, which will lookup the value from
OSGi blueprint.<
br clear="none"> The blueprint syntax for placeholders is
<strong><code>${}</code></strong>. So outside
the <strong><code><camelContext></code></strong> you must use
the <strong><code>${}</code></strong> syntax. Where as
inside <strong><code><camelContext></code></strong> you must
use <code><strong>{{</strong> <strong>}}</strong></code> syntax. OSGi
blueprint allows you to configure the syntax, so you can actually align those
if you want.</p></div></div><p>You can also explicit refer to a specific OSGi
blueprint property placeholder by its id. For that you need to use the
Camel's <strong><code><propertyPlaceholder></code></strong> as shown
in the example 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[<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"
@@ -346,10 +353,10 @@ assertMockEndpointsSatisfied();
</route>
</camelContext>
</blueprint>]]></script>
-</div></div><p> </p><p>Notice how we use the <code>blueprint</code>
scheme to refer to the OSGi blueprint placeholder by its id. This allows you to
mix and match, for example you can also have additional schemes in the
location. For example to load a file from the classpath you can do:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div><p> </p><p>Notice how we use the
<strong><code>blueprint</code></strong> scheme to refer to the OSGi blueprint
placeholder by its id. This allows you to mix and match, for example you can
also have additional schemes in the location. For example to load a file from
the classpath you can do:</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="blueprint:myblueprint.placeholder,classpath:myproperties.properties"
]]></script>
-</div></div><p>Each location is separated by comma.</p><h4
id="UsingPropertyPlaceholder-OverridingBlueprintpropertyplaceholdersoutsideCamelContext">Overriding
Blueprint property placeholders outside CamelContext</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 directly in the XML file
as shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</div></div><p>Each location is separated by comma.</p><h4
id="UsingPropertyPlaceholder-OverridingBlueprintPropertyPlaceholdersOutsideCamelContext">Overriding
Blueprint Property Placeholders Outside CamelContext</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 directly in the XML file
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[
<!-- blueprint property placeholders -->
<cm:property-placeholder persistent-id="my-placeholders"
update-strategy="reload">
@@ -374,7 +381,7 @@ assertMockEndpointsSatisfied();
</camelContext>
]]></script>
-</div></div>Notice that we have a <bean> which refers to one of the
properties. And in the Camel route we refer to the other using the {{ }}
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>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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
@Override
protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
@@ -385,7 +392,7 @@ protected String useOverridePropertiesWi
return "my-placeholders";
}
]]></script>
-</div></div>To do this we override and implement the
<code>useOverridePropertiesWithConfigAdmin</code> method. We can then put the
properties we want to override on the given props parameter. And the return
value <strong>must</strong> be the persistence-id of the
<cm:property-placeholder> tag, which you define in the blueprint XML
file.<h4
id="UsingPropertyPlaceholder-Using.cfgor.propertiesfileforBlueprintpropertyplaceholders">Using
.cfg or .properties 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 .cfg 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 etc/pid.cfg, where pid is the
persistence-id.</p><p>For example in the blueprint XML file we have the
persistence-id="stuff", which mean it will load th
e configuration file as etc/stuff.cfg.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</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">
<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"/>
@@ -405,7 +412,7 @@ protected String useOverridePropertiesWi
</camelContext>
]]></script>
-</div></div>Now if you want to unit test this blueprint XML file, then you can
override the <code>loadConfigAdminConfigurationFile</code> 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>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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
@Override
protected String[] loadConfigAdminConfigurationFile() {
@@ -414,11 +421,11 @@ protected String[] loadConfigAdminConfig
return new String[]{"src/test/resources/etc/stuff.cfg",
"stuff"};
}
]]></script>
-</div></div>Notice that this method requires to return a String[] with 2
values. The 1st value is the path for the configuration file to load.<br
clear="none"> The 2nd value is the persistence-id of the
<cm:property-placeholder> tag.<p>The stuff.cfg 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>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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[## this is a comment
greeting=Bye
]]></script>
-</div></div><h4
id="UsingPropertyPlaceholder-Using.cfgfileandoverridingpropertiesforBlueprintpropertyplaceholders">Using
.cfg file and overriding properties for Blueprint property
placeholders</h4><p>You can do both as well. Here is a complete example. First
we have the Blueprint XML file:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h4
id="UsingPropertyPlaceholder-Usinga.cfgfileandOverridingPropertiesforBlueprintPropertyPlaceholders">Using
a <code>.cfg</code> file and Overriding Properties for Blueprint Property
Placeholders</h4><p>You can do both as well. Here is a complete example. First
we have the Blueprint XML file:</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 xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -501,12 +508,12 @@ public class ConfigAdminLoadConfiguratio
}
]]></script>
-</div></div>And the <code>etc/stuff.cfg</code> configuration file contains<div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[greeting=Bye
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
<code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code>,
which is a Spring
<code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code>
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 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">
<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
<!-- bridge spring property placeholder with Camel -->
@@ -516,7 +523,7 @@ destination=mock:result
</bean>
]]></script>
-</div></div>You <strong>must not</strong> use the spring
<context:property-placeholder> 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
<camelContext> 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>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">
<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
<!-- a bean that uses Spring property placeholder -->
@@ -535,17 +542,17 @@ destination=mock:result
</camelContext>
]]></script>
-</div></div>Notice how the hello bean is using pure Spring property
placeholders using the ${ } notation. And in the Camel routes we use the Camel
placeholder notation with {{ }}.<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 ${ } syntax clashes with the <a
shape="rect" href="simple.html">Simple</a> in Camel, and therefore take care.
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[<setHeader
headerName="Exchange.FILE_NAME">
+</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">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<setHeader
headerName="Exchange.FILE_NAME">
<simple>{{file.rootdir}}/${in.header.CamelFileName}</simple>
</setHeader>
]]></script>
-</div></div><p>clashes with Spring property placeholders, and you should use
$simple{ } to indicate using the <a shape="rect" href="simple.html">Simple</a>
language in Camel.</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[<setHeader
headerName="Exchange.FILE_NAME">
+</div></div><p>clashes with Spring property placeholders, and you should
use <strong><code>$simple{}</code></strong> to indicate using the <a
shape="rect" href="simple.html">Simple</a> language in Camel.</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}}/$simple{in.header.CamelFileName}</simple>
</setHeader>
]]></script>
-</div></div><p>An alternative is to configure the
<code>PropertyPlaceholderConfigurer</code> with
<code>ignoreUnresolvablePlaceholders</code> option to <code>true</code>.</p><h3
id="UsingPropertyPlaceholder-OverridingpropertiesfromCameltestkit">Overriding
properties from Camel test kit</h3><p><strong>Available as of Camel
2.10</strong></p><p>When <a shape="rect" href="testing.html">Testing</a> with
Camel and using the <a shape="rect" href="properties.html">Properties</a>
component, you may want to be able to provide the properties to be used from
directly within the unit test source code.<br clear="none"> This is now
possible from Camel 2.10 onwards, as the Camel test kits, eg
<code>CamelTestSupport</code> class offers the following methods</p><ul
class="alternate"><li>useOverridePropertiesWithPropertiesComponent</li><li>ignoreMissingLocationWithPropertiesComponent</li></ul><p>So
for example in your unit test classes, you can override the
<code>useOverridePropertiesWithPropertiesCom
ponent</code> method and return a <code>java.util.Properties</code> that
contains the properties which should be preferred to be used.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Providing properties from
within unit test source</b></div><div class="codeContent panelContent pdl">
+</div></div><p>An alternative is to configure the
<strong><code>PropertyPlaceholderConfigurer</code></strong> with
<strong><code>ignoreUnresolvablePlaceholders</code></strong> option to
<strong><code>true</code></strong>.</p><h3
id="UsingPropertyPlaceholder-OverridingPropertiesfromCamelTestKit">Overriding
Properties from Camel Test Kit</h3><p><strong>Available as of Camel
2.10</strong></p><p>When <a shape="rect" href="testing.html">Testing</a> with
Camel and using the <a shape="rect" href="properties.html">Properties</a>
component, you may want to be able to provide the properties to be used from
directly within the unit test source code. This is now possible from Camel
2.10, as the Camel test kits, e.g.,
<strong><code>CamelTestSupport</code></strong> class offers the following
methods</p><ul
class="alternate"><li><strong><code>useOverridePropertiesWithPropertiesComponent</code></strong></li><li><strong><code>ignoreMissingLocationWithPropertiesComponent</code></strong></li></ul><p>S
o for example in your unit test classes, you can override the
<strong><code>useOverridePropertiesWithPropertiesComponent</code></strong>
method and return a <strong><code>java.util.Properties</code></strong> that
contains the properties which should be preferred to be used.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader
panelHeader pdl" style="border-bottom-width: 1px;"><b>Providing properties from
within unit test source</b></div><div class="codeContent panelContent pdl">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
// override this method to provide our custom properties we use in this unit
test
@Override
@@ -556,7 +563,7 @@ protected Properties useOverrideProperti
return extra;
}
]]></script>
-</div></div>This can be done from any of the Camel Test kits, such as
camel-test, camel-test-spring, and camel-test-blueprint.<p>The
<code>ignoreMissingLocationWithPropertiesComponent</code> 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
@PropertyInject</h3><p><strong>Available as of Camel 2.12</strong></p><p>Camel
allows to inject property placeholders in POJOs using the @PropertyInject
annotation which can be set on fields and setter methods.<br clear="none"> For
example you can use that with <code>RouteBuilder</code> classes, such as shown
below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</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">
<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends
RouteBuilder {
@PropertyInject("hello")
@@ -568,89 +575,79 @@ protected Properties useOverrideProperti
.transform().constant(greeting)
.to("{{result}}");
}
-
}
]]></script>
-</div></div><p>Notice we have annotated the greeting field with
@PropertyInject and define it to use the key "hello". Camel will then lookup
the property with this key and inject its value, converted to a String
type.</p><p>You can also use multiple placeholders and text in the key, for
example we can do:</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[ @PropertyInject("Hello {{name}} how
are you?")
- private String greeting;
+</div></div><p>Notice we have annotated the greeting field
with <strong><code>@PropertyInject</code></strong> and define it to use
the key <strong><code>hello</code></strong>. Camel will then lookup the
property with this key and inject its value, converted to a String
type.</p><p>You can also use multiple placeholders and text in the key, for
example we can do:</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[@PropertyInject("Hello {{name}} how are
you?")
+private String greeting;
+]]></script>
+</div></div><p>This will lookup the placeholder with they key
<strong><code>name</code></strong>.</p><p>You can also add a default value if
the key does not exists, 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[@PropertyInject(value =
"myTimeout", defaultValue = "5000")
+private int timeout;
]]></script>
-</div></div><p>This will lookup the placeholder with they key
"name".</p><p>You can also add a default value if the key does not exists, 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[ @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>env - A function to lookup the property
from OS environment variables</li><li>sys - A function to lookup the property
from Java JVM system properties</li><li>service - A function to lookup the
property from OS environment variables using the service naming
idiom</li><li>service.host - <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>service.port -
<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 inte
nded 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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <to uri="{{env:SOMENAME}}"/>
- <to uri="{{sys:MyJvmPropertyName}}"/>
- </route>
- </camelContext>]]></script>
-</div></div><p>You can use default values as well, so if the property does not
exists, you can define a default value as shown below, where the default value
is a log:foo and log:bar value.</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[ <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <to uri="{{env:SOMENAME:log:foo}}"/>
- <to uri="{{sys:MyJvmPropertyName:log:bar}}"/>
- </route>
- </camelContext>]]></script>
-</div></div><p> </p><p>The service function is for looking up a service
which is defined using OS environment variables using the service naming idiom,
to refer to a service location using hostname :
port</p><ul><li><em>NAME</em><strong>_SERVICE_HOST</strong></li><li><em>NAME</em><strong>_SERVICE_PORT</strong></li></ul><p>in
other words the service uses _SERVICE_HOST and _SERVICE_PORT as prefix. So if
the service is named FOO, then the OS environment variables should be set
as</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><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">
+<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://camel.apache.org/schema/blueprint">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="{{env:SOMENAME}}"/>
+ <to uri="{{sys:MyJvmPropertyName}}"/>
+ </route>
+</camelContext>]]></script>
+</div></div><p>You can use default values as well, so if the property does not
exists, you can define a default value as shown below, where the default value
is a <strong><code>log:foo</code></strong>
and <strong><code>log:bar</code></strong> value.</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"/>
+ <to uri="{{env:SOMENAME:log:foo}}"/>
+ <to uri="{{sys:MyJvmPropertyName:log:bar}}"/>
+ </route>
+</camelContext>]]></script>
+</div></div><p> </p><p>The service function is for looking up a service
which is defined using OS environment variables using the service naming idiom,
to refer to a service location using <strong><code>hostname :
port</code></strong></p><ul><li><em><code>NAME</code></em><strong><code>_SERVICE_HOST</code></strong></li><li><em><code>NAME</code></em><strong><code>_SERVICE_PORT</code></strong></li></ul><p>in
other words the service uses <strong><code>_SERVICE_HOST</code></strong>
and <strong><code>_SERVICE_PORT</code></strong> as prefix. So if the
service is named <strong><code>FOO</code></strong>, then the OS environment
variables should be set 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[export $FOO_SERVICE_HOST=myserver
export $FOO_SERVICE_PORT=8888]]></script>
-</div></div><p> </p><p>For example if the FOO service a remote HTTP
service, then we can refer to the service in the Camel endpoint uri, and use
the <a shape="rect" href="http.html">HTTP</a> component to make the
HTTP call:</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[ <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <to uri="http://{{service:FOO}}/myapp"/>
- </route>
- </camelContext>]]></script>
-</div></div><p> </p><p>And we can use default values if the service has
not been defined, for example to call a service on localhost, maybe for unit
testing etc</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[ <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <to uri="http://{{service:FOO:localhost:8080}}/myapp"/>
- </route>
- </camelContext>]]></script>
-</div></div><h3 id="UsingPropertyPlaceholder-Usingcustomfunctions">Using
custom functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The
<a shape="rect" href="properties.html">Properties</a> component allow to plugin
3rd party functions which can be used during parsing of the property
placeholders. These functions are then able to do custom logic to resolve the
placeholders, such as looking up in databases, do custom computations, or
whatnot. The name of the function becomes the prefix used in the placeholder.
This is best illustrated in the example code 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[ <bean id="beerFunction"
class="MyBeerFunction"/>
-
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
- <propertyPlaceholder id="properties"
location="none" ignoreMissingLocation="true">
- <propertiesFunction ref="beerFunction"/>
- </propertyPlaceholder>
-
- <route>
- <from uri="direct:start"/>
- <to uri="{{beer:FOO}}"/>
- <to uri="{{beer:BAR}}"/>
- </route>
- </camelContext>]]></script>
-</div></div><p>Here we have a Camel XML route where we have defined the
<propertyPlaceholder> to use a custom function, which we refer to be the
bean id - eg the beerFunction. As the beer function uses "beer" as its name,
then the placeholder syntax can trigger the beer function by starting with
beer:value.</p><p>The implementation of the function is only two methods 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 static final class MyBeerFunction
implements PropertiesFunction {
-
- @Override
- public String getName() {
- return "beer";
- }
-
- @Override
- public String apply(String remainder) {
- return "mock:" + remainder.toLowerCase();
- }
- }
+</div></div><p> </p><p>For example if
the <strong><code>FOO</code></strong> service a remote HTTP service, then
we can refer to the service in the Camel endpoint URI, and use the <a
shape="rect" href="http.html">HTTP</a> component to make the HTTP
call:</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"/>
+ <to uri="http://{{service:FOO}}/myapp"/>
+ </route>
+</camelContext>]]></script>
+</div></div><p> </p><p>And we can use default values if the service has
not been defined, for example to call a service on localhost, maybe for unit
testing etc:</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"/>
+ <to uri="http://{{service:FOO:localhost:8080}}/myapp"/>
+ </route>
+</camelContext>]]></script>
+</div></div><h3 id="UsingPropertyPlaceholder-UsingCustomFunctions">Using
Custom Functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The
<a shape="rect" href="properties.html">Properties</a> component allow to plugin
3rd party functions which can be used during parsing of the property
placeholders. These functions are then able to do custom logic to resolve the
placeholders, such as looking up in databases, do custom computations, or
whatnot. The name of the function becomes the prefix used in the placeholder.
This is best illustrated in the example code 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[<bean id="beerFunction"
class="MyBeerFunction"/>
-]]></script>
-</div></div><p>The function must implement
the <code>org.apache.camel.component.properties.PropertiesFunction</code>
interface. The method <code>getName</code> is  the name of the
function, eg beer. And the <code>apply</code> method is where we implement
the custom logic to do. As the sample code is from an unit test, it just
returns a value to refer to a mock endpoint.</p><p>To register a custom
function from Java code is 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[ PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
- pc.addFunction(new MyBeerFunction());
+<camelContext xmlns="http://camel.apache.org/schema/blueprint">
+ <propertyPlaceholder id="properties" location="none"
ignoreMissingLocation="true">
+ <propertiesFunction ref="beerFunction"/>
+ </propertyPlaceholder>
+ <route>
+ <from uri="direct:start"/>
+ <to uri="{{beer:FOO}}"/>
+ <to uri="{{beer:BAR}}"/>
+ </route>
+</camelContext>]]></script>
+</div></div><p>Here we have a Camel XML route where we have defined
the <strong><code><propertyPlaceholder></code></strong> to use a
custom function, which we refer to be the bean id - e.g., the
<strong><code>beerFunction</code></strong>. As the beer function
uses <strong><code>beer</code></strong> as its name, then the placeholder
syntax can trigger the beer function by starting with
<strong><code>beer:value</code></strong>.</p><p>The implementation of the
function is only two methods 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 static final class MyBeerFunction
implements PropertiesFunction {
+ @Override
+ public String getName() {
+ return "beer";
+ }
+ @Override
+ public String apply(String remainder) {
+ return "mock:" + remainder.toLowerCase();
+ }
+}]]></script>
+</div></div><p>The function must implement
the <strong><code>org.apache.camel.component.properties.PropertiesFunction</code></strong>
interface. The method <strong><code>getName</code></strong> is  the
name of the function, e.g., <strong><code>beer</code></strong>. And
the <strong><code>apply</code></strong> method is where we implement the
custom logic to do. As the sample code is from an unit test, it just returns a
value to refer to a mock endpoint.</p><p>To register a custom function from
Java code is 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[PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
+pc.addFunction(new MyBeerFunction());
]]></script>
-</div></div><p> </p><h2 id="UsingPropertyPlaceholder-SeeAlso">See
Also</h2><ul class="alternate"><li><a shape="rect"
href="properties.html">Properties</a> component</li></ul></div>
+</div></div><h2 id="UsingPropertyPlaceholder-SeeAlso">See Also</h2><ul
class="alternate"><li><a shape="rect" href="properties.html">Properties</a>
component</li></ul></div>
</td>
<td valign="top">
<div class="navigation">