namalfernandolk namalfernandolk - 8 months ago 88
Apache Configuration Question

Set properties to script groovy component in apache camel

I'm invoking groovy scripts from apache camel. When I'm invoking the groovy script, I'm getting below error saying

No such property: INPUTS for class: Script1
.
How can I overcome this? I tried setProperty(). setHeader but no luck.

from("activemq:queue:test.ChooseIManger")
.script().groovy("resource:classpath:tests/port/test.gsh")


Error :

2017-10-02 13:42:00 DEBUG ScriptBuilder:413 - Script evaluation failed: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: INPUTS for class: Script1
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: INPUTS for class: Script1
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:158)
at org.apache.camel.builder.script.ScriptBuilder.runScript(ScriptBuilder.java:469)
at org.apache.camel.builder.script.ScriptBuilder.doEvaluateScript(ScriptBuilder.java:428)
at org.apache.camel.builder.script.ScriptBuilder.evaluateScript(ScriptBuilder.java:409)
at org.apache.camel.builder.script.ScriptBuilder.evaluate(ScriptBuilder.java:160)
at org.apache.camel.builder.script.ScriptBuilder.evaluate(ScriptBuilder.java:164)
at org.apache.camel.processor.ScriptProcessor.process(ScriptProcessor.java:47)
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:198)
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:197)
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:79)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: INPUTS for class: Script1
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155)
... 16 more
Caused by: groovy.lang.MissingPropertyException: No such property: INPUTS for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
at Script1.run(Script1.groovy:1)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
... 17 more


I tried to setProperties as below but I'm getting the same error

from("activemq:queue:test.ChooseIManger").setProperty("INPUTS",constant("123")).script().groovy("resource:classpath:tests/port/test.gsh");


I know that I can do this as below. But I want to do this with apache camel groovy component.

Binding binding = new Binding();
binding.setProperty("INPUTS", inputs);
binding.setProperty("RESULT", results);

GroovyShell shell = new GroovyShell(binding);
Object script = shell.evaluate(getScript("tests/port/test.gsh"));


test.gsh

def inputVal = INPUTS['param']

RESULT.outputVal = inputVal + 'output';

Answer Source

there are some pre-defined bindings: context, properties, ...

http://camel.apache.org/scripting-languages.html

in your case to access property should be like this (camel 2.9+):

property.resolve("INPUTS")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download