camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r971899 [2/2] - in /websites/production/camel/content: book-component-appendix.html book-in-one-page.html cache/main.pageCache properties.html using-propertyplaceholder.html
Date Mon, 09 Nov 2015 17:21:44 GMT
Modified: websites/production/camel/content/using-propertyplaceholder.html
==============================================================================
--- websites/production/camel/content/using-propertyplaceholder.html (original)
+++ websites/production/camel/content/using-propertyplaceholder.html Mon Nov  9 17:21:44 2015
@@ -210,7 +210,7 @@ from("direct:start")
 
 </camelContext>
 ]]></script>
-</div></div><p>You can also define property placeholders in the various
attributes on the &lt;camelContext&gt; 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>You can also define property placeholders in the various attributes
on the &lt;camelContext&gt; tag such as <code>trace</code> as shown here:<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[
 &lt;camelContext trace=&quot;{{foo.trace}}&quot; xmlns=&quot;http://camel.apache.org/schema/spring&quot;&gt;
     &lt;propertyPlaceholder id=&quot;properties&quot; location=&quot;org/apache/camel/spring/processor/myprop.properties&quot;/&gt;
@@ -289,7 +289,7 @@ assertMockEndpointsSatisfied();
 
 &lt;/beans&gt;
 ]]></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">
+</div></div>In our properties file we have the value defined as<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">
@@ -330,7 +330,7 @@ from(&quot;direct:start&quot;)
 
 &lt;/blueprint&gt;
 ]]></script>
-</div></div><p>By default Camel detects and uses OSGi blueprint property
placeholder service. You can disable this by setting the attribute <code>useBlueprintPropertyResolver</code>
to false on the <code>&lt;camelContext&gt;</code> definition.</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 &lt;camelContext&gt;
you must use the ${ } syntax. Where as inside &lt;camelContext&gt; 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
expl
 icit refer to a specific OSGi blueprint property placeholder by its id. For that you need
to use the Camel's &lt;propertyPlaceholder&gt; as shown in the example below:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader
pdl" style="border-bottom-width: 1px;"><b>Explicit referring to a OSGi blueprint
placeholder in Camel</b></div><div class="codeContent panelContent pdl">
+</div></div>By default Camel detects and uses OSGi blueprint property placeholder
service. You can disable this by setting the attribute <code>useBlueprintPropertyResolver</code>
to false on the <code>&lt;camelContext&gt;</code> definition.<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 &lt;camelContext&gt;
you must use the ${ } syntax. Where as inside &lt;camelContext&gt; 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 re
 fer to a specific OSGi blueprint property placeholder by its id. For that you need to use
the Camel's &lt;propertyPlaceholder&gt; as shown in the example below:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader
pdl" style="border-bottom-width: 1px;"><b>Explicit referring to a OSGi blueprint
placeholder in Camel</b></div><div class="codeContent panelContent pdl">
 <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 &lt;blueprint xmlns=&quot;http://www.osgi.org/xmlns/blueprint/v1.0.0&quot;
            xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
@@ -364,7 +364,7 @@ from(&quot;direct:start&quot;)
 
 &lt;/blueprint&gt;
 ]]></script>
-</div></div><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>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:<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=&quot;blueprint:myblueprint.placeholder,classpath:myproperties.properties&quot;
 ]]></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">
@@ -392,7 +392,7 @@ from(&quot;direct:start&quot;)
 
 &lt;/camelContext&gt;
 ]]></script>
-</div></div><p>Notice that we have a &lt;bean&gt; which refers
to one of the properties. And in the Camel route we refer to the other using the {{ }} notation.</p><p>Now
if you want to override these Blueprint properties from an unit test, you can do this as shown
below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
+</div></div>Notice that we have a &lt;bean&gt; 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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 @Override
 protected String useOverridePropertiesWithConfigAdmin(Dictionary props) {
@@ -403,7 +403,7 @@ protected String useOverridePropertiesWi
     return &quot;my-placeholders&quot;;
 }
 ]]></script>
-</div></div><p>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 &lt;cm:property-placeholder&gt;
tag, which you define in the blueprint XML file.</p><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 the 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 <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 &lt;cm:property-placeholder&gt;
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">
 <script class="brush: xml; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 &lt;!-- blueprint property placeholders, that will use etc/stuff.cfg as the properties
file --&gt;
 &lt;cm:property-placeholder persistent-id=&quot;stuff&quot; update-strategy=&quot;reload&quot;/&gt;
@@ -423,7 +423,7 @@ protected String useOverridePropertiesWi
 
 &lt;/camelContext&gt;
 ]]></script>
-</div></div><p>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:</p><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 <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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
 @Override
 protected String[] loadConfigAdminConfigurationFile() {
@@ -432,7 +432,7 @@ protected String[] loadConfigAdminConfig
     return new String[]{&quot;src/test/resources/etc/stuff.cfg&quot;, &quot;stuff&quot;};
 }
 ]]></script>
-</div></div><p>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 &lt;cm:property-placeholder&gt; tag.</p><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 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 &lt;cm:property-placeholder&gt; 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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[##
this is a comment
 greeting=Bye
 ]]></script>
@@ -472,7 +472,7 @@ greeting=Bye
 
 &lt;/blueprint&gt;
 ]]></script>
-</div></div><p>And in the unit test class we do as follows:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
+</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 .cfdg file, and also override its property placeholders
from this unit test
@@ -513,7 +513,7 @@ public class ConfigAdminLoadConfiguratio
 
 }
 ]]></script>
-</div></div><p>And the <code>etc/stuff.cfg</code> configuration
file contains</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
+</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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[greeting=Bye
 echo=Yay
 destination=mock:result
@@ -528,7 +528,7 @@ destination=mock:result
 &lt;/bean&gt;
 
 ]]></script>
-</div></div><p>You <strong>must not</strong> use the spring
&lt;context:property-placeholder&gt; 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 &lt;camelContext&gt; 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 &lt;context:property-placeholder&gt;
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 &lt;camelContext&gt;
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[
 
 &lt;!-- a bean that uses Spring property placeholder --&gt;
@@ -547,7 +547,7 @@ destination=mock:result
 &lt;/camelContext&gt;
 
 ]]></script>
-</div></div><p>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 {{ }}.</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
${ } 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">
+</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[&lt;setHeader
headerName=&quot;Exchange.FILE_NAME&quot;&gt;
   &lt;simple&gt;{{file.rootdir}}/${in.header.CamelFileName}&lt;/simple&gt;
 &lt;/setHeader&gt;
@@ -568,7 +568,7 @@ protected Properties useOverrideProperti
     return extra;
 }
 ]]></script>
-</div></div><p>This can be done from any of the Camel Test kits, such as
camel-test, camel-test-spring, and camel-test-blueprint.</p><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 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">
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[public
class MyRouteBuilder extends RouteBuilder {
 
     @PropertyInject(&quot;hello&quot;)
@@ -591,7 +591,7 @@ protected Properties useOverrideProperti
 <script class="brush: java; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[
   @PropertyInject(value = &quot;myTimeout&quot;, defaultValue = &quot;5000&quot;)
     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&#160;<a
shape="rect" href="properties.html">Properties</a>&#160;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></ul><p>As
you can see these functions is intended to make it easy to lookup values from the environment.
As they are provided out of the box, they can easily be used as shown below:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent
pdl">
+</div></div><h3 id="UsingPropertyPlaceholder-Usingoutoftheboxfunctions">Using
out of the box functions</h3><p><strong>Available as of Camel 2.14.1</strong></p><p>The&#160;<a
shape="rect" href="properties.html">Properties</a>&#160;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.name
- <strong>Camel 2.16.1:&#160;</strong>A function to lookup the property&#160;from
OS environment variables using the service naming idiom returning the hostname part only</li><li>service.port&#160;-
<strong>Camel 2.16.1:&#160;</strong>A function to lookup the property&#160;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[
 &lt;camelContext xmlns=&quot;http://camel.apache.org/schema/blueprint&quot;&gt;
  
     &lt;route&gt;



Mime
View raw message