簡體   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