问题描述
我注意到Camel-FreeMarker的2.25.2版中有一个奇怪的行为,我想知道这是否是库中的错误。在2.25.1版本或其他2.xx.x版本中不会发生这种情况。
在单元测试期间发生以下错误:
SEVERE: Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> exchange [in template "email.ftl" at line 5,column 55]
模板email.ftl包含:
"${exchange.properties.CamelExceptionCaught.message}"
根据Camel-FreeMarker documentation,“ exchange”和“ exchange.properties”应为模板中的有效标识符。
目前,我的解决方案是使用2.25.1版而不是2.25.2版,但我想知道是否还有其他解决方案。
解决方法
出于安全考虑,在所有Apache Camel模板组件中的2.25.2
和3.4.0
中,CAMEL-15050中都默认禁用了此功能。要启用较早的行为,可以使用选项allowContextMapAll=true
。
请参见Camel Freemarker 2.25.x docs:
allowContextMapAll-设置上下文映射是否应允许访问所有详细信息。默认情况下,只能访问邮件正文和标头。可以启用此选项以完全访问当前Exchange和CamelContext。这样做会带来潜在的安全风险,因为这将开放访问CamelContext API的全部功能。