View Full Version : File-source name
watcher
Mar 12th, 2008, 09:47 AM
I've download the filesucker example posted in the blog section.
I see that the FileSucker class processes the polled directory.
However the method param is a String.
@Handler
public void suckAFile(String fileContents) {
LOGGER.debug(fileContents);
}
How can I get the orginal filename of the file been handled.
I've updated to the latest M2 version.
Thanks
watcher
Apr 8th, 2008, 04:30 AM
Let me try and rephase the question.
I want to poll a directory that contains files that will be uploaded into a database. The files will have a certain naming convention.
c:/temp
/AAAA_filename1.txt
/BBBB_filename2.txt
When I use the @Hanlder annotation the file is passed as a String.
How can I get access to the filename been handle so I can parse it and store these fields in the database?
Thanks
Mark Fisher
Apr 8th, 2008, 06:27 AM
I want to make sure I understand your use case. You basically want to use a FileSourceAdapter, but have it just pass the name of the file in a Message so that it can be processed later? In this case, the source adapter is not doing anything with the file itself?
Thanks,
Mark
watcher
Apr 8th, 2008, 09:00 AM
Yes, the file is already processed by a another application (PERL). When the file is processed by the perl application it will be placed in a folder where I had hoped to use the filesourceadapter to take the file and place it on a webserver and create a database entry for the file.
The filename would contain keys that would tell me which file belonged to which user.
The contents of the file are not really important to me, rather the filename itself.
I also see a use case were I would like to route a file based on its file name. for e.g if it has the text 'error' in it filename I'd like to route it to a different output directory.
I've since done this with Apache camel.
public class CamelRouteComponent extends RouteBuilder {
protected final Log log = LogFactory.getLog(getClass());
public void configure() throws Exception {
from("file:c:\\temp").convertBodyTo(File.class).to("bean:fileuploadService?methodName=process")
.setHeader(FileComponent.HEADER_FILE_NAME, el("${in.file.name}"));
}
}
Thanks
Paddy
Mark Fisher
Apr 8th, 2008, 09:22 AM
One way to accomplish this currently is to implement the MessageMapper interface. The input would be a java File object, you can then return a Message whose payload is just the filename. Then, simply call setMessageMapper(fileNameMapper) on the adapter.
I think this would be a good feature to have built-in. Could you create a JIRA issue for it here?: http://jira.springframework.org/browse/INT
Thanks,
Mark
watcher
Apr 8th, 2008, 09:59 AM
I've added a Jira entry for this issue.
http://jira.springframework.org/browse/INT-185
Thanks Mark for your help.
sannederoever
Apr 15th, 2008, 02:19 AM
Hi Mark,
An alternative method could be to store the filename in a property. It could be possible to make that a URL:
file://localhost:/tmp/input-dir/temp.txt
so that alternatives such as:
ftp://sanne@remotehost:/home/sanne
pop3://sanne@mailhost:20:/Inbox/${Message-Id}
Are possible. This would basically be an input reference.
The exact URL schemes would have to be researched, I could look into that.
Rgrds,
Sanne
Mark Fisher
Apr 15th, 2008, 05:37 AM
In the latest version (as of a few days ago actually), the filename is available in the header properties. The key is defined as a constant: FileNameGenerator.FILENAME_PROPERTY_KEY
That said, we will still likely change the *default* behavior to return a File instance as the Message payload while leaving the option to convert to String or bytes in the adapter (with a slight change in configuration).
Thanks for the feedback.
Mark
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.