Apache正规表达式骆驼拦截器
问题描述:
这是我的路线。我想将文件发送到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名称?
答
这是来自骆驼拦截器的文档。
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]")))
设法
摆脱空白的太