You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by packo <pa...@gmail.com> on 2008/12/03 13:09:23 UTC

Endpoint decision based on Header Value with XML configuration

It might be a simple question, but i am stuck with it in the past few days so
any help would be appreciated.

I have a route that looks like this:

<route>
	<from uri="direct:foobar" />
	   <choice>
		<when>
			<simple>${in.headers.foo} == 'foo1'</simple>
			<bean ref="fooBean1" />
		</when>
		<when>
		   <simple>${in.headers.foo} == 'foo2'</simple>				
		   <bean ref="fooBean2" />
		</when>		
	  </choice>
	 <choice>
		<when>
                   <simple>${in.headers.bar } == 'bar1'</simple> 			 				
		  <to uri="bean:barBean?method=barMethod" />					
		</when>				
	  </choice>
</route>

foo and bar headers are pre-populated from the Producer i am using.
What happens is that each expression is evaluated to true. A look in the
code showed that <simple> evaluates just the existence of a header.
I also tried ognl, xpath and others but nothing seems to work.

My exchange is a default exchange with a DTO as payload. Am i missing
something???
-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20811772.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

Posted by James Strachan <ja...@gmail.com>.
2008/12/3 packo <pa...@gmail.com>:
>
> Thank you for your swift reply.
>
> I have already tried ognl, following the example in the URL you mentioned.
>
> The route i created looked like:
>
>  <route>
>        <from uri="direct:foobar" />
>           <choice>
>                <when>
>                        <ognl>request.headers.foo = 'foo1'</ognl>
>                        <bean ref="fooBean1" />
>                </when>
>                <when>
>                        <ognl>request.headers.foo = 'foo2'</ognl>
>                       <bean ref="fooBean2" />
>                </when>
>          </choice>
> .
> .
> .
> </route>
>
>
> But still the result was that i was always getting true for the result of
> ognl expression. Maybe i am overlooking sth with OGNL?

Any chance you could hack this test case to reproduce your problem?
https://svn.apache.org/repos/asf/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/FilterTest.java

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Endpoint decision based on Header Value with XML configuration

Posted by James Strachan <ja...@gmail.com>.
Ah great! BTW I've added your test case to trunk...
http://svn.apache.org/repos/asf/activemq/camel/trunk/components/camel-ognl/src/test/java/org/apache/camel/language/ognl/patterns/FilterTest.java

2008/12/3 packo <pa...@gmail.com>:
>
> After doing a bit more research on OGNL, i found the error:
>
>
> The statement should look like "request.header.foo == 'bar'" and NOT
> "request.header.foo = 'bar'". The test now works.
>
>
> packo wrote:
>>
>> So,  I finished reproducing the situation:
>>
>> My Test class looks like this:
>>
>> public class CamelTest extends ContextTestSupport {
>>
>>     public void testSendMatchingMessage() throws Exception {
>>         MockEndpoint resultEndpoint =
>> resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
>>         resultEndpoint.expectedMessageCount(1);
>>
>>         template.sendBodyAndHeader("direct:start", "<matched/>", "foo",
>> "bar");
>>
>>         resultEndpoint.assertIsSatisfied();
>>     }
>>
>>     public void testSendNotMatchingMessage() throws Exception {
>>         MockEndpoint resultEndpoint =
>> resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
>>         resultEndpoint.expectedMessageCount(0);
>>
>>         template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo",
>> "notMatchedHeaderValue");
>>
>>         resultEndpoint.assertIsSatisfied();
>>     }
>>
>>
>>     protected RouteBuilder createRouteBuilder() {
>>         return new RouteBuilder() {
>>             public void configure() {
>>
>> from("direct:start").choice().when().ognl("request.header.foo =
>> 'bar'").to("mock:result");
>>             }
>>         };
>>     }
>>
>> testSendNotMatchingMessage fails with trace:
>>
>> java.lang.AssertionError: mock:result Received message count. Expected:
>> <0> but was: <1>
>>       at
>> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:712)
>>       at
>> org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:694)
>>       at
>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:238)
>>       at
>> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:214)
>>       at
>> ec.ep.epgreffe.il.epades.CamelTest.testSendNotMatchingMessage(CamelTest.java:43)
>>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>       at
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>>       at
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>>       at java.lang.reflect.Method.invoke(Method.java:597)
>>       at junit.framework.TestCase.runTest(TestCase.java:154)
>>       at junit.framework.TestCase.runBare(TestCase.java:127)
>>       at junit.framework.TestResult$1.protect(TestResult.java:106)
>>       at junit.framework.TestResult.runProtected(TestResult.java:124)
>>       at junit.framework.TestResult.run(TestResult.java:109)
>>       at junit.framework.TestCase.run(TestCase.java:118)
>>       at junit.framework.TestSuite.runTest(TestSuite.java:208)
>>       at junit.framework.TestSuite.run(TestSuite.java:203)
>>       at
>> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
>>       at
>> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
>>       at
>> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
>>
>>
>>
>> I have added in my classpath ognl-2.6.9.jar as well.
>>
>>
>>
>> packo wrote:
>>>
>>> Sorry for the late reply..I am trying to reproduce the issue with the
>>> test you gave me..
>>>
>>> I am using log4J, i am getting various warning for libraries missing, but
>>> ognl seems to be working properly. The following comes from the log
>>> files:
>>>
>>> .
>>> .
>>> DEBUG main org.apache.camel.management.DefaultInstrumentationAgent -
>>> Registered MBean with objectname:
>>> org.apache.camel:context=PRESBRUWSDW82/camel,type=processors,nodeid=choice2,name="Choice[[When[ognl{request.headers.foo
>>> = 'foo1} -> [To[bean:fooBean\?method=fooMethod1]]],
>>> When[ognl{request.headers.foo ='foo2'} ->
>>> [To[bean:fooBean\?method=fooMethod1]]]]]"
>>>
>>>
>>> And then later,
>>> .
>>> .
>>>  DEBUG main
>>> org.springframework.beans.factory.support.DefaultListableBeanFactory -
>>> Creating instance of bean 'org.apache.camel.language.ognl.OgnlLanguage'
>>>  DEBUG main
>>> org.springframework.beans.factory.support.DefaultListableBeanFactory -
>>> Finished creating instance of bean
>>> 'org.apache.camel.language.ognl.OgnlLanguage'
>>> .
>>> .
>>>
>>>
>>>
>>> James.Strachan wrote:
>>>>
>>>> 2008/12/3 packo <pa...@gmail.com>:
>>>>>
>>>>> I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose
>>>>> that i
>>>>> would not need to add any more Jars.
>>>>
>>>> It includes all the camel code - but not the dependencies - for
>>>> example the ognl jar is not included.
>>>>
>>>>> Also, there is not exception thrown, the execution ends properly.
>>>>
>>>> I wonder if you get warnings? You using log4j?
>>>>
>>>> --
>>>> James
>>>> -------
>>>> http://macstrac.blogspot.com/
>>>>
>>>> Open Source Integration
>>>> http://fusesource.com/
>>>>
>>>>
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20815002.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Endpoint decision based on Header Value with XML configuration

Posted by packo <pa...@gmail.com>.
After doing a bit more research on OGNL, i found the error:


The statement should look like "request.header.foo == 'bar'" and NOT 
"request.header.foo = 'bar'". The test now works.


packo wrote:
> 
> So,  I finished reproducing the situation:
> 
> My Test class looks like this:
> 
> public class CamelTest extends ContextTestSupport {
> 
>     public void testSendMatchingMessage() throws Exception {
>         MockEndpoint resultEndpoint =
> resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
>         resultEndpoint.expectedMessageCount(1);
> 
>         template.sendBodyAndHeader("direct:start", "<matched/>", "foo",
> "bar");
> 
>         resultEndpoint.assertIsSatisfied();
>     }
> 
>     public void testSendNotMatchingMessage() throws Exception {
>         MockEndpoint resultEndpoint =
> resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
>         resultEndpoint.expectedMessageCount(0);
> 
>         template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo",
> "notMatchedHeaderValue");
> 
>         resultEndpoint.assertIsSatisfied();
>     }
> 
> 
>     protected RouteBuilder createRouteBuilder() {
>         return new RouteBuilder() {
>             public void configure() {
>                
> from("direct:start").choice().when().ognl("request.header.foo =
> 'bar'").to("mock:result");
>             }
>         };
>     }
> 
> testSendNotMatchingMessage fails with trace:
> 
> java.lang.AssertionError: mock:result Received message count. Expected:
> <0> but was: <1>
> 	at
> org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:712)
> 	at
> org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:694)
> 	at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:238)
> 	at
> org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:214)
> 	at
> ec.ep.epgreffe.il.epades.CamelTest.testSendNotMatchingMessage(CamelTest.java:43)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:597)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at
> org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
> 	at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> 
>  
> 
> I have added in my classpath ognl-2.6.9.jar as well.
> 
> 
> 
> packo wrote:
>> 
>> Sorry for the late reply..I am trying to reproduce the issue with the
>> test you gave me..
>> 
>> I am using log4J, i am getting various warning for libraries missing, but
>> ognl seems to be working properly. The following comes from the log
>> files:
>> 
>> .
>> .
>> DEBUG main org.apache.camel.management.DefaultInstrumentationAgent -
>> Registered MBean with objectname:
>> org.apache.camel:context=PRESBRUWSDW82/camel,type=processors,nodeid=choice2,name="Choice[[When[ognl{request.headers.foo
>> = 'foo1} -> [To[bean:fooBean\?method=fooMethod1]]],
>> When[ognl{request.headers.foo ='foo2'} ->
>> [To[bean:fooBean\?method=fooMethod1]]]]]"
>> 
>> 
>> And then later,
>> .
>> .
>>  DEBUG main
>> org.springframework.beans.factory.support.DefaultListableBeanFactory -
>> Creating instance of bean 'org.apache.camel.language.ognl.OgnlLanguage'
>>  DEBUG main
>> org.springframework.beans.factory.support.DefaultListableBeanFactory -
>> Finished creating instance of bean
>> 'org.apache.camel.language.ognl.OgnlLanguage'
>> .
>> .
>> 
>> 
>> 
>> James.Strachan wrote:
>>> 
>>> 2008/12/3 packo <pa...@gmail.com>:
>>>>
>>>> I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose
>>>> that i
>>>> would not need to add any more Jars.
>>> 
>>> It includes all the camel code - but not the dependencies - for
>>> example the ognl jar is not included.
>>> 
>>>> Also, there is not exception thrown, the execution ends properly.
>>> 
>>> I wonder if you get warnings? You using log4j?
>>> 
>>> -- 
>>> James
>>> -------
>>> http://macstrac.blogspot.com/
>>> 
>>> Open Source Integration
>>> http://fusesource.com/
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20815002.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

Posted by packo <pa...@gmail.com>.
So,  I finished reproducing the situation:

My Test class looks like this:

public class CamelTest extends ContextTestSupport {

    public void testSendMatchingMessage() throws Exception {
        MockEndpoint resultEndpoint =
resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedMessageCount(1);

        template.sendBodyAndHeader("direct:start", "<matched/>", "foo",
"bar");

        resultEndpoint.assertIsSatisfied();
    }

    public void testSendNotMatchingMessage() throws Exception {
        MockEndpoint resultEndpoint =
resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedMessageCount(0);

        template.sendBodyAndHeader("direct:start", "<notMatched/>", "foo",
"notMatchedHeaderValue");

        resultEndpoint.assertIsSatisfied();
    }


    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
               
from("direct:start").choice().when().ognl("request.header.foo =
'bar'").to("mock:result");
            }
        };
    }

testSendNotMatchingMessage fails with trace:

java.lang.AssertionError: mock:result Received message count. Expected: <0>
but was: <1>
	at org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:712)
	at
org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:694)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:238)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:214)
	at
ec.ep.epgreffe.il.epades.CamelTest.testSendNotMatchingMessage(CamelTest.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
	at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

 

I have added in my classpath ognl-2.6.9.jar as well.



packo wrote:
> 
> Sorry for the late reply..I am trying to reproduce the issue with the test
> you gave me..
> 
> I am using log4J, i am getting various warning for libraries missing, but
> ognl seems to be working properly. The following comes from the log files:
> 
> .
> .
> DEBUG main org.apache.camel.management.DefaultInstrumentationAgent -
> Registered MBean with objectname:
> org.apache.camel:context=PRESBRUWSDW82/camel,type=processors,nodeid=choice2,name="Choice[[When[ognl{request.headers.foo
> = 'foo1} -> [To[bean:fooBean\?method=fooMethod1]]],
> When[ognl{request.headers.foo ='foo2'} ->
> [To[bean:fooBean\?method=fooMethod1]]]]]"
> 
> 
> And then later,
> .
> .
>  DEBUG main
> org.springframework.beans.factory.support.DefaultListableBeanFactory -
> Creating instance of bean 'org.apache.camel.language.ognl.OgnlLanguage'
>  DEBUG main
> org.springframework.beans.factory.support.DefaultListableBeanFactory -
> Finished creating instance of bean
> 'org.apache.camel.language.ognl.OgnlLanguage'
> .
> .
> 
> 
> 
> James.Strachan wrote:
>> 
>> 2008/12/3 packo <pa...@gmail.com>:
>>>
>>> I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose
>>> that i
>>> would not need to add any more Jars.
>> 
>> It includes all the camel code - but not the dependencies - for
>> example the ognl jar is not included.
>> 
>>> Also, there is not exception thrown, the execution ends properly.
>> 
>> I wonder if you get warnings? You using log4j?
>> 
>> -- 
>> James
>> -------
>> http://macstrac.blogspot.com/
>> 
>> Open Source Integration
>> http://fusesource.com/
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20813924.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

Posted by packo <pa...@gmail.com>.
Sorry for the late reply..I am trying to reproduce the issue with the test
you gave me..

I am using log4J, i am getting various warning for libraries missing, but
ognl seems to be working properly. The following comes from the log files:

.
.
DEBUG main org.apache.camel.management.DefaultInstrumentationAgent -
Registered MBean with objectname:
org.apache.camel:context=PRESBRUWSDW82/camel,type=processors,nodeid=choice2,name="Choice[[When[ognl{request.headers.foo
= 'foo1} -> [To[bean:fooBean\?method=fooMethod1]]],
When[ognl{request.headers.foo ='foo2'} ->
[To[bean:fooBean\?method=fooMethod1]]]]]"


And then later,
.
.
 DEBUG main
org.springframework.beans.factory.support.DefaultListableBeanFactory -
Creating instance of bean 'org.apache.camel.language.ognl.OgnlLanguage'
 DEBUG main
org.springframework.beans.factory.support.DefaultListableBeanFactory -
Finished creating instance of bean
'org.apache.camel.language.ognl.OgnlLanguage'
.
.



James.Strachan wrote:
> 
> 2008/12/3 packo <pa...@gmail.com>:
>>
>> I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose that
>> i
>> would not need to add any more Jars.
> 
> It includes all the camel code - but not the dependencies - for
> example the ognl jar is not included.
> 
>> Also, there is not exception thrown, the execution ends properly.
> 
> I wonder if you get warnings? You using log4j?
> 
> -- 
> James
> -------
> http://macstrac.blogspot.com/
> 
> Open Source Integration
> http://fusesource.com/
> 
> 

-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20812995.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

Posted by James Strachan <ja...@gmail.com>.
2008/12/3 packo <pa...@gmail.com>:
>
> I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose that i
> would not need to add any more Jars.

It includes all the camel code - but not the dependencies - for
example the ognl jar is not included.

> Also, there is not exception thrown, the execution ends properly.

I wonder if you get warnings? You using log4j?

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Endpoint decision based on Header Value with XML configuration

Posted by packo <pa...@gmail.com>.
I am using the full camel jar (apache-camel-1.5.0.jar), so i suppose that i
would not need to add any more Jars.

Also, there is not exception thrown, the execution ends properly.


Claus Ibsen-2 wrote:
> 
> Hi
> 
> And you have camel-ognl on the classpath?
> 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 
> 
> On Wed, Dec 3, 2008 at 1:43 PM, packo <pa...@gmail.com> wrote:
>>
>> Thank you for your swift reply.
>>
>> I have already tried ognl, following the example in the URL you
>> mentioned.
>>
>> The route i created looked like:
>>
>>  <route>
>>        <from uri="direct:foobar" />
>>           <choice>
>>                <when>
>>                        <ognl>request.headers.foo = 'foo1'</ognl>
>>                        <bean ref="fooBean1" />
>>                </when>
>>                <when>
>>                        <ognl>request.headers.foo = 'foo2'</ognl>
>>                       <bean ref="fooBean2" />
>>                </when>
>>          </choice>
>> .
>> .
>> .
>> </route>
>>
>>
>> But still the result was that i was always getting true for the result of
>> ognl expression. Maybe i am overlooking sth with OGNL?
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> Hi
>>>
>>> Yeah simple does not understand EQ, GE, LT and other operators.
>>>
>>> You can use some of the other languages
>>> - ognl
>>> - el
>>> - groovy
>>> - bean (for using POJO)
>>> - xpath if your payload is xml based
>>>
>>> See
>>> http://activemq.apache.org/camel/scripting-languages.html
>>> http://activemq.apache.org/camel/ognl.html
>>>
>>> Using OGNL it would be
>>> <ognl>request.headers.foo = 'foo1'</ognl>
>>>
>>> But I am wondering if we should improve the simple language so it can
>>> be use some simple operators for simple test such as in your use-case.
>>> No need to learn OGNL, Groovy or depend on 3rd part .jars. Just plain
>>> Java.
>>>
>>> James, any thoughts on this?
>>>
>>>
>>>
>>>
>>> /Claus Ibsen
>>> Apache Camel Committer
>>> Blog: http://davsclaus.blogspot.com/
>>>
>>>
>>>
>>> On Wed, Dec 3, 2008 at 1:09 PM, packo <pa...@gmail.com>
>>> wrote:
>>>>
>>>> It might be a simple question, but i am stuck with it in the past few
>>>> days so
>>>> any help would be appreciated.
>>>>
>>>> I have a route that looks like this:
>>>>
>>>> <route>
>>>>        <from uri="direct:foobar" />
>>>>           <choice>
>>>>                <when>
>>>>                        <simple>${in.headers.foo} == 'foo1'</simple>
>>>>                        <bean ref="fooBean1" />
>>>>                </when>
>>>>                <when>
>>>>                   <simple>${in.headers.foo} == 'foo2'</simple>
>>>>                   <bean ref="fooBean2" />
>>>>                </when>
>>>>          </choice>
>>>>         <choice>
>>>>                <when>
>>>>                   <simple>${in.headers.bar } == 'bar1'</simple>
>>>>                  <to uri="bean:barBean?method=barMethod" />
>>>>                </when>
>>>>          </choice>
>>>> </route>
>>>>
>>>> foo and bar headers are pre-populated from the Producer i am using.
>>>> What happens is that each expression is evaluated to true. A look in
>>>> the
>>>> code showed that <simple> evaluates just the existence of a header.
>>>> I also tried ognl, xpath and others but nothing seems to work.
>>>>
>>>> My exchange is a default exchange with a DTO as payload. Am i missing
>>>> something???
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20811772.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20812287.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20812462.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

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

And you have camel-ognl on the classpath?


/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Wed, Dec 3, 2008 at 1:43 PM, packo <pa...@gmail.com> wrote:
>
> Thank you for your swift reply.
>
> I have already tried ognl, following the example in the URL you mentioned.
>
> The route i created looked like:
>
>  <route>
>        <from uri="direct:foobar" />
>           <choice>
>                <when>
>                        <ognl>request.headers.foo = 'foo1'</ognl>
>                        <bean ref="fooBean1" />
>                </when>
>                <when>
>                        <ognl>request.headers.foo = 'foo2'</ognl>
>                       <bean ref="fooBean2" />
>                </when>
>          </choice>
> .
> .
> .
> </route>
>
>
> But still the result was that i was always getting true for the result of
> ognl expression. Maybe i am overlooking sth with OGNL?
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> Yeah simple does not understand EQ, GE, LT and other operators.
>>
>> You can use some of the other languages
>> - ognl
>> - el
>> - groovy
>> - bean (for using POJO)
>> - xpath if your payload is xml based
>>
>> See
>> http://activemq.apache.org/camel/scripting-languages.html
>> http://activemq.apache.org/camel/ognl.html
>>
>> Using OGNL it would be
>> <ognl>request.headers.foo = 'foo1'</ognl>
>>
>> But I am wondering if we should improve the simple language so it can
>> be use some simple operators for simple test such as in your use-case.
>> No need to learn OGNL, Groovy or depend on 3rd part .jars. Just plain
>> Java.
>>
>> James, any thoughts on this?
>>
>>
>>
>>
>> /Claus Ibsen
>> Apache Camel Committer
>> Blog: http://davsclaus.blogspot.com/
>>
>>
>>
>> On Wed, Dec 3, 2008 at 1:09 PM, packo <pa...@gmail.com> wrote:
>>>
>>> It might be a simple question, but i am stuck with it in the past few
>>> days so
>>> any help would be appreciated.
>>>
>>> I have a route that looks like this:
>>>
>>> <route>
>>>        <from uri="direct:foobar" />
>>>           <choice>
>>>                <when>
>>>                        <simple>${in.headers.foo} == 'foo1'</simple>
>>>                        <bean ref="fooBean1" />
>>>                </when>
>>>                <when>
>>>                   <simple>${in.headers.foo} == 'foo2'</simple>
>>>                   <bean ref="fooBean2" />
>>>                </when>
>>>          </choice>
>>>         <choice>
>>>                <when>
>>>                   <simple>${in.headers.bar } == 'bar1'</simple>
>>>                  <to uri="bean:barBean?method=barMethod" />
>>>                </when>
>>>          </choice>
>>> </route>
>>>
>>> foo and bar headers are pre-populated from the Producer i am using.
>>> What happens is that each expression is evaluated to true. A look in the
>>> code showed that <simple> evaluates just the existence of a header.
>>> I also tried ognl, xpath and others but nothing seems to work.
>>>
>>> My exchange is a default exchange with a DTO as payload. Am i missing
>>> something???
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20811772.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20812287.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: Endpoint decision based on Header Value with XML configuration

Posted by packo <pa...@gmail.com>.
Thank you for your swift reply.

I have already tried ognl, following the example in the URL you mentioned.

The route i created looked like:

 <route>
        <from uri="direct:foobar" />
           <choice>
                <when>
                        <ognl>request.headers.foo = 'foo1'</ognl>
                        <bean ref="fooBean1" />
                </when>
                <when>
                        <ognl>request.headers.foo = 'foo2'</ognl>
                       <bean ref="fooBean2" />
                </when>
          </choice>
.
.
.
</route>


But still the result was that i was always getting true for the result of
ognl expression. Maybe i am overlooking sth with OGNL?


Claus Ibsen-2 wrote:
> 
> Hi
> 
> Yeah simple does not understand EQ, GE, LT and other operators.
> 
> You can use some of the other languages
> - ognl
> - el
> - groovy
> - bean (for using POJO)
> - xpath if your payload is xml based
> 
> See
> http://activemq.apache.org/camel/scripting-languages.html
> http://activemq.apache.org/camel/ognl.html
> 
> Using OGNL it would be
> <ognl>request.headers.foo = 'foo1'</ognl>
> 
> But I am wondering if we should improve the simple language so it can
> be use some simple operators for simple test such as in your use-case.
> No need to learn OGNL, Groovy or depend on 3rd part .jars. Just plain
> Java.
> 
> James, any thoughts on this?
> 
> 
> 
> 
> /Claus Ibsen
> Apache Camel Committer
> Blog: http://davsclaus.blogspot.com/
> 
> 
> 
> On Wed, Dec 3, 2008 at 1:09 PM, packo <pa...@gmail.com> wrote:
>>
>> It might be a simple question, but i am stuck with it in the past few
>> days so
>> any help would be appreciated.
>>
>> I have a route that looks like this:
>>
>> <route>
>>        <from uri="direct:foobar" />
>>           <choice>
>>                <when>
>>                        <simple>${in.headers.foo} == 'foo1'</simple>
>>                        <bean ref="fooBean1" />
>>                </when>
>>                <when>
>>                   <simple>${in.headers.foo} == 'foo2'</simple>
>>                   <bean ref="fooBean2" />
>>                </when>
>>          </choice>
>>         <choice>
>>                <when>
>>                   <simple>${in.headers.bar } == 'bar1'</simple>
>>                  <to uri="bean:barBean?method=barMethod" />
>>                </when>
>>          </choice>
>> </route>
>>
>> foo and bar headers are pre-populated from the Producer i am using.
>> What happens is that each expression is evaluated to true. A look in the
>> code showed that <simple> evaluates just the existence of a header.
>> I also tried ognl, xpath and others but nothing seems to work.
>>
>> My exchange is a default exchange with a DTO as payload. Am i missing
>> something???
>> --
>> View this message in context:
>> http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20811772.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20812287.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Endpoint decision based on Header Value with XML configuration

Posted by James Strachan <ja...@gmail.com>.
2008/12/3 Claus Ibsen <cl...@gmail.com>:
> Hi
>
> Yeah simple does not understand EQ, GE, LT and other operators.
>
> You can use some of the other languages
> - ognl
> - el
> - groovy
> - bean (for using POJO)
> - xpath if your payload is xml based
>
> See
> http://activemq.apache.org/camel/scripting-languages.html
> http://activemq.apache.org/camel/ognl.html
>
> Using OGNL it would be
> <ognl>request.headers.foo = 'foo1'</ognl>
>
> But I am wondering if we should improve the simple language so it can
> be use some simple operators for simple test such as in your use-case.
> No need to learn OGNL, Groovy or depend on 3rd part .jars. Just plain Java.
>
> James, any thoughts on this?

If in doubt, just use a Java method to evaluate your expression...
http://cwiki.apache.org/CAMEL/bean-language.html

e.g.

public boolean isFoo1(@Header(name = "foo") String foo) {
  return foo.equals("foo1");
}

Or you could go one step further and write the router as a single Java method...
http://activemq.apache.org/camel/recipientlist-annotation.html

@RecipientList
public String myRouter(@Header(name="foo") String foo,
@Header(name="bar") Integer bar) {
  if (foo.equals("foo1") {
    return "ref:fooBean1";
  }
  ...
}

With any expressions its always worth writing some test cases to check
your expressions do what you expect...
http://cwiki.apache.org/CAMEL/testing.html

I'd also recommend turning on tracing to make absolutely sure the
messages look exactly as you think
http://activemq.apache.org/camel/tracer.html

-- 
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://fusesource.com/

Re: Endpoint decision based on Header Value with XML configuration

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

Yeah simple does not understand EQ, GE, LT and other operators.

You can use some of the other languages
- ognl
- el
- groovy
- bean (for using POJO)
- xpath if your payload is xml based

See
http://activemq.apache.org/camel/scripting-languages.html
http://activemq.apache.org/camel/ognl.html

Using OGNL it would be
<ognl>request.headers.foo = 'foo1'</ognl>

But I am wondering if we should improve the simple language so it can
be use some simple operators for simple test such as in your use-case.
No need to learn OGNL, Groovy or depend on 3rd part .jars. Just plain Java.

James, any thoughts on this?




/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Wed, Dec 3, 2008 at 1:09 PM, packo <pa...@gmail.com> wrote:
>
> It might be a simple question, but i am stuck with it in the past few days so
> any help would be appreciated.
>
> I have a route that looks like this:
>
> <route>
>        <from uri="direct:foobar" />
>           <choice>
>                <when>
>                        <simple>${in.headers.foo} == 'foo1'</simple>
>                        <bean ref="fooBean1" />
>                </when>
>                <when>
>                   <simple>${in.headers.foo} == 'foo2'</simple>
>                   <bean ref="fooBean2" />
>                </when>
>          </choice>
>         <choice>
>                <when>
>                   <simple>${in.headers.bar } == 'bar1'</simple>
>                  <to uri="bean:barBean?method=barMethod" />
>                </when>
>          </choice>
> </route>
>
> foo and bar headers are pre-populated from the Producer i am using.
> What happens is that each expression is evaluated to true. A look in the
> code showed that <simple> evaluates just the existence of a header.
> I also tried ognl, xpath and others but nothing seems to work.
>
> My exchange is a default exchange with a DTO as payload. Am i missing
> something???
> --
> View this message in context: http://www.nabble.com/Endpoint-decision-based-on-Header-Value-with-XML-configuration-tp20811772s22882p20811772.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>