首页 > 解决方案 > Apache Camel as file explorer

问题描述

I need a way to show the content of a (remote) directory and, since the main application makes an intensive use of Apache Camel, I would like to rely on Apache Camel once more to accomplish this task.

So, the goal is to have a file explorer view which lists the base directory content (directories and files) and, by clicking on a given directory, the view should be refreshed by showing its content, and so on... a sort of FTP client (e.g. WinSCP, FileZilla, etc.) to let the user navigate a directory, which could be remote or local, depending on the context.

If I had to do it with Apache Camel, I would use:

Then, starting from the given base directory, I would use recursive=true to retrieve its full content (so, all files contained by the base directory and all sub-directories). That way, by mapping the result in a tree and keeping it in memory, I would be able to identify the directories structure and show to the user only a specific sub-set of information, depending on its navigation.

However, this approach has at least three side-effects:

  1. since the full structure is immediately retrieved at once, it wouldn't be possible to lazy load the given node, accordingly to the user navigation
  2. at the same way, it would be necessary to keep the full structure in memory, even if the user is viewing a leaf containing, for instance, a single file
  3. it wouldn't be possible to show empty directories... as far as I know, in fact, Camel reads files only so, in case a directory /D contains the file F.txt and the empty directory /E, the Camel component would return /D/F.txt but not /D/E, which is a directory

Points 1 and 2 could probably be fixed by specifying a maxDepth=2, in order to identify all files and all directories of the current level... but, again, considering the following structure:

root
|_ file1.txt
|_ sub-dir-1
   |_ sub-dir-1-A
      |_ nested-file.txt
|_ sub-dir-2
   |_ file2.txt

The file component, starting from root and having recursive=true and maxDepth=2, would only return

(no sub-dir-1, which doesn't directly contains files).

So, my questions are:

  1. Is Apache Camel the right choice?
  2. Is there a better way, in Apache Camel, to navigate a given directory?
  3. Is it possible, in Apache Camel, to retrieve information about empty directories too?

标签: apache-camelftp-clientcamel-ftpcamel-file

解决方案


Ad 1) Probably not - its an integration library, not a directory listening tool

Ad 2) No its not a directory listening tool

Ad 3) No its for files only.


推荐阅读