它可能取决于你的骆驼版本。
从的simple expression language
从骆驼2.9的文档起,可以嵌套函数,如下面所示:
<setHeader headerName="myHeader">
<simple>${properties:${header.someKey}}</simple>
</setHeader>
下面的代码片段骆驼2.17.1
测试
public class NestedTest extends CamelSpringTestSupport {
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("route.xml");
}
@Override
public void setUp() throws Exception {
deleteDirectory("target/inbound");
super.setUp();
}
@Test
public void nested() throws InterruptedException {
getMockEndpoint("mock:end").expectedMessageCount(1);
template.sendBodyAndHeader("file://target/inbound",
"hello camel",
Exchange.FILE_NAME,
"filename.in"
);
assertMockEndpointsSatisfied();
}
}
route.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://target/inbound"/>
<setHeader headerName="dateFormat">
<simple resultType="java.lang.String">ddMMyyyyHHmmss</simple>
</setHeader>
<setHeader headerName="startTime">
<simple resultType="java.lang.String">${date:now:${header.dateFormat}}</simple>
</setHeader>
<log message="header timestamp: ${header.startTime}"/>
<to uri="mock:end"/>
</route>
</camelContext>
</beans>
输出
15:58:57 INFO route1 - header timestamp: 07062016155857
15:58:56 INFO MockEndpoint - Asserting: Endpoint[mock://end] is satisfied
15:58:57 INFO NestedTest - *************************************************
15:58:57 INFO NestedTest - Testing done: nested(camelinaction.NestedTest)
15:58:57 INFO NestedTest - Took: 1.010 seconds (1010 millis)
15:58:57 INFO NestedTest - *************************************************
你能不能给我们的错误? :) –
对不起,有没有异常抛出,当我获取“startTime”值,它是空的。 –
谢谢,它可能会帮助他人回答你的问题。我不是这种技术的专家;)。 –