它可能取決於你的駱駝版本。
從的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」值,它是空的。 –
謝謝,它可能會幫助他人回答你的問題。我不是這種技術的專家;)。 –