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
With:HTML Code:<int-file:outbound-channel-adapter id="fileBackup" directory="${integration.backupDirectory}" ... filename-generator="dailyFolderFileNameGenerator"/>
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(); }


Reply With Quote
