简体   繁体   English

如何在Apache Camel 2.14.1的Hashmap中访问属性?

[英]How can I access to a property in a Hashmap in Apache Camel 2.14.1?

I'm pretty new working in Camel, I have the next doubt, how can I access to a property in a HashMap in Apache Camel 2.14.1? 我是在Camel工作的新手,还有一个疑问,我该如何访问Apache Camel 2.14.1的HashMap中的属性?

I have the next declared bean 我有下一个声明的bean

    <bean id="mapRegion" class="java.util.HashMap">
        <constructor-arg>
            <map key-type="java.lang.String" value-type="java.lang.String">
                <entry key="R01" value="one" />
                <entry key="R02" value="two" />
            </map>
        </constructor-arg>
    </bean>

If I print the map with camel, I can see the values 如果我用骆驼打印地图,我可以看到值

<log message="*** MAP = ${ref:mapRegion}" loggingLevel="DEBUG" />
*** MAP = {R02=two, R01=one}

How can I access to an especific property in the map? 如何访问地图中的especific属性? I have tried with 我尝试过

<log message="*** MAP = ${ref:mapRegion.R01}" loggingLevel="DEBUG" />
<log message="*** MAP = ${ref:mapRegion[R01]}" loggingLevel="DEBUG" />
<log message="*** MAP = ${ref:mapRegion['R01']}" loggingLevel="DEBUG" />

But non of this are working, always is printing empty value. 但是这些都不起作用,总是在打印空值。

Thanks in advance 提前致谢

The solution that I found to this is the next 我找到的解决方案是下一个

        <setProperty propertyName="SERVICE_REGION">
            <simple>${bean:mapRegion?method=get(${property.phoneRegion})}</simple>
        </setProperty>

Using the bean and the id of the bean, we can invoke a specific method of the HashMap, and we can send the key that we are trying to retrieve 使用Bean和Bean的ID,我们可以调用HashMap的特定方法,并可以发送尝试检索的密钥。

That is not supported by the ref function in the simple language to refer to a bean and do OGNL or map lookups. 简单语言的ref函数不支持ref Bean并进行OGNL或映射查找。

And btw what is your use-case for this. 顺便说一句,您的用例是什么。 You just seem to log it at DEBUG level. 您似乎只是将其记录在DEBUG级别。 But what is the business use-case/value of doing that. 但是,这样做的业务用例/价值是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM