2016-04-28 131 views
2

我想在我的过程方法中设置一些属性,但我无法弄清楚如何在xml中使用这些属性,就像我可以轻松地在xml中使用标题值使用语法:$ {} in.header.myKey骆驼 - 在春季使用财产DSL

这里是我的代码:

<route> 
     <from uri="activemq:queue:start.queue" /> 
      <to uri="stream:out" /> 
      <process ref="jsonProcessor"></process> 
      <to uri="bean:validateInputIdentifiers?method=validation(${in.property.SourceMap}, ${in.property.DestinationMap})" /> 
    </route> 

这里in.property.SourceMap是未知的功能。什么是正确的方法? 如果它是类似于标题的话,它会很棒。此外,我想仅使用属性而不是标题,因为标题的值可能不会在我的路线中保留。

这里的处理方法的代码:

@Override 
public void process(Exchange exchange) throws Exception { 
    List<Map<String, String>> body = exchange.getIn().getBody(List.class); 
    Map<String, String> sourceMap = body.get(0); 
    Map<String, String> destinationMap = body.get(1); 
    exchange.setProperty("SourceMap", sourceMap); 
    exchange.setProperty("DestinationMap", destinationMap); 

} 

请提供了解决方案。

回答

2

命中和庭审后,我得到了工作液:

<route> 
     <from uri="activemq:queue:start.queue" /> 
      <to uri="stream:out" /> 
      <process ref="jsonProcessor"></process> 
      <to uri="bean:validateInputIdentifiers?method=validation(${property.SourceMap}, ${property.DestinationMap})" /> 
    </route> 
6

可能有多个解决方案组合,为您的问题。

示例属性键和值。

<cm:property name="app.user" value="PROD008"/> 

在路由如果你想设置具有属性值的标题。使用下面的代码片段。

<setHeader headerName="password"> 
    <simple>${properties:app.user}</simple> 
</setHeader> 

如果你想使用属性,你可以使用下面的代码片段。

<to uri="{{some.endpoint}}"/> 

对于你的例子:如果属性是SourceMap和DestinationMap,你可以使用下面的任何一个。

1. <to uri="bean:validateInputIdentifiers?method=validation(${property.SourceMap}, ${property.DestinationMap})" /> 

2. <to uri="bean:validateInputIdentifiers?method=validation({{SourceMap}},{{DestinationMap}})" /> 

如果要使用标题而不是属性,请使用下面的代码片段。

<to uri="bean:validateInputIdentifiers?method=validation(${header.SourceMap}, ${header.DestinationMap})" />