jeudi 15 octobre 2020

Camel - Use previously set property as a parameter to method

Using Camel 3.5.0.

I need to set a value to a property and, after some transformation, use that property as a parameter in a method call throught the method bean, from Camel.

from("direct:route1")
        .setProperty("myProperty", method(MyBean.class, "myMethod"))
        .transform(method(transformerBean, "transformMethod"))
        .bean(MyBean.class,
                "otherMethod(<<HERE I WANT TO PASS THE PREVIOUSLY SET PROPERTY 'myProperty'>>)")
        .to("direct:route2");

There is an alternative. Instead of using the setProperty method, if I use the setHeader, also from Camel, the way to use that header as a parameter is ${headers.nameOfHeaderKey}. That works as a charm. But when I try to use the Property feature, I am not getting a way to retrieve it and pass it as a method param.

In other words, when I try this: ${properties.myProperty} I get this error:

Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: properties.myProperty
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createSimpleExpression(SimpleFunctionExpression.java:247)
    at org.apache.camel.language.simple.ast.SimpleFunctionExpression.createExpression(SimpleFunctionExpression.java:54)
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.doCreateLiteralExpression(SimpleFunctionStart.java:69)
    at org.apache.camel.language.simple.ast.SimpleFunctionStart.createExpression(SimpleFunctionStart.java:59)
    at org.apache.camel.language.simple.SimpleExpressionParser.createExpressions(SimpleExpressionParser.java:164)
    at org.apache.camel.language.simple.SimpleExpressionParser.doParseExpression(SimpleExpressionParser.java:87)
    at org.apache.camel.language.simple.SimpleExpressionParser.parseExpression(SimpleExpressionParser.java:54)
    ... 98 common frames omitted

Any idea?





Aucun commentaire:

Enregistrer un commentaire