rdmueller
rdmueller

Reputation: 11052

<setBody>: how to encode \n?

imagine you would like to use the character sequence \n in a body of a message in apache-camel... I guess the easiest way would look like this:

<setBody>
  <simple>one line\nsecond line</simple>
</setBody>

unfortunately, the \n will be replaced with a line break. And escaping (\\n) seems not to work within the <simple> Tag...

Any idea how to solve this?

PS: I can't use the Java-DSL and also would like to avoid additional dependencies like camel-groovy.

Upvotes: 1

Views: 911

Answers (3)

rdmueller
rdmueller

Reputation: 11052

I found a solution - a velocity template fits my needs.

Upvotes: 0

kasi
kasi

Reputation: 1045

I looked at the camel sources for Simple language. There is protected allowEscape = true, but no interface to set it. Of course you can inherit from it, and create your own Simple language, overriding this field.

From SimpleTokenizer you can see, there is no way how to construct \n string, using current implementation.

Upvotes: 1

J&#233;r&#233;mie B
J&#233;r&#233;mie B

Reputation: 11032

If you want to use a constant body, you can use the constant language, with doesn't need to escape \n :

<setBody>
  <constant>one line\nsecond line</constant>
</setBody>

I am probably wrong, but I don't think it's possible today (v2.16.2) to quote a backslash in the simple language, in order to do what you want. If I look at the sources of org.apache.camel.language.simple.SimpleTokenizer, the \\ is not handled as a special character. There is maybe some workaround, but it should be easy to create an issue // send a PR with this function.

Upvotes: 2

Related Questions