gpt4 book ai didi

regex - 仅当表达式在 apache Camel 选择中起作用时才第一次?

转载 作者:行者123 更新时间:2023-12-01 00:58:21 26 4
gpt4 key购买 nike

我有这条路线,它检查 body 是否以“01”或“02”开头,并根据它调用不同的 bean。问题是只有第一个有效。例如,如果我发送一条以“01”开头的消息
它工作正常,但如果我的消息以“02”开头,则其他部分将被执行,并且我收到带有空正文的错误消息。

<route id="genericService">
<from uri="servlet:///genericService"/>
<choice>
<when>
<simple>${body} regex "^01.*$"</simple>
<bean ref="cardFacade" method="getBalance" />
</when>
<when>
<simple>${body} regex "^02.*$"</simple>
<bean ref="depositFacade" method="getBalance" />
</when>
<otherwise>
<transform>
<simple>error: ${body}</simple>
</transform>
</otherwise>
</choice>
<marshal>
<json />
</marshal>
<transform>
<simple>${body}</simple>
</transform>
</route>

最佳答案

问题是 servlet 组件将主体提供为只能读取一次的流。因此,您需要启用流缓存,或者将消息正文转换为非流类型,例如 String 或 byte[]。

您可以在此处找到更多详细信息

  • http://camel.apache.org/why-is-my-message-body-empty.html

  • 并且还看到此页面上的第一个框
  • http://camel.apache.org/servlet
  • 关于regex - 仅当表达式在 apache Camel 选择中起作用时才第一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25741098/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com