How to use xpath in camel-context.xml to check if a particular node exists or not
I am trying to develop a content based camel application. This application will look at the src / data folder to see if there is a SOAP request file with node <e2d:getOrderDetaiRequest>
, then this file will be copied to target / message, otherwise the file will be copied to target / other.
Do you know how to use xpath (or any other tools) to check for this 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 an example from two 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</...>
</...></...></...>
source to share
When using xpath and your xml has namespaces like your SOAP message, then you have to use namespaces in the xpath expression too.
The Camel docmentation has some details: http://camel.apache.org/xpath
Using XML DSL in Camel, you can declare namespace in XML tag directly, like camelContext etc.
<camelContext xmlns="http://camel.apache.org/schema/spring" e2d="http://www.abc.com/Abc11WS">
...
<when>
<xpath>/e2d:getOrderDetailRequest</xpath>
...
But remember that XPaths can be a little tricky to work properly. This is why we added logNamespaces in Camel 2.10. See details at the bottom of this page: http://camel.apache.org/xpath
source to share