【问题标题】:Camel simple expression language - How to get property value dynamicallyCamel 简单表达式语言 - 如何动态获取属性值
【发布时间】:2017-04-01 07:14:51
【问题描述】:

我是 Camel 的新手,我使用简单的表达式从 Java DSL 中的属性文件中获取值。

.setProperty("PortalUrl", simple("properties:Portal.url"))

属性文件值 -
Portal.url=abc.com/example

但是现在我需要从属性文件中获取客户特定的 URL。 示例值 -

Portal.url.customer1=abc.com/example/abcd Portal.url.customer2=abc.com/example/xyz

客户名称来自请求本身,所以我想这样做
.setProperty("PortalUrl", simple("properties:Portal.url."+"${body.customerName}"))

但上面的代码不起作用,它给了我 PortalUrl 属性的值为properties:Portal.ulr.customer1

当我尝试使用直接硬编码值时,它会从属性文件中给我正确的 URL - .setProperty("PortalUrl", simple("properties:Portal.url."+"customer1"))

它返回了正确的值 - abc.com/example/abcd

但我想动态获取 URL 作为传入请求中的客户名称。 任何人都可以帮助我,并解释简单的工作原理。

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    您是否尝试过使用简单语言的${body} 函数:

     .setProperty("PortalUrl", 
         simple("${properties:Portal.url.${body.customerName}}"))
    

    【讨论】:

    • 哦,不知道你能做到,TIL ^^
    • 嗨克劳斯,我也试过这个,但它也不起作用,${body.customerName} 被视为正常字符串值,代码给出错误,因为没有找到 Portal.url.${属性文件中的 body.customerName}。
    • 它对我有用,您使用的是哪个版本的 Camel?
    • 我正在使用 - 2.17.0
    • 它也对我有用......早些时候我错过了开始的'$'符号。谢谢克劳斯易卜生和谢谢米洛什米利沃耶维奇:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多