You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Illtud Daniel <il...@llgc.org.uk> on 2010/09/18 03:38:17 UTC

$headername = 'value still works?

Hi,

I'm using camel as distributed with apachemq, sorry if this turns
out to be an activemq problem.

activemq 5.3.2 shipped with camel 2.0 (as far as I can tell)
activemq 5.4 uses 2.4.0

A route that used to work for me in 2.0 doesn't any more:

<route autoStartup="true" inheritErrorHandler="true" id="SCIFglue5" 
xmlns:ns2="http://camel.apache.org/schema/web" 
xmlns="http://camel.apache.org/schema/spring">
     <from uri="activemq:test_in"/>
     <choice inheritErrorHandler="true" id="choice2">
         <when inheritErrorHandler="true">
             <header>$foo = 'true'</header>
             <to uri="activemq:test_out_true" inheritErrorHandler="true" 
id="to6"/>
         </when>
         <otherwise inheritErrorHandler="true">
             <to uri="activemq:test_out_other" 
inheritErrorHandler="true" id="to7"/>
         </otherwise>
     </choice>
</route>

[this was created in the console]

It picks up from test_in, but I get this error in the activemq log:

2010-09-18 01:59:36,205 | ERROR | Failed delivery for exchangeId: 
ID:vaio-51221-1284757417176-5:22:-1:1:1. Exhausted after delivery 
attempt: 1 caught: org.apache.camel.builder.xml.InvalidXPathExpression: 
Invalid xpath: $foo = 'true'.


I know that "$foo = 'true'" isn't valid xpath, but isn't it camel's
way of matching message headers? It worked in the version shipping
with 5.3.x and I'm following the docs here:
http://camel.apache.org/content-based-router.html
http://camel.apache.org/xpath.html

-- 
Illtud Daniel                                 illtud.daniel@llgc.org.uk
Prif Swyddog Technegol                          Chief Technical Officer
Llyfrgell Genedlaethol Cymru                  National Library of Wales

Re: $headername = 'value still works?

Posted by Illtud Daniel <il...@llgc.org.uk>.
Thanks Claus, you've been very helpful

Claus Ibsen wrote:
> On Sun, Sep 19, 2010 at 5:59 PM, Illtud Daniel
> <il...@llgc.org.uk> wrote:

>> Since the Content-Based Router EIP documents using <xpath>
>> for content-based routing swiching on header values, does
>> this mean you can only do this if the content is XML? Seems
>> odd to me to tie one thing (routing on header values) to
>> another unrelated property (XMLness of message). What if
>> you want to switch based on headers but are sending JSON or
>> text?
> 
> Yeah xpath works on the entire message expecting it to be in XML. You
> know the world of XML used to be like "conquer the world".
> So XML is up till your both ears.

I have no beef with XML, I find it very useful. But I
do think the documentation could do with an update. Maybe
put in an example of using <simple> to switch on a header
value if your message isn't XML. Ideally, the <xpath>
operator shouldn't be overloaded with the non-xpath
$header = 'value'. In my opinion it's confusing.

>> Looking at the documentation for simple, I've tried:

>>            <simple>${in.header.foo}=='yes'</simple>

>> But that *always* routes to test_out_true, regardless of the value
>> of the foo header.
> 
> You need spaces around the operators
>           <simple>${in.header.foo} == 'yes'</simple>

If only everything in life was that easy to fix. Thanks Claus, I'll
try that today when I get a chance.

-- 
Illtud Daniel                                 illtud.daniel@llgc.org.uk
Prif Swyddog Technegol                          Chief Technical Officer
Llyfrgell Genedlaethol Cymru                  National Library of Wales

Re: $headername = 'value still works?

Posted by Illtud Daniel <il...@llgc.org.uk>.
On 20/09/10 08:41, Claus Ibsen wrote:

>>             <simple>${in.header.foo}=='yes'</simple>

> You need spaces around the operators
>            <simple>${in.header.foo} == 'yes'</simple>

Thanks, I've checked that and you're quite right. It works
fine with the correct syntax.

-- 
Illtud Daniel                                 illtud.daniel@llgc.org.uk
Prif Swyddog Technegol                          Chief Technical Officer
Llyfrgell Genedlaethol Cymru                  National Library of Wales

Re: $headername = 'value still works?

Posted by Claus Ibsen <cl...@gmail.com>.
On Sun, Sep 19, 2010 at 5:59 PM, Illtud Daniel
<il...@llgc.org.uk> wrote:
> On 19/09/10 07:40, Claus Ibsen wrote:
>
>> And could you double check that there is no old versions of camel in
>> the classpath?
>> And the data you send is valid XML
>
> Ah. That's the problem. Since I wasn't using xpath to actually
> search any xml, I had a test message with no valid xml content.
> If I switch the content for xml, then it works as expected.
>
> Since the Content-Based Router EIP documents using <xpath>
> for content-based routing swiching on header values, does
> this mean you can only do this if the content is XML? Seems
> odd to me to tie one thing (routing on header values) to
> another unrelated property (XMLness of message). What if
> you want to switch based on headers but are sending JSON or
> text?

Yeah xpath works on the entire message expecting it to be in XML. You
know the world of XML used to be like "conquer the world".
So XML is up till your both ears.


>
> It does seem odd to me to overload the <xpath> operator
> with non-valid xpath to match on a header value anyway,
> to be honest.
>
> Somebody else suggested using:
> <simple>$header.foo=='value'</simple>
>
> Looking at the documentation for simple, I've tried:
>
>    <from uri="activemq:test_in"/>
>    <choice inheritErrorHandler="true" id="choice1">
>        <when inheritErrorHandler="true">
>            <simple>${in.header.foo}=='yes'</simple>
>            <to uri="activemq:test_out_true" inheritErrorHandler="true"
> id="to1"/>
>        </when>
>        <otherwise inheritErrorHandler="true">
>            <to uri="activemq:test_out_other" inheritErrorHandler="true"
> id="to2"/>
>        </otherwise>
>    </choice>
>
> But that *always* routes to test_out_true, regardless of the value
> of the foo header.

You need spaces around the operators
          <simple>${in.header.foo} == 'yes'</simple>




>
> I'm using stomp, BTW, to create the message in the first place, which
> may have a bearing on the problem. I can see the message properties
> (headers) in the activemq console, but I can't tell what type they
> are.
> .
>
> --
> Illtud Daniel                                 illtud.daniel@llgc.org.uk
> Prif Swyddog Technegol                          Chief Technical Officer
> Llyfrgell Genedlaethol Cymru                  National Library of Wales
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: $headername = 'value still works?

Posted by Illtud Daniel <il...@llgc.org.uk>.
On 19/09/10 07:40, Claus Ibsen wrote:

> And could you double check that there is no old versions of camel in
> the classpath?
> And the data you send is valid XML

Ah. That's the problem. Since I wasn't using xpath to actually
search any xml, I had a test message with no valid xml content.
If I switch the content for xml, then it works as expected.

Since the Content-Based Router EIP documents using <xpath>
for content-based routing swiching on header values, does
this mean you can only do this if the content is XML? Seems
odd to me to tie one thing (routing on header values) to
another unrelated property (XMLness of message). What if
you want to switch based on headers but are sending JSON or
text?

It does seem odd to me to overload the <xpath> operator
with non-valid xpath to match on a header value anyway,
to be honest.

Somebody else suggested using:
<simple>$header.foo=='value'</simple>

Looking at the documentation for simple, I've tried:

     <from uri="activemq:test_in"/>
     <choice inheritErrorHandler="true" id="choice1">
         <when inheritErrorHandler="true">
             <simple>${in.header.foo}=='yes'</simple>
             <to uri="activemq:test_out_true" inheritErrorHandler="true" 
id="to1"/>
         </when>
         <otherwise inheritErrorHandler="true">
             <to uri="activemq:test_out_other" 
inheritErrorHandler="true" id="to2"/>
         </otherwise>
     </choice>

But that *always* routes to test_out_true, regardless of the value
of the foo header.

I'm using stomp, BTW, to create the message in the first place, which
may have a bearing on the problem. I can see the message properties
(headers) in the activemq console, but I can't tell what type they
are.
.

-- 
Illtud Daniel                                 illtud.daniel@llgc.org.uk
Prif Swyddog Technegol                          Chief Technical Officer
Llyfrgell Genedlaethol Cymru                  National Library of Wales

Re: $headername = 'value still works?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

A bit odd. I added unit tests to camel-jms which works
http://svn.apache.org/viewvc?rev=998598&view=rev

And could you double check that there is no old versions of camel in
the classpath?
And the data you send is valid XML

Also when you get that exception, is there a JMS header with the key foo?
And what type is that header? Is it a boolean or a String type?


On Sat, Sep 18, 2010 at 8:56 PM, Illtud Daniel
<il...@llgc.org.uk> wrote:
> On 18/09/10 07:19, Claus Ibsen wrote:
>>
>> You have header
>>>
>>>            <header>$foo = 'true'</header>
>>
>> But you should use xpath
>>             <xpath>$foo = 'true'</xpath>
>
> Sorry, I cut and pasted in the route that I attempted to
> fix this problem.
>
> My original was indeed <xpath>$foo = 'true'</xpath>
> and that gave the error:
>
> 2010-09-18 01:59:36,205 | ERROR | Failed delivery for exchangeId:
>> ID:vaio-51221-1284757417176-5:22:-1:1:1. Exhausted after delivery attempt:
>> 1
>> caught: org.apache.camel.builder.xml.InvalidXPathExpression: Invalid
>> xpath:
>> $foo = 'true'.
>
> Has something changed between camel 2.0 & 2.4.0? Is that still
> the proper way to match on headers (using xpath?). It doesn't
> work for me anymore.
>
> --
> Illtud Daniel                                 illtud.daniel@llgc.org.uk
> Prif Swyddog Technoleg                          Chief Technical Officer
> Llyfrgell Genedlaethol Cymru                  National Library of Wales
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: $headername = 'value still works?

Posted by Illtud Daniel <il...@llgc.org.uk>.
On 18/09/10 07:19, Claus Ibsen wrote:
> You have header
>>             <header>$foo = 'true'</header>
>
> But you should use xpath
>              <xpath>$foo = 'true'</xpath>

Sorry, I cut and pasted in the route that I attempted to
fix this problem.

My original was indeed <xpath>$foo = 'true'</xpath>
and that gave the error:

2010-09-18 01:59:36,205 | ERROR | Failed delivery for exchangeId:
 > ID:vaio-51221-1284757417176-5:22:-1:1:1. Exhausted after delivery 
attempt: 1
 > caught: org.apache.camel.builder.xml.InvalidXPathExpression: Invalid 
xpath:
 > $foo = 'true'.

Has something changed between camel 2.0 & 2.4.0? Is that still
the proper way to match on headers (using xpath?). It doesn't
work for me anymore.

-- 
Illtud Daniel                                 illtud.daniel@llgc.org.uk
Prif Swyddog Technoleg                          Chief Technical Officer
Llyfrgell Genedlaethol Cymru                  National Library of Wales

Re: $headername = 'value still works?

Posted by Claus Ibsen <cl...@gmail.com>.
You have header
>            <header>$foo = 'true'</header>

But you should use xpath
            <xpath>$foo = 'true'</xpath>



On Sat, Sep 18, 2010 at 3:38 AM, Illtud Daniel
<il...@llgc.org.uk> wrote:
> Hi,
>
> I'm using camel as distributed with apachemq, sorry if this turns
> out to be an activemq problem.
>
> activemq 5.3.2 shipped with camel 2.0 (as far as I can tell)
> activemq 5.4 uses 2.4.0
>
> A route that used to work for me in 2.0 doesn't any more:
>
> <route autoStartup="true" inheritErrorHandler="true" id="SCIFglue5"
> xmlns:ns2="http://camel.apache.org/schema/web"
> xmlns="http://camel.apache.org/schema/spring">
>    <from uri="activemq:test_in"/>
>    <choice inheritErrorHandler="true" id="choice2">
>        <when inheritErrorHandler="true">
>            <header>$foo = 'true'</header>
>            <to uri="activemq:test_out_true" inheritErrorHandler="true"
> id="to6"/>
>        </when>
>        <otherwise inheritErrorHandler="true">
>            <to uri="activemq:test_out_other" inheritErrorHandler="true"
> id="to7"/>
>        </otherwise>
>    </choice>
> </route>
>
> [this was created in the console]
>
> It picks up from test_in, but I get this error in the activemq log:
>
> 2010-09-18 01:59:36,205 | ERROR | Failed delivery for exchangeId:
> ID:vaio-51221-1284757417176-5:22:-1:1:1. Exhausted after delivery attempt: 1
> caught: org.apache.camel.builder.xml.InvalidXPathExpression: Invalid xpath:
> $foo = 'true'.
>
>
> I know that "$foo = 'true'" isn't valid xpath, but isn't it camel's
> way of matching message headers? It worked in the version shipping
> with 5.3.x and I'm following the docs here:
> http://camel.apache.org/content-based-router.html
> http://camel.apache.org/xpath.html
>
> --
> Illtud Daniel                                 illtud.daniel@llgc.org.uk
> Prif Swyddog Technegol                          Chief Technical Officer
> Llyfrgell Genedlaethol Cymru                  National Library of Wales
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus