Search code examples
xmlpropertiesapache-camel

Camel - How to use properties set in a file in a route written in xml


i've encountered some trouble using properties in a camel xml route without spring. I'm trying to use the properties in 'to uri' tag and so far i've achieved this result:

<to uri="properties:{{url}}{{delimiter}}throwExceptionOnFailure=false?locations=endpoint.properties"/>

url is the key for something like 'http4://localhost:8080' and delimiter is the key for '?'. I used this workaround to be able to use throwExceptionOnFailure option for the http4 component and avoid a FailedToCreateRouteException. Is there another way to not get the exception? I'm also trying to get another solution using simple and recipientList, but until now i got only errors.

Thank you in advance


Solution

  • You need to ensure that the property placeholder is loaded before you can use it.

    PropertiesComponent props = camelContext.getComponent("properties", PropertiesComponent.class);
    props.setLocation("classpath:yourfile.properties:);
    

    in XML :

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