how to use global camel context properties in camel 3.3.0 groovy external script file

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

how to use global camel context properties in camel 3.3.0 groovy external script file

Ronny Aerts-3
Hello camel community,

I’m taking my first steps in migrating from camel 2.25.1 to 3.0.0. Since (nearly) all our camel routes (more then 2000) are written using spring dsl, this migration is a very big job.

Our spring dsl routes regularly use external file scripting for doing some “coding” things. Until now, we used javascript for those scripting requirements. Javascript is not supported anymore in camel3 (and newer java versions) and therefore we will switch to groovy as scripting language.

I have several scripts where I need to access global camel context properties. In javascript, I did a properties.resolve("") call to resolve the properties. The shows that the properties (as org.apache.camel.builder.script.PropertiesFunction) are passed to the external groovy file but I does not seems to work. A display of the groovy properties variables shows something like “{class=class Script_8adfd05454ebe3bbb0f3980896103164, binding=groovy.lang.Binding@62787393}” of type java.util.LinkedHashMap.
Examining the content of the “binding” also proves that there is no “properties” available.

The question I have for the community is how to work with global camel context properties in groovy.

Possible solutions could be:
1. value = camelContext.getPropertiesComponent().resolveProperty("").get(); ⇒ gives a good result
2. value = camelContext.globalOptions.get(""); ⇒ gives a good result
3. value = org.apache.camel.builder.Builder.simple("").evaluate(exchange, java.lang.String.class); ⇒ gives “” as result and is not good
4. value = org.apache.camel.builder.Builder.simple("${}").evaluate(exchange, java.lang.String.class); ⇒ gives a “No such property: tris for class: Script_56c358fac7b1c2c9df318d99c84d4670” error message.
The first option seems to be the best because it also supports default values.
Met vriendelijke groeten / Kind regards / Cordialement / Mit besten Grüßen,

Product Owner Integrations / Integrations Manager
e: mailto:[hidden email]  |  t: +32 (0) 3 326 50 75 / | Empowering and enabling the logistics industry globally.
This email is subject to our

Intris nv   Wapenstilstandlaan 47   B-2600 Berchem

This is an e-mail from Intris. The information contained in this communication is intended solely for use by the individual or entity to whom it is addressed.
Use of this communication by others is prohibited. If the e-mail message was sent to you by mistake, please notify [hidden email]<mailto:[hidden email]>, destroy it without reading, using, copying or disclosing its contents to any other person.
We accept no liability for damage related to data and/or documents which are communicated by electronic mail.