2016-04-28 125 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})" />