You can make use of the other PropertiesComponent method to pass over an
array of locations upfront:
PropertiesComponent.setLocations(String[] locations)
So given your code example it would become:
PropertiesComponent pc = new PropertiesComponent();
pc.setLocations(new String[] {"classpath:settings.properties",
"classpath:com/mycompany/dynamic.properties"});
context.addComponent("properties", pc);
That said I think a better approach, instead of creating a new properties
file on the fly and passing it over to PropertiesComponent as above, is to
implement your own:
org.apache.camel.component.properties.PropertiesResolver
That's this method signature:
Properties resolveProperties(CamelContext context, boolean
ignoreMissingLocation, String... uri) throws Exception;
For which would just extend the pre-existing implementation:
org.apache.camel.component.properties.DefaultPropertiesResolver
And just override the resolveProperties method of super in that you call
super.resolveProperties() and then add the *dynamic* key/value pairs you
read from the DB to the properties being returned.
And then the resulting code would somehow look like:
PropertiesComponent pc = new PropertiesComponent();
pc.setPropertiesResolver(new MyPropertiesResolver())
pc.setLocation("classpath:settings.properties");
context.addComponent("properties", pc);
And of course the same wiring in Java code above can be achieved using
Spring IoC as well.
Babak
salemi wrote
> Hi Babak,
>
> Thank you for your quick respond. We tried the approach to override a
> property at the run time. It seem like if you set the uri attribute for
> the
> <from>
> element then it become immutable!
>
> In our example we have defined the following elements in the camel context
> file
> <bean id="bridgePropertyPlaceholder"
> class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer" >
>
> <property name="location" value="classpath:settings.properties"/>
> </bean>
>
> <route id="routeTypeName" autoStartup="false" >
>
> <from uri="{{type}}.{{name}}.{{dynamic}}"/>
> In the settings.properties we define:
> type=type
> name=name
>
> When camel comes up we retrieve the value for dynamic from db. Are you
> proposing to create a new file on the fly and add the name and value to
> the file?
>
> PropertiesComponent pc = new PropertiesComponent();
> pc.setLocation("classpath:com/mycompany/dynamic.properties");
> context.addComponent("properties", pc);
>
> My developer tried to overwrite the existing values of a property using
> using a JVM System Property and he told me he can't get it to work.
--
View this message in context:
http://camel.465427.n5.nabble.com/dynamicly-change-the-url-of-the-from-element-after-the-camelcontext-is-started-tp5740599p5740612.html
Sent from the Camel - Users mailing list archive at Nabble.com.