问题
This will probably be a layup for most of you, so I apologize in advance. I am using Apache camel with spring DSL. My message body has been converted to a string. I want everything from the 9th to 998th character, preferably using a simple expression. I have tried
<transform>
<simple>${body.substring(8,${body.length}-1)}</simple>
</transform>
but Camel doesn't recognize the subtraction. As such, it will try to convert the string "1045-2"
to an integer, and obviously fail. Is there a workaround here?
回答1:
Use groovy, javascript etc which is more powerful dynamic programming language
<groovy>request.body.substring(8, request.body.length-1)</groovy>
You need to add camel-groovy as a dependency together with groovy also.
- Camel Groovy documentation
回答2:
The following code snippet will work.
<transform>
<simple>${body.substring(8,${body.length()-1})}</simple>
</transform>
来源:https://stackoverflow.com/questions/29636600/camel-substring-operation-n-characters-from-end-of-message-body