Results 1 to 3 of 3

Thread: DailyFolderAppender in a File outbound channel adapter

  1. #1
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default 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. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

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

  3. #3
    Join Date
    May 2006
    Location
    Madrid
    Posts
    382

    Default

    You flatter me

Posting Permissions

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