Desenfoque
Desenfoque

Reputation: 816

How to use property placeholder inside a Camel Processor

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

Upvotes: 6

Views: 7066

Answers (2)

Ahmet Özaydın
Ahmet Özaydın

Reputation: 51

or use;

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

Upvotes: 1

Claus Ibsen
Claus Ibsen

Reputation: 55525

There is API on CamelContext to do that:

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

Upvotes: 25

Related Questions