Announcement Announcement Module
Collapse
No announcement yet.
File-source name Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      Comment


      • #4
        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

        Comment


        • #5
          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

          Comment


          • #6
            Jira

            I've added a Jira entry for this issue.

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

            Thanks Mark for your help.

            Comment


            • #7
              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

              Comment


              • #8
                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

                Comment

                Working...
                X