PDA

View Full Version : file outbound-channel-adapter filename-generator not working?



corani
Sep 24th, 2009, 08:40 AM
I'm using Spring Integration 1.0.3.RELEASE, and have troubles getting the filename-generator to work.

My spring configuration is as follows:



...
<integration:channel id="file-channel" />
<file:outbound-channel-adapter directory="/tmp/integration" channel="template-channel" filename-generator="filename-generator" />
<bean id="filename-generator" class="some.FileNameGenerator" />
...


The implementation of the filename generator is as follows:


public class FilenameGenerator extends DefaultFileNameGenerator {

@Override
public String generateFileName(Message<?> message) {
System.out.println("generateFileName(" + message.getPayload() + ")");
String filename = super.generateFileName(message);
System.out.println("Generate filename: " + filename);
if (message.getPayload() instanceof SomeMessage) {
filename = "example_filename.txt";
}
System.out.println("Generate filename: " + filename);

return filename;
}
}


I see the filename-generator getting called, but no file is written to disk. When I replace "some.FileNameGenerator" with "org.springframework.integration.file.DefaultFileNa meGenerator" no file is written either. When I remove the filename-generator attribute, the file gets written.

Am I doing something wrong, or is this a bug?

Mark Fisher
Sep 24th, 2009, 09:13 AM
I'll try to reproduce this. If it's behaving as you described, then it is a bug. Maybe something else is happening.

corani
Sep 24th, 2009, 09:39 AM
For now I've solved it by adding a FileHeaders.FILENAME header, but I'm curious if you can reproduce this, or if I made a mistake somewhere!

By the way, is it somehow possible to let the outbound-channel-adapter create sub-directories? Or do I have to write my own FileWritingMessageHandler for that?

Use-case: I would like to write my files to BASE/YYYY-mm-dd/id.msg

Mark Fisher
Sep 25th, 2009, 11:35 AM
Actually, we have been planning to add support for dynamic generation of the outbound directory (or sub-directories). In fact, it's part of a general trend for making output targets more dynamic (e.g. WebService URI with DestinationProvider strategy, etc.).

Could you please create a new issue in JIRA with a brief description of your use-case?

Thanks,
Mark

corani
Sep 25th, 2009, 03:18 PM
I opened INT-805 (jira.springframework.org/browse/INT-805) about dynamically creating directories.

iwein
Oct 4th, 2009, 02:52 AM
Is the problem with generating fileNames resolved now? If not, could you create and issue for that too?

armandlek16
Oct 11th, 2010, 05:22 AM
What is the status of this feature? I need to be able to use the same use case for dynamic outbound subdirectories.

devnullable
Dec 28th, 2010, 03:40 AM
What is the status of this feature?I just voted this one on Jira. Is there anything going on with this one?

Mark Fisher
Jan 3rd, 2011, 08:46 AM
What version of Spring Integration are you using now? The main reason I ask is that if we do address the issue, it will most likely be in an upcoming 2.0.x release.

devnullable
Jan 4th, 2011, 02:27 AM
What version of Spring Integration are you using now?I am using 2.0.1.RELEASE.

As a side note. Funny that Maven Repository (http://mvnrepository.com/artifact/org.springframework.integration/spring-integration-core) is showing 2.0.0.RELEASE as the latest version.