I am trying to set a header parameter (param2), using simple expression language:
from("timer://foo?repeatCount=1")
.setBody(constant("on,off"))
.split()
.tokenize(",")
.setHeader("param1", simple("${body}"))
.setHeader("param2", simple("${header.param1} == 'on'"))
.log("param1 = [${header.param1}], param2 = [${header.param2}]");
But as result I get a string set instead of a boolean value, the following gets logged:
param1 = [on], param2 = [on == 'on']
param1 = [off], param2 = [off == 'on']
I would expect it log:
param1 = [on], param2 = [true]
param1 = [off], param2 = [false]
Documentation writes, that it is possible to do comparison using simple and I can get it working when doing choices:
from("timer://foo?repeatCount=1")
.setBody(constant("on,off"))
.split()
.tokenize(",")
.setHeader("param1", simple("${body}"))
.choice()
.when(simple("${header.param1} == 'on'"))
.setHeader("param2", constant(true))
.otherwise()
.setHeader("param2", constant(false))
.end()
.log("param1 = [${header.param1}], param2 = [${header.param2}]");
The output then is:
param1 = [on], param2 = [true]
param1 = [off], param2 = [false]
But why it is not working then in direct assignment?
This is a bug. I tested with 2.12.3, 2.13.0, 2.12-SNAPSHOT and 2.13-SNAPSHOT and the operators are not handled correctly. Even setting the output type did not help.
By the way, you may also use Groovy to solve your problem:
.setHeader("param2").groovy("request.headers.param1.equals('on')")
EDIT: This bug was fixed in 2.12.4, 2.13.1 and 2.14.0, see CAMEL-7298
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With