如何在camel-context.xml 中使用xpath 来检查特定节点是否存在 [英] how to use xpath in camel-context.xml to check if a particular node is exist or not

查看:36
本文介绍了如何在camel-context.xml 中使用xpath 来检查特定节点是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个基于内容的路由骆驼应用程序.此应用程序将查看文件夹 src/data 以查看是否存在具有节点 的 SOAP 请求文件,然后将该文件复制到目标/消息中,否则文件将被复制到目标/其他.

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

这是我的骆驼语境

<from uri="file://c:/src/data?noop=true"/><选择><什么时候><xpath>**??????????????????????????????**</xpath><to uri="file://c:/target/message"/></何时><否则><to uri="file://c:/target/other"/></否则></路线>

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

<soapenv:Header/><soapenv:Body><e2d:getOrderDetailRequest><actionCode>1234</actionCode></..></...></...>

<soapenv:Header/><soapenv:Body><lsr:getProductDetailsRequest><productId>12345</...></...></...></...>

解决方案

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

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

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

...<什么时候><xpath>/e2d:getOrderDetailRequest</xpath>...

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

I am trying to develop a content-based routing camel application. This application will look at the folder src/data to see if there is a SOAP request file that has node <e2d:getOrderDetaiRequest>, then that file will be copy into target/message, otherwise the file will be copy to target/other.

Do you know how to use xpath(or any other tools ) to check that condition (i prefer using camel-context.xml file)?

Here is my camel-context

<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>

And here is the sample of 2 different SOAP requests

<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</...>
     </...></...></...>

解决方案

When using xpath and your xml has namespaces, such as your SOAP message, then you must use namespaces in the xpath expression as well.

There is some details at the Camel docmentation at: http://camel.apache.org/xpath

By using the XML DSL in Camel you can declare the namespace in the XML tag directly such as in the camelContext etc.

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

But mind that XPaths can be a bit tricky to get working correctly. And that is why we added the logNamespaces in Camel 2.10. See details in the bottom of the this page: http://camel.apache.org/xpath

这篇关于如何在camel-context.xml 中使用xpath 来检查特定节点是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆