如何在Camel Processor中使用属性占位符

w41d8nur  于 10个月前  发布在  Apache
关注(0)|答案(2)|浏览(142)

我正在用camel写一些路由,我想用处理器做一些转换。我有一个属性文件,它工作正常。

from(URI_LOG)
    .routeId("{{PREFIX_LOG}}.prepareForMQ") 
    .log("Mail to: {{MAIL}}") //The value is read from a property file
    .process(new ProcessorPrepareMail())
    .log("${body}");

字符串
现在.我想在处理器中读取{{MAIL}}的值,但我不知道如何读取。
我尝试了这些东西:

public class ProcessorPrepareMail implements Processor
{

    @Override
    public void process(Exchange exchange) throws Exception
    {
        //Plan A: Does not work.... I get an empty String
        String mail = exchange.getProperty("MAIL", String.class);

        //Plan B: Does not work.... I get the String "{{MAIL}}"
        Language simple = exchange.getContext().resolveLanguage("simple");
        Expression expresion = simple.createExpression("{{MAIL}}");
        String valor = expresion.evaluate(exchange, String.class);

        //Plan C: Does not work. It activates the default error handler
        Language simple = exchange.getContext().resolveLanguage("simple");
        Expression expresion = simple.createExpression("${MAIL}");
        String valor = expresion.evaluate(exchange, String.class);
    }
}


你能帮帮我吗?
谢谢

6yt4nkrj

6yt4nkrj1#

CamelContext上有API可以做到这一点:

String mail = exchange.getContext().resolvePropertyPlaceholders("{{MAIL}}");

字符串

vlurs2pr

vlurs2pr2#

或使用;

String databaseName = ConfigProvider.getConfig().getValue("database.name", String.class);

字符串

相关问题