how to set jms message custom header using xpath in camel route

瘦欲@ 提交于 2019-12-25 11:25:59

问题


I am using camel route builder to move one activemq jms message from one queue to another by setting some custom header, by using xpath to read the node value from xml. nothing has been set. Please suggest if you know the answer.

from("activemq:com.queue1")
    .setHeader("orderNumber").xpath("/orderRequest/authNumber")
                    .to("activemq:com.queue2")
            .end();

XML would look like

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns3:orderRequest xmlns:ns2="http://www.company.com/services/entity/v1" 
                  xmlns:ns3="http://www.company.com/services/dataobject/v1">    
    <authNumber>A81585</authNumber>
</ns3:orderRequest>

回答1:


XML with namespaces requires the name spaces to be setup correctly.

You need to setup a namespace handler with something like this:

Namespaces ns = new Namespaces("ns3", "http://www.company.com/services/dataobject/v1");

....
xpath("/ns3:orderRequest/ns3:authNumber",ns)
...


来源:https://stackoverflow.com/questions/31303891/how-to-set-jms-message-custom-header-using-xpath-in-camel-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!