0
votes

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
Can you post the XML you're trying to traverse? - Brent D
It is a big xml, SO I couldn't share, but lets try for first element under root node. like <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns3:orderRequest xmlns:ns2="company.com/services/entity/v1" xmlns:ns3="company.com/services/dataobject/…> - Dkr
You need to setup the namespace for the xpath, see more at camel.apache.org/xpath - Claus Ibsen
How to access that JMS message header property value.? - Dkr
You may want to tell xpath which type you want to use for the order number, should it be String or Integer etc .setHeader("orderNumber").xpath("/orderRequest/authNumber", String.class) - Claus Ibsen

1 Answers

1
votes

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