Nomad
Nomad

Reputation: 781

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

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>

Upvotes: 0

Views: 1033

Answers (1)

Petter Nordlander
Petter Nordlander

Reputation: 22279

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

Upvotes: 1

Related Questions