骆驼-使用先前设置的属性作为方法的参数

问题描述

使用骆驼3.5.0。

我需要为一个属性设置一个值,经过一些转换后,在通过骆驼的方法bean进行的方法调用中,将该属性用作参数。

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");

还有另一种选择。如果我也使用Camel的setProperty,而不是使用setHeader方法,则使用该标头作为参数的方法${headers.nameOfheaderKey}。这是一种魅力。但是,当我尝试使用“属性功能时,没有办法检索它并将其作为方法参数传递。

换句话说,当我尝试这样做时:${properties.myProperty},我收到此错误

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

有什么主意吗?

解决方法

Exchange属性的语法为${exchangeProperty.myProperty}

请参见Simple language docs

exchangeProperty.foo |对象请参考交易所的foo属性

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...