...
Code Block | ||
---|---|---|
| ||
pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties"); pc.setLocation(new String[] {"com/mycompany/myprop.properties", "com/mycompany/other.properties"}); |
From Camel 2.19.0: you can set which location can be discarded if missing by setting optional=true
, (false
by default).
Example:
Code Block | ||
---|---|---|
| ||
pc.setLocations("com/mycompany/override.properties;optional=true,com/mycompany/defaults.properties"); |
...
Code Block | ||
---|---|---|
| ||
<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"> <!-- list some properties as needed --> <cm:default-properties> <cm:property name="prefix.result" value="mock:result"/> </cm:default-properties> </cm:property-placeholder> <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."/> <!-- in the route we can use {{ }} placeholders which will lookup in blueprint --> <route> <from uri="direct:start"/> <to uri="mock:foo"/> <to uri="[[result]]"/> </route> </camelContext> </blueprint> |
...
Notice how we use the blueprint
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:
...
When using Blueprint property placeholder in the Blueprint XML file, you can declare the properties directly in the XML file as shown below:
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-outside.xml} |
<bean>
which refers to one of the properties. And in the Camel route we refer to the other using the {{ }}
notation.Now if you want to override these Blueprint properties from an unit test, you can do this as shown below:
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesOutsideCamelContextTest.java} |
useOverridePropertiesWithConfigAdmin
method. We can then put the properties we want to override on the given props parameter. And the return value must be the persistence-id of the <cm:property-placeholder>
tag, which you define in the blueprint XML file.Using a .cfg
or .properties
File
...
For Blueprint Property Placeholders
Available as of Camel 2.10.4
...
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
.
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfile.xml} |
loadConfigAdminConfigurationFile
and tell Camel which file to load as shown below:Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileTest.java} |
String[]
with 2 values. The 1st value is the path for the configuration file to load. The second value is the persistence-id of the <cm:property-placeholder>
tag....
You can do both as well. Here is a complete example. First we have the Blueprint XML file:
Wiki Markup |
---|
{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/configadmin-loadfileoverride.xml} |
Wiki Markup |
---|
{snippet:id=e1|lang=java|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminLoadConfigurationFileAndOverrideTest.java} |
etc/stuff.cfg
configuration file contains:...
To bridge Spring and Camel you must define a single bean as shown below:
Wiki Markup |
---|
{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} |
<context:property-placeholder>
namespace at the same time; this is not possible.After declaring this bean, you can define property placeholders using both the Spring style, and the Camel style within the <camelContext>
tag as shown below:
Wiki Markup |
---|
{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} |
${}
notation. And in the Camel routes we use the Camel placeholder notation with {{ }}
....
So for example in your unit test classes, you can override the useOverridePropertiesWithPropertiesComponent
method and return a java.util.Properties
that contains the properties which should be preferred to be used.
Wiki Markup |
---|
{snippet:id=e1|lang=java|title=Providing properties from within unit test source|url=camel/trunk/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminOverridePropertiesTest.java} |
camel-test
, camel-test-spring
and camel-test-blueprint
....
Code Block | ||
---|---|---|
| ||
<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:start"/> <to uri="{{env:SOMENAME:log:foo}}"/> <to uri="{{sys:MyJvmPropertyName:log:bar}}"/> </route> </camelContext> |
...
The service function is for looking up a service which is defined using OS environment variables using the service naming idiom, to refer to a service location using hostname : port
...
Code Block |
---|
export $FOO_SERVICE_HOST=myserver export $FOO_SERVICE_PORT=8888 |
...
For example if the FOO
service a remote HTTP service, then we can refer to the service in the Camel endpoint URI, and use the HTTP component to make the HTTP call:
Code Block | ||
---|---|---|
| ||
<camelContext xmlns="http://camel.apache.org/schema/blueprint"> <route> <from uri="direct:start"/> <to uri="http://{{service:FOO}}/myapp"/> </route> </camelContext> |
...
And we can use default values if the service has not been defined, for example to call a service on localhost, maybe for unit testing etc:
...