繁体   English   中英

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

[英]How to use property placeholder inside a Camel Processor

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

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

你能帮助我吗?

谢谢

CamelContext上有API来做到这一点:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM