json - 使用 json 进行 Camel 选择

标签 json xpath apache-camel fuseesb

我已经编写了 Camel 选择,路线的输入是xml。如下图所示: 我想用 json 作为输入来编写选择,那么如何评估 json 以路由到下一个组件。请指导我。 JSON 是:

{
  "service": { "serviceType": "OtherServcie" }
}

<choice>
 <when>
  <xpath>/service/serviceType='PaymentServcie'</xpath>
  <log message="In PaymentServcie"/>
 </when>
 <otherwise>
  <log message="In OtherServcie"/>
 </otherwise>
</choice>

最佳答案

也许为时已晚,但答案是使用 camel-jsonpath .

<route>
  <from uri="direct:start"/>
  <choice>
    <when>
      <jsonpath>$.service[?(@.serviceType=='PaymentService')]</jsonpath>
      <log message="In PaymentServcie"/>
    </when>
    <otherwise>
      <log message="In OtherServcie"/>
    </otherwise>
  </choice>

不要忘记 Maven 依赖项:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jsonpath</artifactId>
    <version>${camel.version}</version>
</dependency>

关于json - 使用 json 进行 Camel 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18824515/

相关文章:

java - 当 Camel 从 XML 文件加载路由时,在注册表中找不到 Bean

java - 与Camel并行处理大型SQL表

Javascript 过滤器非数组 JSON 对象

xslt - Symphony CMS中奇怪的XSL输出

java - 使用 JPA 持久化实体时面临的问题

python - selenium可以在outlook online中find_element_by_xpath吗?

xml - 为什么简单的 XPATH 不起作用

asp.net-mvc - 从 Controller 传递 json 到 View

ios - 使用 Alamofire 和 EVReflection 的 JSON POST 请求

python - 不能从 python 漂亮地打印 json