Results 1 to 8 of 8

Thread: File-source name

  1. #1
    Join Date
    Jul 2007
    Posts
    25

    Default File-source name

    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.

    Code:
    @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

  2. #2
    Join Date
    Jul 2007
    Posts
    25

    Default Filename

    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

  3. #3
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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

  4. #4
    Join Date
    Jul 2007
    Posts
    25

    Default Filename

    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.

    Code:
    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

  5. #5
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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

  6. #6
    Join Date
    Jul 2007
    Posts
    25

    Default Jira

    I've added a Jira entry for this issue.

    http://jira.springframework.org/browse/INT-185

    Thanks Mark for your help.

  7. #7

    Default Input reference

    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

  8. #8
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,853

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •