camel substring operation- n characters from end of message body

雨燕双飞 提交于 2019-12-11 23:16:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!