Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: file:outbound-channel-adapter : file extension ".writing" issue

  1. #1
    Join Date
    Nov 2009
    Posts
    2

    Unhappy file:outbound-channel-adapter : file extension ".writing" issue

    Hi,

    I am using quartz and spring integration to updates the file into local directory using file:outbound-channel-adapter. The file is writing to dir correctly only first time thereafter it is using ".writing" extension to write the file for the one which is already present. My requirement is to update the files and overwrite if present. I am using spring integration version 2.0. Pls. advice me how to overcome this problem.

    Thanks in Advance

    Ajay

  2. #2
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    Do you have a sample I could try out? Best would be in the form of a JUnit test. I'm not sure if I get your point.

  3. #3
    Join Date
    Nov 2009
    Posts
    2

    Default

    Quote Originally Posted by iwein View Post
    Do you have a sample I could try out? Best would be in the form of a JUnit test. I'm not sure if I get your point.
    I am in poc mode so I was pushing spring integration so lack junit test case.

    Sorry for not being clear with my question earlier ... Let me try to explain my problem again

    I have an application which is executed at regular interval to call specific web service and pull some String data. This string data is then written to the local directory using spring integration.

    So suppose first time it got file a.xml and b.xml. it is writing to local directory as a.xml and b.xml.

    In the second run, it again got a.xml and b.xml file but when S I is trying to write in local directory it writing it as "a.xml.writing" and "b.xml.writing" because a.xml/b.xml is already present in directory.

    some code snippet (in case i am doing something wrong)

    appcontext.xml

    ............
    <bean id="fileBasedHandler" class= .......
    <si:channel id="inputMessage"/>
    <si:channel id="outputFile"/>
    <file:outbound-channel-adapter channel="outputFile" directory="${file.directory.output}" auto-create-directory="true" filename-generator="fileBasedHandler" />
    ....................
    //fileBasedHandler.java

    public class FileBasedHandler extends DefaultFileNameGenerator{

    public FileBasedHandler(){
    super.setHeaderName("MSG_FILENAME");
    }


    //sending message as
    MessageChannel input = (MessageChannel)appContext.getBean("outputFile");
    msg=MessageBuilder.withPayload(strRule).setHeader( "MSG_FILENAME", currentRuleName).build();
    boolean sendStatus = input.send(msg);


    Appreciate you help

    Thanks

    Ajay

  4. #4
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    I think it might be the case that there are exceptions in your log? If you find those you will be able to track it to the FileWritingMessageHandler which might not be capable of overwriting files? If you manage to do that you could log an issue so we can add a flag to turn this on.

    I'm just guessing... without log messages / stacktraces / testcases you may assume I'm wrong.

  5. #5

    Default

    I encountered something similar (Spring-integration 1.0.3) and needed to make sure that I could over-write multiple versions of a file.

    I created a file renaming endpoint that checked for the existence of the file and, if found, renamed the previous version before passing the message on to the < file : outbound-channel-adapter/>

    Paul

  6. #6
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    614

    Default

    That sounds like a useful feature.

  7. #7

    Default

    I would contribute the code, but I think that perhaps a cleaner solution would be to add to FileWritingMessageHandler the following methods ...

    Code:
        /**
         * If true and the file already exists overwrite the original file.
         * @param overwrite true or false
         */
        public void setOverwriteFiles(final boolean overwrite);
    
        /**
         * If set and the file already exists use the filename generator to rename the previous version of the file. 
         * @param filenameGenerator used to create an alternative filename for the previous version of the file
         */
        public void setCollisionFileNameGenerator(final FileNameGenerator filenameGenerator);
    Of course it makes no sense to set both overwrite true and a collision filename generator.

  8. #8
    Join Date
    Jul 2010
    Posts
    139

    Default

    I'm seeing this same issue. All subsequent writes to a file after the first never make it to the destination file. The reason is because the rename from the *.writing file to the destination file is never successful. In my case at least, this seems to be inherent to the Win32FileSystem rename function.

    Like the previous poster, I think an option to overwrite the file if it already exists would be a nice edition to FileWritingMessageHandler. INT-1721 captures this issue.

  9. #9
    Join Date
    Aug 2009
    Location
    Paris, France
    Posts
    32

    Default

    Hi all,
    I cannot find anywhere in the last release 2.0.5 any option like this, does it exist ?
    The INT-1721 says it has been solved.

    Can you please help ? before i code it myself

    thank you very much

  10. #10
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Are you saying that it doesn't work for you. I mean right now it should override an existing file.

Posting Permissions

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