1

my problem is, I don't know how I can access exchange's header values inside a string-template declaration. I would like to have internationalized mail templates. The test code below ...

public class StringTemplateTest extends CamelTestSupport {

    @EndpointInject(uri = "mock:result")
    protected MockEndpoint resultEndpoint;

    @Produce(uri = "direct:start")
    protected ProducerTemplate template;

    @Test
    public void testTemplating() throws Exception {
        resultEndpoint.expectedBodiesReceived("test");
        template.sendBodyAndHeader("test", "lang", "de");
        resultEndpoint.assertIsSatisfied();
    }

    @Override
    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            public void configure() {
                from("direct:start").to("string-template:mailTemplate_$simple{in.header.lang}.tm").to("mock:result");
            }
        };
    }
}

ends in a ...

java.io.FileNotFoundException: Cannot find resource: mailTemplate_$simple{in.header.lang}.tm in classpath for URI: mailTemplate_$simple{in.header.lang}.tm

I would expect, the string-template is lookig for mailTemplate_de.tm.

Thank you for help in advance!

1 Answer 1

1

Your problem is that .to("component:xyz") endpoints are evaluated at the time the route is built - they are not dynamic and won't pick up ${} properties.

Instead you need to use recipientList, like this:

from("direct:start")
    .recipientList(simple("string_template:mailTemplate_${in.header.lang}.tm"))
    .to("mock:result")
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.