2017-10-17 61 views
1

這是我的路線。我想將文件發送到Azure blob。我想將blob的名稱設置爲沒有擴展名的文件名。我也想過濾掉文件名中的空格。我想用一個攔截器Apache正規表達式駱駝攔截器

from("file://C:/camel/source1").recipientList(simple("azure-blob://datastorage/container1/${header.fileName}?credentials=#credentials&operation=updateBlockBlob")) 

我要調用的攔截只針對updateBlockBlob操作系

interceptSendToEndpoint("^(azure-blob:).+(operation=updateBlockBlob)").setHeader("fileName",simple("${file:onlyname.noext}")).convertBodyTo(File.class) 

上面的代碼可與interceptFrom()。

我嘗試用像azure *這樣的通配符替換正則表達式,即interceptSendToEndpoint(「azure *」)。它沒有工作

上述代碼有什麼問題?是因爲收件人列表嗎?

還有什麼功能簡單地刪除空白? 有沒有更好的方式來動態生成blob名稱?

回答

0

這是來自駱駝攔截器的文檔。

http://camel.apache.org/intercept.html

  • interceptFrom截獲的路線進入交易所。
  • interceptSendToEndpoint截獲當Exchange將要發送到給定端點的 。

所以我懷疑Exchange已經形成,駱駝期望url被解決。 因此,在爲Azure端點創建交換之前需要設置標題。

我做了以下事情。要設置標題,我用的是interceptFrom,並且將對象轉換成文件我用inteceptSendToEndPoint

interceptSendToEndpoint("^(azure-blob:).+(operation=updateBlockBlob)").convertBodyTo(File.class) 

interceptFrom().setHeader("fileName",simple("${file:onlyname.noext}".replaceAll("[^a-zA-Z\d]"))) 

設法

擺脫空白的太