2

I'm implementing a content based router in camel using XPath. But for some reason the XPath expression doesn't evaluate the content and always the otherwise path is chosen. This is the route I defined in my camel-context:

<route>
        <from uri="cxf:bean:hioServiceEndPoint"/>
        <process ref="hioProcessor"/>
        <inOnly uri="file:{{path.ws.data}}/incoming/hio?fileName=hio_${date:now:yyyyMMdd_HHmmssSS}.xml"/>
        <choice>
            <when>
                <xpath>//ORDER_TYPE = 'CROSSDOCKING'</xpath>
                <log message="NIELS Incoming CROSS HIO !!!"/>
                <to uri="jms:incomingHioCross"/>
            </when>
            <otherwise>
                <to uri="jms:incomingHio"/>
                <log message="NIELS Incoming HIO"/>
            </otherwise>
        </choice>
        <transform>
            <constant>OK</constant>
        </transform>
</route>

And this is the XML which needs to be searched for the tag ORDER_TYPE:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<INBOUND_ORDER xmlns="urn:ifsworld-com:schemas:handle_inbound_order">
    <DELIVERY_LEADTIME>0.0</DELIVERY_LEADTIME>
    <DELNOTE_DATE>2010-12-15T00:00:00</DELNOTE_DATE>
    <DELNOTE_NO>1454</DELNOTE_NO>
    <DESPATCH_DATE>2010-12-15T16:39:43</DESPATCH_DATE>
    <ORDER_DATE>2010-12-15T16:39:43</ORDER_DATE>
    <ORDER_NO>1454</ORDER_NO>
    <ORDER_TYPE>CROSSDOCKING</ORDER_TYPE>
    <REMARKS xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <SITE>DC2</SITE>
    <VENDOR_NO>ALM</VENDOR_NO>
    <INBOUND_ORDER_LINES>
        <INBOUND_ORDER_LINE>
            <CURRENCY_CODE>EUR</CURRENCY_CODE>
            <PART_NO>1276.1</PART_NO>
            <QUANTITY>2.0</QUANTITY>
            <QUANTITY_UNIT_MEAS>PCS</QUANTITY_UNIT_MEAS>
            <REMARKS xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
            <SEQUENCE_NO>1.0</SEQUENCE_NO>
            <UNIT_PRICE>0.0</UNIT_PRICE>
        </INBOUND_ORDER_LINE>
    </INBOUND_ORDER_LINES>
</INBOUND_ORDER>

I can't see what I'm doing wrong, I also tried /INBOUND_ORDER/ORDER_TYPE = 'CROSSDOCKING' but even then I can seem to get It working. I wrote a test case to see if my XPath expression is correct and that works fine and returns true.

I'm using camel 2.5.0.

So if anybody has a tip, I would appreciate it.

Sicco
  • 6,167
  • 5
  • 45
  • 61
Niels
  • 599
  • 5
  • 28
  • 1
    This is the most FAQ in XPath. Just search for "XPath and default namespace" and you will find tons of good explanations and solutions to the problem. In a nutshell, you need to "register a namespace" and use its prefix (say `"x"`) so that your expression will become: `//x:ORDER_TYPE = 'CROSSDOCKING'` – Dimitre Novatchev Sep 05 '12 at 12:16
  • 1
    Yeah XPath and namespaces is a common problem to get working together. You can also maybe just search the XML as a String for the content of CROSSDOCKING, as a kind of test. For example with the Camel Simple language: ${body} contains 'CROSSDOCKING' – Claus Ibsen Sep 05 '12 at 13:28

1 Answers1

1

I'm a little bit confused by your namespace xmlns="urn:ifsworld-com:schemas:handle_inbound_order". Is it a valid namespace?

Anyway, I think this should work:

//*[local-name() = 'ORDER_TYPE'][codepoint-equal(text(), 'CROSSDOCKING')]
Sicco
  • 6,167
  • 5
  • 45
  • 61