如何在Camel处理器中使用属性占位符

问题描述 投票:0回答:2

我正在用骆驼编写一些路线,我想使用处理器进行一些转换。我有一个属性文件,它工作正常。

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

你能帮我吗?

谢谢

java apache-camel integration
2个回答
22
投票

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

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

0
投票

或使用;

String databaseName = ConfigProvider.getConfig().getValue("database.name", String.class);
© www.soinside.com 2019 - 2024. All rights reserved.