OPEN - issue INT-518: inconsistent configuration opportunities in file:inbound-channel-adapter and file:outbound-channel-adapter directory attribute
http://jira.springframework.org/browse/INT-518 Added "file:" prepending default strategy to the FileOutboundChannelAdapterParser (and some trivial fixes)
This commit is contained in:
@@ -20,8 +20,6 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A convenience base class for any {@link FileListFilter} whose criteria can be
|
||||
* evaluated against each File in isolation. If the entire List of files is
|
||||
|
||||
@@ -18,9 +18,11 @@ package org.springframework.integration.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
@@ -41,6 +43,7 @@ import org.springframework.util.FileCopyUtils;
|
||||
* method by the {@link org.springframework.integration.transformer.ObjectToStringTransformer}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FileWritingMessageHandler implements MessageHandler {
|
||||
|
||||
@@ -50,13 +53,14 @@ public class FileWritingMessageHandler implements MessageHandler {
|
||||
|
||||
private volatile Charset charset = Charset.defaultCharset();
|
||||
|
||||
|
||||
public FileWritingMessageHandler(String parentDirectoryPath) {
|
||||
this(new File(parentDirectoryPath));
|
||||
}
|
||||
|
||||
public FileWritingMessageHandler(File parentDirectory) {
|
||||
this.parentDirectory = parentDirectory;
|
||||
public FileWritingMessageHandler(Resource parentDirectory) {
|
||||
try {
|
||||
this.parentDirectory = parentDirectory.getFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,9 +25,12 @@ import org.springframework.integration.config.xml.AbstractOutboundChannelAdapter
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <outbound-channel-adapter/> element of the 'file' namespace.
|
||||
* Parser for the <outbound-channel-adapter/> element of the 'file'
|
||||
* namespace.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*
|
||||
*/
|
||||
public class FileOutboundChannelAdapterParser extends AbstractOutboundChannelAdapterParser {
|
||||
|
||||
@@ -37,8 +40,11 @@ public class FileOutboundChannelAdapterParser extends AbstractOutboundChannelAda
|
||||
if (!StringUtils.hasText(directory)) {
|
||||
parserContext.getReaderContext().error("directory is required", element);
|
||||
}
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
"org.springframework.integration.file.FileWritingMessageHandler");
|
||||
if (directory.indexOf(':') == -1) {
|
||||
directory = "file:" + directory;
|
||||
}
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition("org.springframework.integration.file.FileWritingMessageHandler");
|
||||
builder.addConstructorArgValue(directory);
|
||||
String fileNameGenerator = element.getAttribute("filename-generator");
|
||||
if (StringUtils.hasText(fileNameGenerator)) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.io.File;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -16,22 +16,29 @@
|
||||
|
||||
package org.springframework.integration.file;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FileWritingMessageHandlerTests {
|
||||
|
||||
private Resource outputDirectory = createMock(Resource.class);
|
||||
|
||||
@Test(expected = MessageHandlingException.class)
|
||||
public void unsupportedType() {
|
||||
public void unsupportedType() throws Exception {
|
||||
expect(outputDirectory.getFile()).andReturn(new File(System.getProperty("java.io.tmpdir"))).anyTimes();
|
||||
replay(outputDirectory);
|
||||
FileWritingMessageHandler handler = new FileWritingMessageHandler(
|
||||
new File(System.getProperty("java.io.tmpdir")));
|
||||
outputDirectory );
|
||||
handler.handleMessage(new GenericMessage<Integer>(99));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user