How to use property placeholder inside a Camel Processor
Asked Answered
P

2

6

I'm writing some routes with camel, and I want to make some transformations using a Processor. I have a properties file and it is working ok.

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

Now... I want to read the value of {{MAIL}} inside the processor but I don't know how.

I tried these things:

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

Can you help me?

Thanks

Poundal answered 4/8, 2016 at 16:31 Comment(0)
C
25

There is API on CamelContext to do that:

String mail = exchange.getContext().resolvePropertyPlaceholders("{{MAIL}}");
Careen answered 4/8, 2016 at 16:40 Comment(2)
Excellent! Thank you!Poundal
how can do this in spring XML?Dieball
P
1

or use;

String databaseName = ConfigProvider.getConfig().getValue("database.name", String.class);
Prismatic answered 10/12, 2023 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.