Reputation: 918
i m stuck with xpath filter in camel route, and i don t find solution...
here is my xml message
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:ct="http://com/fr/test">
<env:Header>
<receptionTime xmlns="http://com/fr/test">2016-02-12T14:40:56+0100
</receptionTime>
<correlationId xmlns="http://com/fr/test">944689bc-9605-4292-929a-3b2e8a5eddd7
</correlationId>
<equipmentType xmlns="http://com/fr/test">WCA</equipmentType>
<messageType xmlns="http://com/fr/test">Reservation</messageType>
</env:Header>
<env:Body>
<content xmlns="http://com/fr/test"></content>
</env:Body>
and my route lokk like this :
from("activemq-ext-in:queue:" + queueName)
.id("amq-transfert-downward-route")
.filter().xpath("/env:Envelope/env:Header/equipmentType/text()='WCA'")
//.when(body().contains("WCA"))
.to("activemq-ext-out:topic:" + topicName);
and my message never arrived in my out topic :( if i uncomment the when clause, and comment the filter, my message is correctly send, but i want to use filter
can someone help me how to find the good xpath expression?
possibly i can use .choice().when(xpath...).to(...)?
i just need a correct solution :)
thanks a lot!
Upvotes: 0
Views: 1824
Reputation: 729
Looks like a namespace prefix issue. You're qualifying Envelope with "env:" which is good as long as that prefix is mapped to the right namespace. However, you are missing a suitable qualifier on equipmentTest which is in a different namespace.
See the Camel docs on how to configure a namespaces.
Namespaces ns = new Namespaces("ct", "http://com/fr/test")
.add("env", "http://www.w3.org/2003/05/soap-envelope");
from("activemq-ext-in:queue:" + queueName)
.id("amq-transfert-downward-route")
.filter(
ns.xpath("/env:Envelope/env:Header/ct:equipmentType/text()='WCA'")
).to("activemq-ext-out:topic:" + topicName);
Updated: changed to use the OP example instead of the one from the Camel docs. I haven't tested this but it looks about right.
Upvotes: 1