PropertiesPage edited by Claus IbsenProperties ComponentAvailable as of Camel 2.3 URI formatproperties:key[?options] Where key is the key for the property to lookup
Using PropertyPlaceholderAvailable as of Camel 2.3 Camel now provides a new PropertiesComponent in camel-core which allows you to use property placeholders when defining Camel Endpoint URIs. SyntaxThe syntax to use Camel's property placeholder is to use #{key} for example #{file.uri} where file.uri is the property key. PropertyResolverAs usually Camel provides a pluggable mechanism which allows 3rd part to provide their own resolver to lookup properties. Camel provides a default implementation org.apache.camel.component.properties.DefaultPropertiesResolver which is capable of loading properties from the file system or classpath. You can prefix the locations with either file: or classpath: where classpath: is the default if no prefix is provided. Defining locationThe PropertiesResolver need to know a location(s) where to resolve the properties. You can define 1 to many locations. If you define the location in a single String property you can separate multiple locations with comma such as:
pc.setLocation("com/mycompany/myprop.properties,com/mycompany/other.properties");
Configuring in Java DSLYou have to create and register the PropertiesComponent under the name properties such as: PropertiesComponent pc = new PropertiesComponent(); pc.setLocation("classpath:com/mycompany/myprop.properties"); context.addComponent("properties", pc); Configuring in Spring XMLSpring XML offers two variations to configure. You can define a spring bean as a PropertiesComponent which resembles the way done in Java DSL. Or you can use the <propertyPlaceholder> tag. <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent"> <property name="location" value="classpath:com/mycompany/myprop.properties"/> </bean> Using the <propertyPlaceholder> tag makes the configuration a bit more fresh such as: <camelContext ...> <propertyPlaceholder id="properties" location="com/mycompany/myprop.properties"/> </camelContext> Examples using properties componentWhen using property placeholders in the endpoint URIs you can either use the properties: component or define the placeholders directly in the URI. We will show example of both cases, starting with the former. // properties cool.end=mock:result // route from("direct:start").to("properties:#{cool.end}"); You can also use placeholders as a part of the endpoint uri: // properties cool.foo=result // route from("direct:start").to("properties:mock:#{cool.foo}"); In the example above the to endpoint will be resolved to mock:result. You can also have properties with refer to each other such as: // properties cool.foo=result cool.concat=mock:#{cool.foo} // route from("direct:start").to("properties:mock:#{cool.concat}"); Notice how cool.concat refer to another property. The properties: component also offers you to override and provide a location in the given uri using the locations option: from("direct:start").to("properties:#{bar.end}?locations=com/mycompany/bar.properties"); ExamplesYou can also use property placeholders directly in the endpoint uris without having to use properties:. // properties cool.foo=result // route from("direct:start").to("mock:#{cool.foo}"); And you can use them in multiple wherever you want them: // 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}"); You can also your property placeholders when using ProducerTemplate for example: template.sendBody("#{cool.start}", "Hello World"); Example with Simple languageThe Simple language now also support using property placeholders, for example in the route below: // properties cheese.quote=Camel rocks // route from("direct:start") .transform().simple("Hi ${body} do you think ${properties:cheese.quote}?"); You can also specify the location in the Simple language for example: // bar.properties bar.quote=Beer tastes good // route from("direct:start") .transform().simple("Hi ${body}. ${properties:com/mycompany/bar.properties:bar.quote}."); Unit testsSee the unit tests in camel-core and camel-spring
See Also
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > Properties confluence
- [CONF] Apache Camel > Properties confluence
- [CONF] Apache Camel > Properties confluence
- [CONF] Apache Camel > Properties confluence
- [CONF] Apache Camel > Properties confluence