Apache Camel as file explorer - apache-camel

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:
the file component to gather local directories content
the sftp component to gather remote directories content
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:
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
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
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
/root/file1.txt
/root/sub-dir-2/file2.txt
(no sub-dir-1, which doesn't directly contains files).
So, my questions are:
Is Apache Camel the right choice?
Is there a better way, in Apache Camel, to navigate a given directory?
Is it possible, in Apache Camel, to retrieve information about empty directories too?

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.

Related

Move files from the import directory into archive using Apache Camel

I have a requirement to move all files from the import directory monitored by Camel into another directory. For that I used the move and moveFailed options of Camel in my route.
I have a MaxFilesAllowedInArchive parameter in a properties files and if the file limit is exceeded, the oldest file has to be deleted.
How can I make a custom move and moveFailed to control the number of files moved and to keep latest files in archive?
Camel doesn't have a component that operates off of filesystem meta data (such as counts and dates), but you can easily implement this using a customer processor that uses the new Java Paths and Files API's.
Create a timer/quartz route that calls to a customer processor. In this customer processor, list files in your "move" and "moveFailed" directory to count the contents (and sort by date). If the MaxFilesAllowsInArchive is exceeded, then delete X number of files from the folders.

Reading data organised in folders with Codename one

I've got data generated by a desktop application. These data are organized in a 2-levels folders system : each folder is a physical representation of one object, with an image file, a property file and different text files. There is no way I can change this structure.
I'm willing to show these data with a mobile application. I started something with Intel XDK, but I feel more comfortable with java. So I'm building a POC with Codename One. The final goal is to get these data on the mobile device with a DropBox integration. But for now (in dev phase), I'm going to manually download the data in a user folder on the device.
In netbeans, I put a sample of these data in the src/ folder, but when I try to read them, I've got an error telling me that nested directories are not allowed:
ERROR: resources cannont be nested in directories in Codename One! Invalid resource: /00002/page.properties
Any suggestion on how I can move on with the development, using with static folders ?
Resource files must be placed in the root of the src directory to be packaged and can't be deeper. The reasoning is that we don't generate a JAR but rather a native package where hierarchies are pretty different.
If you need this exact structure just extract them into the FileSystemStorage on the first activation then you can use the hierarchy that's available there.

Dart: Accessing a resource out side the project|web/ directory

I have a web-app(browser based) which needs to access a folder full of icons that resides outside the web folder.
This folder MUST be outside the web folder, and would ideally exist outside the project folder all together
however, when specifying the path to the folder neither "../" or making use of a symlink will work
when the page attempts to load the image I always get
"[web] GET /Project|web/icons/img.png => Could not find asset Project|web/icons/img.png."
however I set the image source to "../icons/img.png"
how can i get dart to access this file properly
PS: I attempted a symlink to another part of the filesystem (where the images would be kept ideally) however this did not work either.
The web server integrated into DartEditor or pub serve only serves directories that are added as folders to the files view. When you add the folder to DartEditor you should be able to access the files. This is just for development.
You have also to find a solution for when you deploy your server app. It would be a hazardous security issue when you could access files outside the project directory. Where should the server draw the line? If this would be possible your entire server would be accessible to the world.
Like #Robert asked, I also have a hard time imaging why the files must not be in the project folder.
If you want to reuse the icons/images between different projects you could create a resource package that contains only those images and add them as a dependency to your project.
If you want a better answer you need to provide more information about your requirements.
If you wrote your own server (by using the HttpServer class) it may be possible to use the VirtualDirectory to server your external files.
Looking at look the dartiverse_search example may give you some ideas.
You could put them in the lib directory and refer to them via /packages/Project/...
Or in another package, in which case they would be in a different place in the file system. But as other people have said, your requirement seems odd.

I have a huge music archive on a remote server. How can I set up a page that lets people interact with it?

What I want to have is some sort of file tree that people can interact with and download songs or folders of songs. I kinda got started with a file listing PHP script (which you can see here) but it requires me to copy the same index.php to every individual folder. I would be okay with this if I knew how to copy the same file to every subdirectory in the archive.
What do you guys think? Any ideas?
What you do is to use your webserver to browse the file hierarchy. But what you want is to use your script (the index.php). So instead of creating links that point to a deeper place in your file system, create links that point to your index.php, but add a parameter that tells the script the (relative) folder. Beware that you have to verify that only files can be shown that you actually want to make public (i.e. no files above your "entry" directory).

Reading Properties of all Files existing in one of the folders on Application Server and print on a JSP

I have to read the Name and Creation Date/Last Modified Date of all the files that may exist on /product/xyz folder, existing on JBoss Application Server and print the same on JSP.
This folder is being loaded with the fresh files when server is booted. The framework used is Struts 1.2.
Any hints or examples around how to read these information and print on JSP? Thanks!
EDIT :
I understand that it is much easy to read the files from a folder which might be part of my workspace folder. But, this is a different scenario.
Here, the JSP file will be deployed on JBoss application server, in some ABC folder, as part of some EARs. On the same application server, there is some other XYZ location, which will be loaded with the fresh files, when server is booted. I want to read the files existing in that XYZ folder. I Hope the scenario is more clear now.
The code doesn't change whether I try to access the files from my Work Space folders (Rather, which are to be part of EARs) or I may access from the Server File System (Outside the EARs).
The issue could be there in Path Mentioned or the Permission (Read/Write) to the Folder from which the files are being read.

Resources