Announcement Announcement Module
Collapse
No announcement yet.
file:outbound-channel-adapter : file extension ".writing" issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Because they can be dynamiccally instanciated at runtime.

    Comment


    • #17
      Ok, since you are creating it yourself, would you be able to compile a test case that reproduces this issue and attach it to this forum and I'll take a look?

      Comment


      • #18
        oh, it seems the .writing file is overwritten correctly, but not the original !

        Comment


        • #19
          so, to sum up :

          first time file created correctly with filename
          second time, second file created called : filename.writing
          then after : file filename.writing overwritten but original file never changes

          thanks

          Comment


          • #20
            Hi Oleg,

            Please find an example of what i've described just in previous post.
            Here is my spring integration XML file (at least the file writing part) :

            Code:
            <bean id="toStringTransformer" class="org.springframework.integration.xml.transformer.ResultToStringTransformer" />
              	<integration:channel id="toDiskChannel"></integration:channel>
              	<integration:channel id="testOutputChannel"></integration:channel>
              	
              	<si-xml:marshalling-transformer marshaller="testResultMessageMarshaller" 
              		output-channel="toDiskChannel" 
              		input-channel="testOutputChannel" 
              		result-transformer="toStringTransformer" />
              		
              	<file:outbound-channel-adapter channel="toDiskChannel" 
              		directory="${test.output.directory}">
              	</file:outbound-channel-adapter>
            Then in my code, when i send messages to this channel:

            Code:
            Message<GenericXMLMessageType> mess = MessageBuilder.withPayload(msg.getPayload()).
            			copyHeaders(fileContents.getHeaders()).
            			build();
            			
            			MessageChannel channel2 = (MessageChannel)ApplicationContextProvider.getApplicationContext().getBean("testOutputChannel");
            			channel2.send(mess);
            The first is written correctly, and the following message with identical filename produce a .writing file, which is correctly overwritten then (with following messages) :

            Attachment


            Thank you very much

            Max
            Attached Files

            Comment


            • #21
              Hi again,

              Sorry not coming with a full compiled test case, but i've looked at the source code in the spring-integration-file package, and i think the problem may come from that the rename function is not working, but its return value is not processed here :

              Code:
              private File handleFileMessage(File sourceFile, File tempFile, File resultFile) throws IOException {
              		if (this.deleteSourceFiles) {
              			if (sourceFile.renameTo(resultFile)) {
              				return resultFile;
              			}
              			if (logger.isInfoEnabled()) {
              				logger.info(String.format("Failed to move file '%s'. Using copy and delete fallback.",
              						sourceFile.getAbsolutePath()));
              			}
              		}
              		FileCopyUtils.copy(sourceFile, tempFile);
              		tempFile.renameTo(resultFile);
              		if (this.deleteSourceFiles) {
              			sourceFile.delete();
              		}
              		return resultFile;
              	}
              
              	private File handleByteArrayMessage(byte[] bytes, File originalFile, File tempFile, File resultFile) throws IOException {
              		FileCopyUtils.copy(bytes, tempFile);
              		tempFile.renameTo(resultFile);
              		if (this.deleteSourceFiles && originalFile != null) {
              			originalFile.delete();
              		}
              		return resultFile;
              	}
              
              	private File handleStringMessage(String content, File originalFile, File tempFile, File resultFile) throws IOException {
              		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), this.charset);
              		FileCopyUtils.copy(content, writer);
              		tempFile.renameTo(resultFile);
              		if (this.deleteSourceFiles && originalFile != null) {
              			originalFile.delete();
              		}
              		return resultFile;
              	}
              What about deleting src file first and then renaming the tempFile, if first rename failed (returned false) ?

              Thanks for your help

              Max

              Comment


              • #22
                getting error in constructor attribute..!!

                have to see first ..!!

                Comment


                • #23
                  What do you wanna see ?

                  Comment


                  • #24
                    Solved like this

                    Problem solved re-writing and subclassing FileWritingMessageHandler like follows :

                    Code:
                    @Override
                    	protected File handleStringMessage(String content, File originalFile, File tempFile, File resultFile) throws IOException {
                    		getLogger().debug("handling string message");
                    		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), this.getCharset());
                    		FileCopyUtils.copy(content, writer);
                    		renameTo(tempFile, resultFile);
                    		if (this.isDeleteSourceFiles() && originalFile != null) {
                    			originalFile.delete();
                    		}
                    		return resultFile;
                    	}
                    
                    
                    
                    	private void renameTo(File tempFile, File resultFile) {
                    		if (resultFile != null && resultFile.exists())
                    		{
                    		resultFile.setWritable(true,false);
                    		resultFile.delete();
                    		if (!tempFile.renameTo(resultFile))
                    			getLogger().debug("rename KO from " + tempFile.getAbsolutePath() + " to " + resultFile.getAbsolutePath());
                    		}
                    	else
                    		{
                    		if (!tempFile.renameTo(resultFile))
                    			getLogger().debug("rename KO from " + tempFile.getAbsolutePath() + " to " + resultFile.getAbsolutePath());
                    		
                    		}
                    	}
                    Thanks for you help.

                    Comment


                    • #25
                      @munger

                      Could you please rais a jIRA issue for that?

                      Comment


                      • #26
                        Done : INT-2278
                        Thanks !

                        Comment

                        Working...
                        X