如何在camel-context.xml中使用xpath来检查特定节点是否存在

2024-02-02

我正在尝试开发一个基于内容的路由骆驼应用程序。该应用程序将查看文件夹 src/data 以查看是否存在包含节点的 SOAP 请求文件<e2d:getOrderDetaiRequest>,那么该文件将被复制到目标/消息,否则该文件将被复制到目标/其他。

您知道如何使用 xpath(或任何其他工具)来检查该条件(我更喜欢使用camel-context.xml 文件)?

这是我的骆驼上下文

<route>
        <from uri="file://c:/src/data?noop=true"/>
        <choice>
           <when>
            <xpath>**???????????????????????????**</xpath>
                <to uri="file://c:/target/message"/>
           </when>
           <otherwise>
            <to uri="file://c:/target/other"/>
           </otherwise>
        </choice>
    </route>

这是 2 个不同 SOAP 请求的示例

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:e2d="http://www.abc.com/Abc11WS">
   <soapenv:Header/>
   <soapenv:Body>
      <e2d:getOrderDetailRequest>
         <actionCode>1234</actionCode>
      </..>
   </...></...>

And

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lsr="http://www.abc.com/Abc22WS">
   <soapenv:Header/>
   <soapenv:Body>
      <lsr:getProductDetailsRequest>
           <productId>12345</...>
     </...></...></...>

当使用 xpath 并且您的 xml 具有命名空间(例如 SOAP 消息)时,您也必须在 xpath 表达式中使用命名空间。

Camel 文档中有一些详细信息:http://camel.apache.org/xpath http://camel.apache.org/xpath

通过在 Camel 中使用 XML DSL,您可以直接在 XML 标签中声明名称空间,例如在camelContext 等中。

<camelContext xmlns="http://camel.apache.org/schema/spring" e2d="http://www.abc.com/Abc11WS">
   ...
   <when>
     <xpath>/e2d:getOrderDetailRequest</xpath>
       ...

但请注意,XPath 正常工作可能有点棘手。这就是我们在 Camel 2.10 中添加 logNamespaces 的原因。请参阅本页底部的详细信息:http://camel.apache.org/xpath http://camel.apache.org/xpath

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在camel-context.xml中使用xpath来检查特定节点是否存在 的相关文章

随机推荐