Apache camel Apache Camel访问字符串模板中的头值
我的问题是,我不知道如何在字符串模板声明中访问exchange的头值。我想有国际化的邮件模板。下面的测试代码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
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")
请参阅此常见问题解答,了解有关“动态访问”的内容: