嗨,
在文件夹上使用文件使用者时,骆驼上下文无法访问(例如,使用chmod a-rwx test/locked
),上下文将正常启动(甚至没有警告),但也不会拾取其中的任何文件文件夹(嗯,应该怎么办)。
当无法访问文件夹时,是否有办法使文件组件在启动时(或至少在轮询文件夹时)抛出错误?
否则,在配置路由之前,我将不得不使用手动Java代码对其进行检查,
感谢和问候
克里斯
答案 0 :(得分:1)
否则,在配置路由之前,我将不得不使用手动Java代码对其进行检查,这是我想避免的。
您可以将PollingConsumerPollStrategy与端点一起使用,以检查路径是否存在访问问题,然后引发错误。
public class FileAccessPollingConsumerPollStrategy extends DefaultPollingConsumerPollStrategy{
public boolean begin(Consumer consumer, Endpoint endpoint) {
File pollingDirectory = ((FileEndpoint) endpoint).getFile();
//check your access with poillingDirectory and raise any error.
return true;
}
}
然后配置您的骆驼端点-from("file://inbox/?pollStrategy=#fileAccessPollingConsumerPollStrategy")
答案 1 :(得分:0)
我决定在配置路由之前执行以下代码,从而确保可以对其进行访问:
Path path = Paths.get(folderPath);
// The only case we do not allow is when the folder exists and is not readable
boolean canAccess = !Files.exists(path) || Files.isReadable(path);
if (!canAccess) {
throw new IllegalArgumentException("Could not initialize route, because folder \""
+ baseFolder + "\" can not be accessed. This might happen when it does not exist "
+ "or there are no read permission for the current user");
}
我还在apache jira中创建了一个问题,以在将来添加该功能:
https://issues.apache.org/jira/browse/CAMEL-13483
感谢大家的建议
克里斯