2016-05-12 114 views
0

我試圖通過屬性值動態地將傳遞給URI值。該屬性值將在cfg文件中進行配置。基於文件名/ cfg文件/屬性名稱的動態URI

當使用CamelFileNameOnly頭提取文件名時,它必須傳遞到to Uri端點。因此代碼中提到了同一個名字。

請在下面找到我的代碼:

我在我的服務器位置= d下降與名KevinFile.txt文件:\服務器\ jboss的熔絲,6.2.0.redhat-133 \ DATA \ myLocalFTP(文件://數據/ myLocalFTP)

配置文件

local.folder.url=file://data/myLocalFTP 
KevinFile=file://data/KevinFileDirectory 

駱駝路線

<route id="awsRoute"> 
     <from uri="{{local.folder.url}}"/> 
     <bean ref="processorClass" method="process"/> 
     <log message="myProperty value is ${exchangeProperty.myProperty}"/> <---Gives the fileName 
     <to uri="{{${exchangeProperty.myProperty}}}"/>  <--This is the spot i am getting error :( 
</route> 

ProcessorClass.java

public class ProcessorClass implements Processor{ 
@Override 
     public void process(Exchange exchange) throws Exception { 

       String fileName = (String) exchange.getIn().getHeader("CamelFileNameOnly"); 
       exchange.setProperty("myPropertyNew", fileName); 

     } 
} 
+1

凱文,我很困惑與你試圖完成什麼都可以嘗試,以提高描述了一下,重點是你的目標是什麼? –

+0

您好Mathew,我需要傳遞「uri」組件中的Propery「文件名」,以便它將引用具有相似名稱的cfg文件並將文件放在指定位置。 –

回答

0

啊你想找的,就是設定頭作爲屬性。你可以是這樣做的:

from("direct:start") 
    .setHeader("CamelFileNameOnly").simple("{{myPropertyName}}") 
    .to("file://data/myLocalDisk"); 

您還可以通過使用文件組件上可用的URI語法在此情況下(感謝謝爾蓋·對於推薦)簡化此。只要確保你檢查每個組件的駱駝文檔,某些組件依賴於交換頭,而另一些組件可以利用URI屬性。

from("direct:start") 
    .to("file://data/myLocalDisk?fileName={{myPropertyName}}"); 

它也是值得注意的是,如果你有你想要設置頁眉前使用的邏輯可以讓打電話的setHeader豆。

from("direct:start") 
    .setHeader("CamelFileNameOnly").bean(MyPropertyLogicBean.class, "someMethod({{myPropertyName}})") 
    .to("file://data/myLocalDisk"); 

使用駝峯屬性組件來獲得該屬性來解決。

參考:http://camel.apache.org/properties.html

+1

更好因爲問題出在Spring DSL –

+0

@SergiiPozharov謝謝我會將這個簡化添加到我的答案中 –

0

如果我理解正確的話,你需要指定生產者的不變部分「動態」 vlue。取而代之的<to uri="{{${exchangeProperty.myProperty}}}"/>可以使用recipientList或routingSlip:

<recipientList> 
    <simple>${exchangeProperty.myProperty}</simple> 
</recipientList> 

<routingSlip> 
    <simple>${exchangeProperty.myProperty}</simple> 
</routingSlip>