【问题标题】:How do I Loop over json and post every index in camelcontext如何循环 json 并在 camelcontext 中发布每个索引
【发布时间】:2019-11-01 11:40:15
【问题描述】:

假设我有以下 CamelContext:

<camelContext id="camelId"  xmlns="http://camel.apache.org/schema/spring">
    <route id="upsertItem">
        <from uri="cxf:bean:someEndpoint" />
        <process ref="someTransformer" />
        <log message="$someJson"/>
    </route>
</camelContext>

$someJson 包含以下 json:

{
   "0":{
      "title":"hello world",
      "description":"a greeting to the world"
   },
   "1":{
      "title":"goodbye world",
      "description":"a goodbye to the world"
   }
   //might have more indexes
}

我想编辑我的 CamelContext 以便它可以将每个索引发布到端点。问题是我不知道如何遍历 JSON。

所以我想要一些看起来像这样的东西:

<loop src="${someJson[index]}">
    <to uri="http://bookstore/api/books"/>
</loop>

【问题讨论】:

    标签: java json apache-camel javabeans


    【解决方案1】:

    可以通过拆分原始消息来完成

    <split>
        <jsonpath>$[*]</jsonpath>
        <log message="${body}"/>
    </split>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-08
      • 2020-07-19
      • 1970-01-01
      • 2016-06-06
      相关资源
      最近更新 更多