java 如何将标头设置为 Apache Camel 中的属性文件中的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14038561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:50:54  来源:igfitidea点击:

How to set a header to a value from a properties file in Apache Camel

javaapache-camel

提问by Ahmad Y. Saleh

Is it possible to set a message header to a value read from a properties file, using the camel Properties Component? I can set such properties to URI options, but I'm unable to set them as a header values.

是否可以使用骆驼属性组件将消息头设置为从属性文件读取的值?我可以将此类属性设置为 URI 选项,但我无法将它们设置为标头值。

I need something like this:

我需要这样的东西:

<camel:setHeader headerName="actionId">
    <camel:constant>{{onus.transPosting.RtSFailed}}</camel:constant>
</camel:setHeader>

where onus.transPosting.RtSFailedis a property key set on a file imported using camel Properties Component.

onus.transPosting.RtSFailed使用骆驼属性组件导入的文件上设置的属性键在哪里。

Note: I'm using Apache Camel 2.10.1

注意:我使用的是 Apache Camel 2.10.1

UPDATE

更新

Using the <propertyPlaceholder>as suggested by this discussiondid not work and it causes an exception:

使用本讨论中<propertyPlaceholder>建议的无效并导致异常:

Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: onus.transPosting.RtSFailed

Caused by: org.apache.camel.language.simple.types.SimpleParserException: Unknown function: onus.transPosting.RtSFailed

回答by Claus Ibsen

Yes you can, use the simple language which has a properties function: http://camel.apache.org/simple

是的,您可以使用具有属性功能的简单语言:http: //camel.apache.org/simple

<camel:setHeader headerName="actionId">
    <camel:simple>${properties:onus.transPosting.RtSFailed}</camel:simple>
</camel:setHeader>

Though I think we have fixed in latest Camel releases that < camel:constant > will resolve property placeholders as well.

虽然我认为我们已经在最新的 Camel 版本中修复了 <camel:constant> 也将解析属性占位符。