You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by welshstew <st...@gmail.com> on 2014/12/05 00:51:21 UTC

Unexpected behaviour of Camel Simple expression

Long time lurker - first time poster!  Please be nice :)

I have a very simple camel route:

<from uri="timer://foo?period=1000&amp;repeatCount=1" />
      <process ref="populateMap" />
      <log message="SIMPLE SPRING: INSERT INTO SOMETHING
(${bean:myeval?method=eval(${body[VALUE_ONE]})},${bean:myeval?method=eval(${body[VALUE_TWO]})})"
/>
      <process ref="simpleExpProcessor"/>
      <log message="${body}" />
      <log message="EXPECTED: INSERT INTO SOMETHING ('value','Thing (with
brackets)')" />

The populateMap bean creates a map as follows:

LinkedHashMap<String,Object> map = new LinkedHashMap<String, Object>();
map.put("VALUE_ONE", "'value'");
map.put("VALUE_TWO", "'Thing (with brackets)'");

The log output is:

[pache.camel.spring.Main.main()] SpringCamelContext             INFO  Apache
Camel 2.13.3 (CamelContext: camel-1) started in 0.282 seconds
[mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
evaluated : value
[mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
evaluated : 'Thing (with brackets
[mel-1) thread #0 - timer://foo] route1                         INFO  SIMPLE
SPRING: INSERT INTO SOMETHING (value,'Thing (with brackets)
[mel-1) thread #0 - timer://foo] SimpleExpressionProcessor      DEBUG INSERT
INTO SOMETHING
(${bean:myeval?method=eval(${body[VALUE_ONE]})},${bean:myeval?method=eval(${body[VALUE_TWO]})})
[mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
evaluated : value
[mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
evaluated : 'Thing (with brackets
[mel-1) thread #0 - timer://foo] route1                         INFO  INSERT
INTO SOMETHING (value,'Thing (with brackets)
[mel-1) thread #0 - timer://foo] route1                         INFO 
EXPECTED: INSERT INTO SOMETHING ('value','Thing (with brackets)')

Am I using the simple expression in the wrong way?  As you may expect I am
attempting to build SQL queries/inserts using simple and the results are not
quite as expected.

Many Thanks,

Stu.




--
View this message in context: http://camel.465427.n5.nabble.com/Unexpected-behaviour-of-Camel-Simple-expression-tp5760163.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unexpected behaviour of Camel Simple expression

Posted by welshstew <st...@gmail.com>.
Thanks Taariq - plenty of ways to skin this camel - which is what is so nice
about it.  I managed to get what I wanted by using a simple java processor.  

Cheers,

Stu.



--
View this message in context: http://camel.465427.n5.nabble.com/Unexpected-behaviour-of-Camel-Simple-expression-tp5760163p5760268.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unexpected behaviour of Camel Simple expression

Posted by Taariq Levack <ta...@gmail.com>.
The type converter ends up looking for a type Thingwithbrackets, the quotes and brackets don't make it easy.
I really don't know if it's meant to work that way, when Simple gets tricky I reach for something like Groovy or Java.


> On 05 Dec 2014, at 09:08, welshstew <st...@gmail.com> wrote:
> 
> Thanks for your response Taariq - but as you can see form the log output this
> isn't the case.  The myEval bean actually doesn't do anything but the String
> it receives during the simple expression evaluation is missing the single
> quotes - as per the log output:
> 
> INSERT INTO SOMETHING (value,'Thing (with brackets) 
> 
> I have published the code to github:
> 
> https://github.com/welshstew/simple-test
> <https://github.com/welshstew/simple-test>  
> 
> I'm pulling this out as an example - in another project I am working on
> because the bean represented by myEval does not get the correct input - then
> the evaluation of my eventual SQL statement ends up being incorrect.  :(
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Unexpected-behaviour-of-Camel-Simple-expression-tp5760163p5760187.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unexpected behaviour of Camel Simple expression

Posted by welshstew <st...@gmail.com>.
Thanks for your response Taariq - but as you can see form the log output this
isn't the case.  The myEval bean actually doesn't do anything but the String
it receives during the simple expression evaluation is missing the single
quotes - as per the log output:

INSERT INTO SOMETHING (value,'Thing (with brackets) 

I have published the code to github:

https://github.com/welshstew/simple-test
<https://github.com/welshstew/simple-test>  

I'm pulling this out as an example - in another project I am working on
because the bean represented by myEval does not get the correct input - then
the evaluation of my eventual SQL statement ends up being incorrect.  :(



--
View this message in context: http://camel.465427.n5.nabble.com/Unexpected-behaviour-of-Camel-Simple-expression-tp5760163p5760187.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Unexpected behaviour of Camel Simple expression

Posted by Taariq Levack <ta...@gmail.com>.
Hi and welcome

You don't say what myEval does, but the following expression does what you
want.

INSERT INTO SOMETHING (${body[VALUE_ONE]},${body[VALUE_TWO]})

Taariq

On Fri, Dec 5, 2014 at 1:51 AM, welshstew <st...@gmail.com>
wrote:

> Long time lurker - first time poster!  Please be nice :)
>
> I have a very simple camel route:
>
> <from uri="timer://foo?period=1000&amp;repeatCount=1" />
>       <process ref="populateMap" />
>       <log message="SIMPLE SPRING: INSERT INTO SOMETHING
>
> (${bean:myeval?method=eval(${body[VALUE_ONE]})},${bean:myeval?method=eval(${body[VALUE_TWO]})})"
> />
>       <process ref="simpleExpProcessor"/>
>       <log message="${body}" />
>       <log message="EXPECTED: INSERT INTO SOMETHING ('value','Thing (with
> brackets)')" />
>
> The populateMap bean creates a map as follows:
>
> LinkedHashMap<String,Object> map = new LinkedHashMap<String, Object>();
> map.put("VALUE_ONE", "'value'");
> map.put("VALUE_TWO", "'Thing (with brackets)'");
>
> The log output is:
>
> [pache.camel.spring.Main.main()] SpringCamelContext             INFO
> Apache
> Camel 2.13.3 (CamelContext: camel-1) started in 0.282 seconds
> [mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
> evaluated : value
> [mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
> evaluated : 'Thing (with brackets
> [mel-1) thread #0 - timer://foo] route1                         INFO
> SIMPLE
> SPRING: INSERT INTO SOMETHING (value,'Thing (with brackets)
> [mel-1) thread #0 - timer://foo] SimpleExpressionProcessor      DEBUG
> INSERT
> INTO SOMETHING
>
> (${bean:myeval?method=eval(${body[VALUE_ONE]})},${bean:myeval?method=eval(${body[VALUE_TWO]})})
> [mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
> evaluated : value
> [mel-1) thread #0 - timer://foo] MyEvaluator                    DEBUG
> evaluated : 'Thing (with brackets
> [mel-1) thread #0 - timer://foo] route1                         INFO
> INSERT
> INTO SOMETHING (value,'Thing (with brackets)
> [mel-1) thread #0 - timer://foo] route1                         INFO
> EXPECTED: INSERT INTO SOMETHING ('value','Thing (with brackets)')
>
> Am I using the simple expression in the wrong way?  As you may expect I am
> attempting to build SQL queries/inserts using simple and the results are
> not
> quite as expected.
>
> Many Thanks,
>
> Stu.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Unexpected-behaviour-of-Camel-Simple-expression-tp5760163.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>