Announcement Announcement Module
Collapse
No announcement yet.
DailyFolderAppender in a File outbound channel adapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DailyFolderAppender in a File outbound channel adapter

    Hello,

    I need to create files in a similar fashion that DailyFolderAppender does with the log files in log4j: in an output directory, a folder per day. And there the resulting files.

    See http://www.codeproject.com/Articles/...older-Appender

    I'd like to use the Spring Integration namespace, so I've created a file name generator that, besides returning the file name from a Message, it creates the appropriate directories when necessary.

    Does this approach go against the expected behaviour of a Spring Integration file outbound channel adapter?

    Thanks


    HTML Code:
    <int-file:outbound-channel-adapter id="fileBackup" directory="${integration.backupDirectory}" ... filename-generator="dailyFolderFileNameGenerator"/>
    With:

    Code:
    @Component
    public class DailyFolderFileNameGeneratorimplements FileNameGenerator {
    
    	@Value("${integration.backupDirectory}")
    	private String dir;
    
    	public String generateFileName(Message<?> message) {
    		
    		MessageHeaders headers = message.getHeaders(); //If necessary
    
    		//Obtain INFO to enrich the base folder
    
    		File folder = new File(dir);
    
    		//Append the INFO from the Header and the current date to the folder File
    
    		if (!folder.exists()) {
    			if (!folder.mkdirs())
    				throw new MessageHandlingException(message, "failed to write Message payload to file. Can't create the daily folder appender with some data from the Header: "+folder.getAbsolutePath());
    		}
    
    		sb = new StringBuilder();
    		sb.append(folder.getAbsolutePath())
    			.append(File.separator)
    			.append(message.getPayload().getName()) //Assuming we have a File
    		;
    
    		return sb.toString();
    	}

  • #2
    I dont't think so. Its actually pretty cool!

    Comment


    • #3
      You flatter me

      Comment

      Working...
      X