2

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

heartlex
  • 103
  • 1
  • 13

1 Answers1

0

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>
fg78nc
  • 4,774
  • 3
  • 19
  • 32
  • i tried to use a bean inside the camel config file, but i got an xml error so i changed strategy. i give it another try – heartlex Nov 08 '18 at 13:46
  • my camel config file begins with the tag routes, not beans, and i can't load a bean inside it – heartlex Nov 08 '18 at 13:54
  • `bean` element should be outside of `camelContext` element. Are you using Blueprint XML? – fg78nc Nov 08 '18 at 14:48
  • i started from the exampe camel-example-servlet-tomcat-no-spring where i have a camel-config.xml which contains only routes (the file itself starts with the tag routes). No camel context or blueprint is provided. Changing approach using spring with a camelContext gives me the possibility to use beans (i used a propertyPlaceholder though). I'm only curious to know if another way is possible in the first scenario i mentioned – heartlex Nov 08 '18 at 15:41
  • Add to `beforeStart` method of the `MyLifecycle` class the following lines : `PropertiesComponent props = camelContext.getComponent("properties", PropertiesComponent.class); props.setLocation("classpath:yourfile.properties:);` – fg78nc Nov 08 '18 at 16:06
  • it's not clear in my mind how to access the property file in the camel xml route, inside the to uri tag. I tried different approaches with no luck. thank you for your help – heartlex Nov 09 '18 at 10:05
  • `` is the syntax, where `url` is the property name in your properties file. – fg78nc Nov 09 '18 at 16:45
  • sadly this return an error: FailedToCreateRouteException ... Remove... because of Property with key [example.url] not found in properties from text: http4://{{ex with your ample.url}}. I think this is related to the fact the property file is loaded using the camelContext, but in the camel-config the context isn't used – heartlex Nov 09 '18 at 16:58
  • found the error: i deleted MyLifecyle as context-param because i didn't need it and i forgot to re-set it. now it works as you suggested – heartlex Nov 12 '18 at 11:29