如何在骆驼路线中使用 xpath 设置 jms 消息自定义 header

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

我正在使用 camel 路由生成器通过设置一些自定义 header 将一个 activemq jms 消息从一个 queue 移动到另一个 header,通过使用 xpath 从 xml 读取节点值.什么都没有设置。知道答案的请指教

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

XML 看起来像

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

XML 带有命名空间需要正确设置命名空间。

您需要使用如下内容设置名称空间处理程序:

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

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