3

In a property file a variable test has been defined:

test=OLD_VALUE

In the following Spring-DSL definition a camel route is defined. Properties are loaded via PropertiesComponent.

  <bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="cache" value="false"/>
    <property name="location" value="classpath:res.properties"/>
  </bean>


  <camelContext id="ctx" xmlns="http://camel.apache.org/schema/spring">
    <route id="toParamRoute">    
      <from uri="servlet:myParam"/>
            HERE I WOULD LIKE TO SET THE 
            VARIABLE TEST WITH A NEW VALUE, 
            SUCH THAT THE FOLLOWING LOG MESSAGE 
            WILL PRINT THE NEW VALUE, 
            E.G: test=NEW_VALUE
      <log message="{{test}}"/>                   
    </route>    
 </camelContext>

I tried different approach using groovy, language script expression, external spring bean but without success. Is there a way to set and change the value of a variable loaded at startup? What is the best way to do it?

Anyone can help me? I did not find any similar question on stackoverflow! The problem I am facing and the solution I am looking for is a basic building-block to build a WEB UI management console to change some behavior of routes on the fly. To simplify the flow I can say that after propertyPlaceholder has loaded a property file then via a UI web page the default parameters of routes can be changed, and only after the route can be started.

E.Ambrosi
  • 31
  • 1
  • 4

1 Answers1

1

Properties evaluated with syntax {{property}} are resolved only once during context initialization. If you need to reflect runtime changes, use Simple language

Example:

<bean id="myProperties" class="java.util.Properties"/>

<bean id="properties" class="org.apache.camel.component.properties.PropertiesComponent">
    <property name="cache" value="false"/>
    <property name="location" value="classpath:res.properties"/>
    <property name="overrideProperties" ref="myProperties" />
</bean>


<camelContext id="ctx" xmlns="http://camel.apache.org/schema/spring">
    <route id="toParamRoute">
        <from uri="timer://foo"/>
        <log message="About to change property test from value ${properties:test} to value ${exchangeProperty.CamelTimerCounter}. Initial value was {{test}}"/>
        <bean ref="myProperties" method="setProperty(test, ${exchangeProperty.CamelTimerCounter})" />
        <log message="New value is ${properties:test}"/>
    </route>
</camelContext>
Bedla
  • 4,789
  • 2
  • 13
  • 27