Modified: websites/production/camel/content/using-propertyplaceholder.html
==============================================================================
--- websites/production/camel/content/using-propertyplaceholder.html (original)
+++ websites/production/camel/content/using-propertyplaceholder.html Fri Aug 25
09:20:43 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Using PropertyPlaceholder
@@ -86,585 +75,305 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2
id="UsingPropertyPlaceholder-UsingPropertyPlaceholder">Using <strong><code>PropertyPlaceholder</code></strong></h2><p><strong>Available
as of Camel 2.3</strong></p><p>Camel now provides a new
<strong><code>PropertiesComponent</code></strong>
in <strong><code>camel-core</code></strong> which allows you to use
property placeholders when defining Camel <a shape="rect"
href="endpoint.html">Endpoint</a> URIs. This works much like you would do if
using Spring's <strong><code><property-placeholder></code></strong> tag.
However Spring has a limitation that prevents third-party frameworks from fully
leveraging Spring property placeholders.</p><p>For more details see: <a
shape="rect"
href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I
use Spring Property Placeholder with Camel XML</a>.</p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Bridging Spring and Camel Proper
ty Placeholders</p><span class="aui-icon aui-icon-small aui-iconfont-approve
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From <strong>Camel 2.10</strong>:
Spring's property placeholder can be bridged with Camel's. See below for more
details.</p></div></div><p>The property placeholder is typically used when
trying to do any of the following:</p><ul class="alternate"><li>Lookup or
creating endpoints.</li><li>Lookup of beans in the <a shape="rect"
href="registry.html">Registry.</a></li><li>Additional supported in Spring XML
(see below in examples).</li><li>Using
Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a
shape="rect" href="properties.html">Properties</a> component.</li><li>Using
<strong><code>@PropertyInject</code></strong> to inject a property in a
POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property
does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box
functions, to lookup property values from OS environment variables, JVM system
properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using
custom functions, which can be plugged into the property
component.</li></ul><h3 id="UsingPropertyPlaceholder-Format">Format</h3><p>The
value of a Camel property can be obtained by specifying its key name within a
property placeholder, using the following format:
<strong>{{<code>key</code>}}</strong>.</p><p>For example:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[{{file.uri}}]]></script>
-</div></div><p>where <strong><code>file.uri</code></strong> is the property
key.</p><p>Property placeholders can be used to specify parts, or all, of an
endpoint's URI by embedding one or more placeholders in the URI's string
definition.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a
default value to use if a property with the key does not exists, e.g.,
<strong><code>file.url:/some/path</code></strong> where the default value is
the text after the colon, e.g.,
<strong><code>/some/path</code></strong>.</p><div
class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From <strong>Camel
2.14.1</strong>: do <em>not</em> use a colon in the property key. The colon
character is used as a token separator when providing a default
value.</p></div></div><h3 id="UsingPropertyPlaceholder-UsingPropertyResolver">Us
ing <code>PropertyResolver</code></h3><p>Camel provides a pluggable
mechanism that allows third-parties to specify their own resolver to use for
the lookup of properties.</p><p>Camel provides a default implementation
<strong><code>org.apache.camel.component.properties.DefaultPropertiesResolver</code></strong>
which is capable of loading properties from the file system, classpath or <a
shape="rect" href="registry.html">Registry</a>. To indicate which source to use
the location must contain the appropriate prefix.</p><p>The list of prefixes
is:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Prefix</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>ref:</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Lookup in the <a shape="rect"
href="registry.html">Registry.</a></p></td></tr><tr><td colspan="1
" rowspan="1" class="confluenceTd"><p><code>file:</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Load the from file
system.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>classpath:</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Load from the classpath (this is also the
default if no prefix is provided).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>blueprint:</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use a specific OSGi blueprint placeholder
service.</p></td></tr></tbody></table></div><h3
id="UsingPropertyPlaceholder-DefiningLocation">Defining Location</h3><p>The
<strong><code>PropertiesResolver</code></strong> must be configured with the
location(s) to use when resolving properties. One or more locations can be
given. Specifying multiple locations can be done a couple of ways: using either
a single comma separated string, or an array of strings.</p><div class="
code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties");
-pc.setLocation(new String[] {"com/mycompany/myprop.properties",
"com/mycompany/other.properties"});Â ]]></script>
-</div></div><div><p>From<strong> Camel 2.19.0</strong>: you can set which
location can be discarded if missing by setting 
<strong><code>optional=true</code></strong>,
(<strong><code>false</code></strong> by
default).</p><p>Example:</p></div><div><p> </p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[pc.setLocations("com/mycompany/override.properties;optional=true,com/mycompany/defaults.properties");]]></script>
-</div></div><p> </p></div><h4
id="UsingPropertyPlaceholder-UsingSystemandEnvironmentVariablesinLocations">Using
System and Environment Variables in Locations</h4><p><strong>Available as of
Camel 2.7</strong></p><p>The location now supports using placeholders for JVM
system properties and OS environments variables.</p><p>Example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[location=file:${karaf.home}/etc/foo.properties
-]]></script>
-</div></div><p>In the location above we defined a location using the file
scheme using the JVM system property with key
<strong><code>karaf.home</code></strong>.</p><p>To use an OS environment
variable instead you would have to prefix with
<strong><code>env</code></strong>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/foo.properties
-]]></script>
-</div></div><p>Where <strong><code>APP_HOME</code></strong> is an OS
environment variable.</p><p>You can have multiple placeholders in the same
location, such as:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[location=file:${env:APP_HOME}/etc/${prop.name}.properties
-]]></script>
-</div></div><h4
id="UsingPropertyPlaceholder-UsingSystemorEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using
System or Environment Variables to Configure Property Prefixes and
Suffixes</h4><p>From<strong> Camel 2.12.5, 2.13.3,
2.14.0</strong>:<strong><code> propertyPrefix</code></strong>,
<strong><code>propertySuffix</code></strong> configuration properties support
the use of placeholders for de-referencing JVM system properties and OS
environments variables.</p><p>Example:</p><p>Assume the
<strong><code>PropertiesComponent</code></strong> is configured with the
following properties file:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: text; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[dev.endpoint = result1
-test.endpoint = result2]]></script>
-</div></div><p>The same properties file is then referenced from a route
definition:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
-pc.setPropertyPrefix("${stage}.");
+<div class="wiki-content maincontent"><h2
id="UsingPropertyPlaceholder-UsingPropertyPlaceholder">Using <strong><code>PropertyPlaceholder</code></strong></h2><p><strong>Available
as of Camel 2.3</strong></p><p>Camel now provides a new
<strong><code>PropertiesComponent</code></strong>
in <strong><code>camel-core</code></strong> which allows you to use
property placeholders when defining Camel <a shape="rect"
href="endpoint.html">Endpoint</a> URIs. This works much like you would do if
using Spring's <strong><code><property-placeholder></code></strong> tag.
However Spring has a limitation that prevents third-party frameworks from fully
leveraging Spring property placeholders.</p><p>For more details see: <a
shape="rect"
href="how-do-i-use-spring-property-placeholder-with-camel-xml.html">How do I
use Spring Property Placeholder with Camel XML</a>.</p><parameter
ac:name="title">Bridging Spring and Camel Property
Placeholders</parameter><rich-text-body><p>From <strong>Camel
2.10</strong>: Spring's property placeholder can be bridged with Camel's. See
below for more details.</p></rich-text-body><p>The property placeholder is
typically used when trying to do any of the following:</p><ul
class="alternate"><li>Lookup or creating endpoints.</li><li>Lookup of beans in
the <a shape="rect" href="registry.html">Registry.</a></li><li>Additional
supported in Spring XML (see below in examples).</li><li>Using
Blueprint <strong><code>PropertyPlaceholder</code></strong> with Camel <a
shape="rect" href="properties.html">Properties</a> component.</li><li>Using
<strong><code>@PropertyInject</code></strong> to inject a property in a
POJO.</li><li><strong>Camel 2.14.1</strong> Using default value if a property
does not exists.</li><li><strong>Camel 2.14.1</strong> Include out of the box
functions, to lookup property values from OS environment variables, JVM system
properties, or the service idiom.</li><li><strong>Camel 2.14.1</strong> Using
custom functions, which ca
n be plugged into the property component.</li></ul><h3
id="UsingPropertyPlaceholder-Format">Format</h3><p>The value of a Camel
property can be obtained by specifying its key name within a property
placeholder, using the following format:
<strong>{{<code>key</code>}}</strong>.</p><p>For
example:</p><plain-text-body>{{file.uri}}</plain-text-body><p>where
<strong><code>file.uri</code></strong> is the property key.</p><p>Property
placeholders can be used to specify parts, or all, of an endpoint's URI by
embedding one or more placeholders in the URI's string
definition.</p><p>From <strong>Camel 2.14.1</strong>: you can specify a
default value to use if a property with the key does not exists, e.g.,
<strong><code>file.url:/some/path</code></strong> where the default value is
the text after the colon, e.g.,
<strong><code>/some/path</code></strong>.</p><rich-text-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></rich-text-body><h3
id="UsingPropertyPlaceholder-UsingPropertyResolver">Using <code>PropertyResolver</code></h3><p>Camel
provides a pluggable mechanism that allows third-parties to specify their own
resolver to use for the lookup of properties.</p><p>Camel provides a default
implementation
<strong><code>org.apache.camel.component.properties.DefaultPropertiesResolver</code></strong>
which is capable of loading properties from the file system, classpath or <a
shape="rect" href="registry.html">Registry</a>. To indicate which source to use
the location must contain the appropriate prefix.</p><p>The list of prefixes
is:</p><div class="table-wrap"><table class="confluenceTable"><tbody><tr><th
colspan="1" rowspan="1" class="confluenceTh"><p>Prefix</p></th><th colspan="1"
rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>ref:</code></p></td><td
colspan="1" rows
pan="1" class="confluenceTd"><p>Lookup in the <a shape="rect"
href="registry.html">Registry.</a></p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>file:</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Load the from file system.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>classpath:</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Load from the classpath (this is also the
default if no prefix is provided).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>blueprint:</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Use a specific OSGi blueprint placeholder
service.</p></td></tr></tbody></table></div><h3
id="UsingPropertyPlaceholder-DefiningLocation">Defining Location</h3><p>The
<strong><code>PropertiesResolver</code></strong> must be configured with the
location(s) to use when resolving properties. One or more locations can be
given. Specifying multip
le locations can be done a couple of ways: using either a single comma
separated string, or an array of strings.</p><parameter
ac:name="language">java</parameter><plain-text-body>pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties");
+pc.setLocation(new String[] {"com/mycompany/myprop.properties",
"com/mycompany/other.properties"}); </plain-text-body><div><p>From<strong>
Camel 2.19.0</strong>: you can set which location can be discarded if missing
by setting  <strong><code>optional=true</code></strong>,
(<strong><code>false</code></strong> by
default).</p><p>Example:</p></div><div><p> </p><parameter
ac:name="language">java</parameter><plain-text-body>pc.setLocations("com/mycompany/override.properties;optional=true,com/mycompany/defaults.properties");</plain-text-body><p> </p></div><h4
id="UsingPropertyPlaceholder-UsingSystemandEnvironmentVariablesinLocations">Using
System and Environment Variables in Locations</h4><p><strong>Available as of
Camel 2.7</strong></p><p>The location now supports using placeholders for JVM
system properties and OS environments
variables.</p><p>Example:</p><plain-text-body>location=file:${karaf.home}/etc/foo.properties
+</plain-text-body><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><plain-text-body>location=file:${env:APP_HOME}/etc/foo.properties
+</plain-text-body><p>Where <strong><code>APP_HOME</code></strong> is an OS
environment variable.</p><p>You can have multiple placeholders in the same
location, such
as:</p><plain-text-body>location=file:${env:APP_HOME}/etc/${prop.name}.properties
+</plain-text-body><h4
id="UsingPropertyPlaceholder-UsingSystemorEnvironmentVariablestoConfigurePropertyPrefixesandSuffixes">Using
System or Environment Variables to Configure Property Prefixes and
Suffixes</h4><p>From<strong> Camel 2.12.5, 2.13.3,
2.14.0</strong>:<strong><code> propertyPrefix</code></strong>,
<strong><code>propertySuffix</code></strong> configuration properties support
the use of placeholders for de-referencing JVM system properties and OS
environments variables.</p><p>Example:</p><p>Assume the
<strong><code>PropertiesComponent</code></strong> is configured with the
following properties file:</p><parameter
ac:name="language">text</parameter><plain-text-body>dev.endpoint = result1
+test.endpoint = result2</plain-text-body><p>The same properties file is then
referenced from a route definition:</p><parameter
ac:name="language">java</parameter><plain-text-body>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>By using the configuration options
<strong><code>propertyPrefix</code></strong> it's possible to change the target
endpoint simply by changing the value of the system
property <strong><code>stage</code></strong> either
to <strong><code>dev</code></strong> (the message will be routed
to <strong><code>mock:result1</code></strong>)
or <strong><code>test</code></strong> (the message will be routed
to <strong><code>mock:result2</code></strong>).</p><h3
id="UsingPropertyPlaceholder-ConfiguringinJavaDSL">Configuring in Java
DSL</h3><p>You have to create and register the
<strong><code>PropertiesComponent</code></strong> under the name
<strong><code>properties</code></strong> such as:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[PropertiesComponent pc = new
PropertiesComponent();
-pc.setLocation("classpath:com/mycompany/myprop.properties");
-context.addComponent("properties", pc);
-]]></script>
-</div></div><h3
id="UsingPropertyPlaceholder-ConfiguringinSpringXML">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"/>
+});</plain-text-body><p>By using the configuration options
<strong><code>propertyPrefix</code></strong> it's possible to change the target
endpoint simply by changing the value of the system
property <strong><code>stage</code></strong> either
to <strong><code>dev</code></strong> (the message will be routed
to <strong><code>mock:result1</code></strong>)
or <strong><code>test</code></strong> (the message will be routed
to <strong><code>mock:result2</code></strong>).</p><h3
id="UsingPropertyPlaceholder-ConfiguringinJavaDSL">Configuring in Java
DSL</h3><p>You have to create and register the
<strong><code>PropertiesComponent</code></strong> under the name
<strong><code>properties</code></strong> such as:</p><parameter
ac:name="language">java</parameter><plain-text-body>PropertiesComponent pc =
new PropertiesComponent();
+pc.setLocation("classpath:com/mycompany/myprop.properties");
+context.addComponent("properties", pc);
+</plain-text-body><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><parameter
ac:name="language">xml</parameter><plain-text-body><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
<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"/>
+</plain-text-body><p>Using the
<strong><code><propertyPlaceholder></code></strong> tag makes the
configuration a bit more fresh such as:</p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext ...>
+ <propertyPlaceholder id="properties"
location="com/mycompany/myprop.properties"/>
</camelContext>
-]]></script>
-</div></div><p><span>Setting the properties location through the location tag
works just fine but sometime you have a number of resources to take into
account and starting from </span><strong>Camel
2.19.0</strong><span> you can set the properties location with a dedicated
<strong><code>propertiesLocation</code></strong>:</span></p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext ...>
- <propertyPlaceholder id="myPropertyPlaceholder">
+</plain-text-body><p><span>Setting the properties location through the
location tag works just fine but sometime you have a number of resources to
take into account and starting from </span><strong>Camel
2.19.0</strong><span> you can set the properties location with a dedicated
<strong><code>propertiesLocation</code></strong>:</span></p><parameter
ac:name="language">xml</parameter><plain-text-body><camelContext ...>
+ <propertyPlaceholder id="myPropertyPlaceholder">
<propertiesLocation
- resolver = "classpath"
- path =
"com/my/company/something/my-properties-1.properties"
- optional = "false"/>
+ resolver = "classpath"
+ path = "com/my/company/something/my-properties-1.properties"
+ optional = "false"/>
<propertiesLocation
- resolver = "classpath"
- path =
"com/my/company/something/my-properties-2.properties"
- optional = "false"/>
+ resolver = "classpath"
+ path = "com/my/company/something/my-properties-2.properties"
+ optional = "false"/>
<propertiesLocation
- resolver = "file"
- path = "${karaf.home}/etc/my-override.properties"
- optional = "true"/>
+ resolver = "file"
+ path = "${karaf.home}/etc/my-override.properties"
+ optional = "true"/>
</propertyPlaceholder>
-</camelContext>]]></script>
-</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 <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
+</camelContext></plain-text-body><parameter ac:name="title">Specifying
the cache option in XML</parameter><rich-text-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></rich-text-body><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><parameter
ac:name="">xml</parameter><plain-text-body><propertyPlaceholder
id="properties" location="ref:myProperties"/>
+</plain-text-body><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><parameter
ac:name="language">java</parameter><plain-text-body>// properties
cool.end=mock:result
// route
-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">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// properties
+from("direct:start")
+ .to("properties:{{cool.end}}");
+</plain-text-body><p>You can also use placeholders as a part of the endpoint
URI:</p><parameter ac:name="language">java</parameter><plain-text-body>//
properties
cool.foo=result
// route
-from("direct:start")
- .to("properties:mock:{{cool.foo}}");
-]]></script>
-</div></div><p>In the example above the to endpoint will be resolved to
<strong><code>mock:result</code></strong>.</p><p>You can also have properties
with refer to each other such as:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// properties
+from("direct:start")
+ .to("properties:mock:{{cool.foo}}");
+</plain-text-body><p>In the example above the to endpoint will be resolved to
<strong><code>mock:result</code></strong>.</p><p>You can also have properties
with refer to each other such as:</p><parameter
ac:name="language">java</parameter><plain-text-body>// properties
cool.foo=result
cool.concat=mock:{{cool.foo}}
// route
-from("direct:start")
- .to("properties:mock:{{cool.concat}}");
-]]></script>
-</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 <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
+from("direct:start")
+ .to("properties:mock:{{cool.concat}}");
+</plain-text-body><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><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:start")
+ .to("properties:bar.end?locations=com/mycompany/bar.properties");
+</plain-text-body><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><parameter
ac:name="language">java</parameter><plain-text-body>// properties
cool.foo=result
// route
-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
+from("direct:start")
+ .to("mock:{{cool.foo}}");
+</plain-text-body><p>And you can use them in multiple wherever you want
them:</p><parameter ac:name="language">java</parameter><plain-text-body>//
properties
cool.start=direct:start
cool.showid=true
cool.result=result
// route
-from("{{cool.start}}")
-
.to("log:{{cool.start}}?showBodyType=false&showExchangeId={{cool.showid}}")
- .to("mock:{{cool.result}}");
-]]></script>
-</div></div><p>You can also your property placeholders when using <a
shape="rect" href="producertemplate.html">ProducerTemplate</a> 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[template.sendBody("{{cool.start}}",
"Hello World");
-]]></script>
-</div></div><h3 id="UsingPropertyPlaceholder-Examplewithlanguage">Example with
<a shape="rect" href="simple.html">Simple</a> language</h3><p>The <a
shape="rect" href="simple.html">Simple</a> language now also support using
property placeholders, for example in the route 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[// properties
+from("{{cool.start}}")
+
.to("log:{{cool.start}}?showBodyType=false&showExchangeId={{cool.showid}}")
+ .to("mock:{{cool.result}}");
+</plain-text-body><p>You can also your property placeholders when using <a
shape="rect" href="producertemplate.html">ProducerTemplate</a> for
example:</p><parameter
ac:name="language">java</parameter><plain-text-body>template.sendBody("{{cool.start}}",
"Hello World");
+</plain-text-body><h3
id="UsingPropertyPlaceholder-Examplewithlanguage">Example with <a shape="rect"
href="simple.html">Simple</a> language</h3><p>The <a shape="rect"
href="simple.html">Simple</a> language now also support using property
placeholders, for example in the route below:</p><parameter
ac:name="language">java</parameter><plain-text-body>// properties
cheese.quote=Camel rocks
// route
-from("direct:start")
- .transform().simple("Hi ${body} do you think
${properties:cheese.quote}?");
-]]></script>
-</div></div><p>You can also specify the location in the <a shape="rect"
href="simple.html">Simple</a> language 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[// bar.properties
+from("direct:start")
+ .transform().simple("Hi ${body} do you think ${properties:cheese.quote}?");
+</plain-text-body><p>You can also specify the location in the <a shape="rect"
href="simple.html">Simple</a> language for example:</p><parameter
ac:name="language">java</parameter><plain-text-body>// bar.properties
bar.quote=Beer tastes good
// route
-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>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"/>
+from("direct:start")
+ .transform().simple("Hi ${body}.
${properties:com/mycompany/bar.properties:bar.quote}.");
+</plain-text-body><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><parameter
ac:name="language">xml</parameter><parameter ac:name="title">Using property
placeholders in the <jmxAgent>
tag</parameter><plain-text-body><camelContext
xmlns="http://camel.apache.org/schema/spring">
+ <propertyPlaceholder id="properties"
location="org/apache/camel/spring/jmx.properties"/>
<!-- we can use propery placeholders when we define the JMX agent -->
- <jmxAgent id="agent" registryPort="{{myjmx.port}}"
disabled="{{myjmx.disabled}}"
- usePlatformMBeanServer="{{myjmx.usePlatform}}"
- createConnector="true"
- statisticsLevel="RoutesOnly"
- useHostIPAddress="true"/>
-
- <route id="foo" autoStartup="false">
- <from uri="seda:start"/>
- <to uri="mock:result"/>
+ <jmxAgent id="agent" registryPort="{{myjmx.port}}"
disabled="{{myjmx.disabled}}"
+ usePlatformMBeanServer="{{myjmx.usePlatform}}"
+ createConnector="true"
+ statisticsLevel="RoutesOnly"
+ useHostIPAddress="true"/>
+
+ <route id="foo" autoStartup="false">
+ <from uri="seda:start"/>
+ <to uri="mock:result"/>
</route>
-</camelContext>]]></script>
-</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"/>
+</camelContext></plain-text-body><p>Example:</p><parameter
ac:name="language">xml</parameter><parameter ac:name="title">Using property
placeholders in the attributes of
<camelContext></parameter><plain-text-body><camelContext
trace="{{foo.trace}}" xmlns="http://camel.apache.org/schema/spring">
+ <propertyPlaceholder id="properties"
location="org/apache/camel/spring/processor/myprop.properties"/>
- <template id="camelTemplate"
defaultEndpoint="{{foo.cool}}"/>
+ <template id="camelTemplate" defaultEndpoint="{{foo.cool}}"/>
<route>
- <from uri="direct:start"/>
- <setHeader headerName="{{foo.header}}">
+ <from uri="direct:start"/>
+ <setHeader headerName="{{foo.header}}">
<simple>${in.body} World!</simple>
</setHeader>
- <to uri="mock:result"/>
+ <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.</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);
+</camelContext></plain-text-body><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><parameter
ac:name="language">java</parameter><plain-text-body>PropertiesComponent pc =
context.getComponent("properties", PropertiesComponent.class);
pc.setCache(false);
-System.setProperty("cool.end", "mock:override");
-System.setProperty("cool.result", "override");
+System.setProperty("cool.end", "mock:override");
+System.setProperty("cool.result", "override");
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
- from("direct:start").to("properties:cool.end");
-
from("direct:foo").to("properties:mock:{{cool.result}}");
+ from("direct:start").to("properties:cool.end");
+ from("direct:foo").to("properties:mock:{{cool.result}}");
}
});
context.start();
-getMockEndpoint("mock:override").expectedMessageCount(2);
+getMockEndpoint("mock:override").expectedMessageCount(2);
-template.sendBody("direct:start", "Hello World");
-template.sendBody("direct:foo", "Hello Foo");
+template.sendBody("direct:start", "Hello World");
+template.sendBody("direct:foo", "Hello Foo");
-System.clearProperty("cool.end");
-System.clearProperty("cool.result");
+System.clearProperty("cool.end");
+System.clearProperty("cool.result");
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
<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">
+</plain-text-body><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><rich-text-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></rich-text-body><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 c
an 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><parameter
ac:name="language">xml</parameter><plain-text-body><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">
<!-- Notice in the declaration above, we have defined the prop prefix
as the Camel placeholder namespace -->
- <bean id="damn"
class="java.lang.IllegalArgumentException">
- <constructor-arg index="0" value="Damn"/>
+ <bean id="damn" class="java.lang.IllegalArgumentException">
+ <constructor-arg index="0" value="Damn"/>
</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"/>
+ <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"/>
<route>
- <from uri="direct:start"/>
+ <from uri="direct:start"/>
<!-- use prop namespace, to define a property placeholder,
which maps to
option stopOnException={{stop}} -->
- <multicast prop:stopOnException="stop">
- <to uri="mock:a"/>
- <throwException ref="damn"/>
- <to uri="mock:b"/>
+ <multicast prop:stopOnException="stop">
+ <to uri="mock:a"/>
+ <throwException ref="damn"/>
+ <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 <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")
+</beans></plain-text-body><p>In our properties file we have the value
defined as</p><plain-text-body>stop=true
+</plain-text-body><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><parameter
ac:name="language">java</parameter><plain-text-body>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"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+ .placeholder("stopOnException", "stop")
+ .to("mock:a")
+ .throwException(new IllegalAccessException("Damn"))
+ .to("mock:b");</plain-text-body><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><parameter
ac:name="language">xml</parameter><plain-text-body><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">
<!-- OSGI blueprint property placeholder -->
- <cm:property-placeholder id="myblueprint.placeholder"
persistent-id="camel.blueprint">
+ <cm:property-placeholder id="myblueprint.placeholder"
persistent-id="camel.blueprint">
<!-- list some properties as needed -->
<cm:default-properties>
- <cm:property name="result"
value="mock:result"/>
+ <cm:property name="result" value="mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- in the route we can use {{ }} placeholders which will lookup
in blueprint
as Camel will auto detect the OSGi blueprint property placeholder
and use it -->
<route>
- <from uri="direct:start"/>
- <to uri="mock:foo"/>
- <to uri="{{result}}"/>
+ <from uri="direct:start"/>
+ <to uri="mock:foo"/>
+ <to uri="{{result}}"/>
</route>
</camelContext>
-</blueprint>]]></script>
-</div></div><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"
- xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+</blueprint></plain-text-body><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><parameter
ac:name="title">About placeholder syntaxes</parameter><rich-text-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></rich-text-body><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><parameter
ac:name="language">xml</parameter><plain-text-body><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">
<!-- OSGI blueprint property placeholder -->
- <cm:property-placeholder id="myblueprint.placeholder"
persistent-id="camel.blueprint">
+ <cm:property-placeholder id="myblueprint.placeholder"
persistent-id="camel.blueprint">
<!-- list some properties as needed -->
<cm:default-properties>
- <cm:property name="prefix.result"
value="mock:result"/>
+ <cm:property name="prefix.result" value="mock:result"/>
</cm:default-properties>
</cm:property-placeholder>
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
<!-- using Camel properties component and refer to the blueprint
property placeholder by its id -->
- <propertyPlaceholder id="properties"
location="blueprint:myblueprint.placeholder"
- prefixToken="[["
suffixToken="]]"
- propertyPrefix="prefix."/>
+ <propertyPlaceholder id="properties"
location="blueprint:myblueprint.placeholder"
+ prefixToken="[[" suffixToken="]]"
+ propertyPrefix="prefix."/>
<!-- in the route we can use {{ }} placeholders which will lookup
in blueprint -->
<route>
- <from uri="direct:start"/>
- <to uri="mock:foo"/>
- <to uri="[[result]]"/>
+ <from uri="direct:start"/>
+ <to uri="mock:foo"/>
+ <to uri="[[result]]"/>
</route>
</camelContext>
-</blueprint>]]></script>
-</div></div><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">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<!-- blueprint property placeholders -->
-<cm:property-placeholder persistent-id="my-placeholders"
update-strategy="reload">
- <cm:default-properties>
- <cm:property name="greeting" value="Hello"/>
- <cm:property name="destination"
value="mock:result"/>
- </cm:default-properties>
-</cm:property-placeholder>
-
-<!-- a bean that uses a blueprint property placeholder -->
-<bean id="myCoolBean"
class="org.apache.camel.test.blueprint.MyCoolBean">
- <property name="say" value="${greeting}"/>
-</bean>
-
-<camelContext xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <bean ref="myCoolBean" method="saySomething"/>
- <to uri="{{destination}}"/>
- </route>
-
-</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">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@Override
-protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
- // add the properties we want to override
- props.put("greeting", "Bye");
-
- // return the PID of the config-admin we are using in the blueprint xml
file
- 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
ServiceMix/Karaf then this container has a convention that it loads the
properties from a file in the etc directory with the naming
<strong><code>etc/pid.cfg</code></strong
>, where <strong><code>pid</code></strong> is the
>persistence-id.</p><p>For example in the blueprint XML file we have the
><strong><code>persistence-id="stuff"</code></strong>, which mean it will load
>the configuration file as
><strong><code>etc/stuff.cfg</code></strong>.</p><div class="code panel pdl"
>style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<!-- blueprint property placeholders, that will use etc/stuff.cfg as the
properties file -->
-<cm:property-placeholder persistent-id="stuff"
update-strategy="reload"/>
-
-<!-- a bean that uses a blueprint property placeholder -->
-<bean id="myCoolBean"
class="org.apache.camel.test.blueprint.MyCoolBean">
- <property name="say" value="${greeting}"/>
-</bean>
-
-<camelContext xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <bean ref="myCoolBean" method="saySomething"/>
- <to uri="mock:result"/>
- </route>
-
-</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">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@Override
-protected String[] loadConfigAdminConfigurationFile() {
- // String[0] = tell Camel the path of the .cfg file to use for OSGi
ConfigAdmin in the blueprint XML file
- // String[1] = tell Camel the persistence-id of the
cm:property-placeholder in the blueprint XML file
- 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 second 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
+</blueprint></plain-text-body><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><plain-text-body>location="blueprint:myblueprint.placeholder,classpath:myproperties.properties"
+</plain-text-body><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:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml}</plain-text-body>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:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/cam
el-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java}</plain-text-body>To
do this we override and implement the
<strong><code>useOverridePropertiesWithConfigAdmin</code></strong> method. We
can then put the properties we want to override on the given props parameter.
And the return value <em>must</em> be the persistence-id of
the <strong><code><cm:property-placeholder></code></strong> tag,
which you define in the blueprint XML file.</p><h4
id="UsingPropertyPlaceholder-Usinga.cfgor.propertiesFileForBlueprintPropertyPlaceholders">Using
a <code>.cfg</code> or <code>.properties</code> File For Blueprint
Property Placeholders</h4><p><strong>Available as of Camel
2.10.4</strong></p><p>When using Blueprint property placeholder in the
Blueprint XML file, you can declare the properties in a .properties
or <strong><code>.cfg</code></strong> file. If you use Apache
ServiceMix/Karaf then this container has
a convention that it loads the properties from a file in the etc directory
with the naming <strong><code>etc/pid.cfg</code></strong>,
where <strong><code>pid</code></strong> is the persistence-id.</p><p>For
example in the blueprint XML file we have the
<strong><code>persistence-id="stuff"</code></strong>, which mean it will load
the configuration file as
<strong><code>etc/stuff.cfg</code></strong>.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml}</plain-text-body>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:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java}</plain-text-body>Notice
that this me
thod requires to return a <strong><code>String[]</code></strong> with 2
values. The 1st value is the path for the configuration file to load. The
second value is the persistence-id of
the <strong><code><cm:property-placeholder></code></strong>
tag.</p><p>The <strong><code>stuff.cfg</code></strong> file is just a
plain properties file with the property placeholders such
as:</p><plain-text-body>## this is a comment
greeting=Bye
-]]></script>
-</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"
-
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
- xsi:schemaLocation="
- http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0
http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd
- http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
-
- <!-- blueprint property placeholders, that will use etc/stuff.cfg as the
properties file -->
- <cm:property-placeholder persistent-id="stuff"
update-strategy="reload">
- <cm:default-properties>
- <cm:property name="greeting" value="Hello" />
- <cm:property name="echo" value="Hey" />
- <cm:property name="destination"
value="mock:original" />
- </cm:default-properties>
- </cm:property-placeholder>
-
- <!-- a bean that uses a blueprint property placeholder -->
- <bean id="myCoolBean"
class="org.apache.camel.test.blueprint.MyCoolBean">
- <property name="say" value="${greeting}"/>
- <property name="echo" value="${echo}"/>
- </bean>
-
- <camelContext
xmlns="http://camel.apache.org/schema/blueprint">
-
- <route>
- <from uri="direct:start"/>
- <bean ref="myCoolBean" method="saySomething"/>
- <to uri="{{destination}}"/>
- <bean ref="myCoolBean" method="echoSomething"/>
- <to uri="{{destination}}"/>
- </route>
-
- </camelContext>
-
-</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">
-<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
- * placeholders from this unit test source code directly (the change will
reload blueprint container).
- */
-public class ConfigAdminLoadConfigurationFileAndOverrideTest extends
CamelBlueprintTestSupport {
-
- @Override
- protected String getBlueprintDescriptor() {
- // which blueprint XML file to use for this test
- return
"org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml";
- }
-
- @Override
- protected String[] loadConfigAdminConfigurationFile() {
- // which .cfg file to use, and the name of the persistence-id
- return new String[]{"src/test/resources/etc/stuff.cfg",
"stuff"};
- }
-
- @Override
- protected String useOverridePropertiesWithConfigAdmin(Dictionary props)
throws Exception {
- // override / add extra properties
- props.put("destination", "mock:extra");
-
- // return the persistence-id to use
- return "stuff";
- }
-
- @Test
- public void testConfigAdmin() throws Exception {
- // mock:original comes from
<cm:default-properties>/<cm:property name="destination"
value="mock:original" />
- getMockEndpoint("mock:original").setExpectedMessageCount(0);
- // mock:result comes from loadConfigAdminConfigurationFile()
- getMockEndpoint("mock:result").setExpectedMessageCount(0);
- // mock:extra comes from useOverridePropertiesWithConfigAdmin()
-
getMockEndpoint("mock:extra").expectedBodiesReceived("Bye
World", "Yay Bye WorldYay Bye World");
-
- template.sendBody("direct:start", "World");
-
- assertMockEndpointsSatisfied();
- }
-
-}
-]]></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">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[greeting=Bye
+</plain-text-body><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:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml}</plain-text-body>And
in the unit test class we do as
follows:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java}</plain-text-body>And
the <strong><code>etc/stuff.cfg</code></strong> configuration file
contains:</p><plain-text-body>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 third-party frameworks
such as Apache Camel to seamless hook into the Spring property placeholder
mechanism. However you can easily bridge Spring and Camel by declaring a Spring
bean with the type
<strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>,
which is a Spring
<strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong>
type.</p><p>To bridge Spring and Camel you must define a single bean as shown
below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>Bridging Spring and Camel property placeholders</b></div><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-
-<!-- bridge spring property placeholder with Camel -->
-<!-- you must NOT use the <context:property-placeholder at the same
time, only this bridge bean -->
-<bean id="bridgePropertyPlaceholder"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
- <property name="location"
value="classpath:org/apache/camel/component/properties/cheese.properties"/>
-</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">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-
-<!-- a bean that uses Spring property placeholder -->
-<!-- the ${hi} is a spring property placeholder -->
-<bean id="hello"
class="org.apache.camel.component.properties.HelloBean">
- <property name="greeting" value="${hi}"/>
-</bean>
-
-<camelContext xmlns="http://camel.apache.org/schema/spring">
- <!-- in this route we use Camels property placeholder {{ }} style -->
- <route>
- <from uri="direct:{{cool.bar}}"/>
- <bean ref="hello"/>
- <to uri="{{cool.end}}"/>
- </route>
-</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">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<setHeader
headerName="Exchange.FILE_NAME">
+</plain-text-body><h3
id="UsingPropertyPlaceholder-BridgingSpringandCamelPropertyPlaceholders">Bridging
Spring and Camel Property Placeholders</h3><p><strong>Available as of Camel
2.10</strong></p><p>The Spring Framework does not allow third-party frameworks
such as Apache Camel to seamless hook into the Spring property placeholder
mechanism. However you can easily bridge Spring and Camel by declaring a Spring
bean with the type
<strong><code>org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer</code></strong>,
which is a Spring
<strong><code>org.springframework.beans.factory.config.PropertyPlaceholderConfigurer</code></strong>
type.</p><p>To bridge Spring and Camel you must define a single bean as shown
below:<plain-text-body>{snippet:id=e1|lang=xml|title=Bridging Spring and Camel
property
placeholders|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.xml}</plain-text-body>You
<st
rong>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:<plain-text-body>{snippet:id=e2|lang=xml|title=Using bridge
property
placeholders|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/component/properties/CamelSpringPropertyPlaceholderConfigurerTest.xml}</plain-text-body>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><parameter
ac:name="language">xml</parameter><plain-text-body><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 <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">
+</plain-text-body><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><parameter
ac:name="language">xml</parameter><plain-text-body><setHeader
headerName="Exchange.FILE_NAME">
<simple>{{file.rootdir}}/$simple{in.header.CamelFileName}</simple>
</setHeader>
-]]></script>
-</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
-protected Properties useOverridePropertiesWithPropertiesComponent() {
- Properties extra = new Properties();
- extra.put("destination", "mock:extra");
- extra.put("greeting", "Bye");
- return extra;
-}
-]]></script>
-</div></div>This can be done from any of the Camel Test kits, such as
<strong><code>camel-test</code></strong>,
<strong><code>camel-test-spring</code></strong> and
<strong><code>camel-test-blueprint</code></strong>.<p>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 cla
ss="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class MyRouteBuilder extends
RouteBuilder {
[... 123 lines stripped ...]