Oliver Koch
Oliver Koch

Reputation: 103

How to set an empty space as constant in Apache Camel?

I tried to set a String with an empty space as a constant in Camel.

from("timer:test?fixedRate=true&period=5000")
    .setBody().constant(" ")
    .log("'${body}'")
;

It seems not to work, because the above code prints '' as log output.

I'm using Camel Version 2.23.1 and figured out that the method constant in the Class ExpressionClauseSupport needs to set the Attribute trim to true when creating the ConstantExpression. See the creation of the Object and the trimming of the constant String.

In my opinion a constant should not be trimmed or am I wrong?

Upvotes: 0

Views: 684

Answers (1)

TacheDeChoco
TacheDeChoco

Reputation: 3903

May be this ?

ConstantExpression exp = new ConstantExpression(" ");
exp.setTrim(false);

from("timer:test?fixedRate=true&period=5000")
.setBody(exp)
.log("'${body}'");

Upvotes: 3

Related Questions