具有正则表达式的Apache Camel Interceptor

时间:2017-10-17 15:17:27

标签: apache-camel

这是我的路线。我想将文件发送到Azure blob。我想将blob的名称设置为没有扩展名的文件名。我还想从文件名中过滤出空格。我正在考虑使用拦截器

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

我想仅为updateBlockBlob operatin

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

以上代码适用于interceptFrom()。

我尝试用像azure *即interceptSendToEndpoint(“azure *”)这样的通配符替换正则表达式。它不起作用

上述代码有什么问题?是因为收件人列表吗?

还有什么功能可以简单地删除空白区域? 有没有更好的方法动态生成blob名称?

1 个答案:

答案 0 :(得分:0)

以下是来自拦截器上驼峰的文档。

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

  • interceptFrom拦截路由中的传入Exchange。
  • interceptSendToEndpoint,在Exchange即将发生时拦截 被发送到给定的端点。

所以我怀疑Exchange已经形成,并且驼峰期望网址得到解决。 因此,需要在为Azure端点创建交换之前设置标头。

我做了以下事情。要设置标题,我使用interceptFrom,并将对象转换为File我使用了inteceptSendToEndPoint

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

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

管理也摆脱了空白