Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache camel Apache Camel访问字符串模板中的头值_Apache Camel_Stringtemplate - Fatal编程技术网

Apache camel Apache Camel访问字符串模板中的头值

Apache camel Apache Camel访问字符串模板中的头值,apache-camel,stringtemplate,Apache Camel,Stringtemplate,我的问题是,我不知道如何在字符串模板声明中访问exchange的头值。我想有国际化的邮件模板。下面的测试代码 public class StringTemplateTest extends CamelTestSupport { @EndpointInject(uri = "mock:result") protected MockEndpoint resultEndpoint; @Produce(uri = "direct:start") protected P

我的问题是,我不知道如何在字符串模板声明中访问exchange的头值。我想有国际化的邮件模板。下面的测试代码

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");
            }
        };
    }
}
以…结尾

java.io.FileNotFoundException: Cannot find resource: mailTemplate_$simple{in.header.lang}.tm in classpath for URI: mailTemplate_$simple{in.header.lang}.tm
我希望字符串模板正在查找mailTemplate\u de.tm


提前感谢您的帮助

您的问题是,
.to(“component:xyz”)
端点在构建路由时进行评估-它们不是动态的,不会获取
${}
属性

相反,您需要使用
recipientList
,如下所示:

from("direct:start")
    .recipientList(simple("string_template:mailTemplate_${in.header.lang}.tm"))
    .to("mock:result")

请参阅此常见问题解答,了解有关“动态访问”的内容: