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

Search Discussions

  • Taariq Levack at Dec 5, 2014 at 6:58 am
    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 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.
  • Welshstew at Dec 5, 2014 at 7:09 am
    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.
  • Taariq Levack at Dec 5, 2014 at 6:55 pm
    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 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.
  • Welshstew at Dec 8, 2014 at 5:44 am
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedDec 4, '14 at 11:51p
activeDec 8, '14 at 5:44a
posts5
users2
websitecamel.apache.org

2 users in discussion

Welshstew: 3 posts Taariq Levack: 2 posts

People

Translate

site design / logo © 2022 Grokbase