Removing 'file' package contents from 'org.springframework.integration.adapter'. The new 'org.springframework.integration.file' module replaces it.
This commit is contained in:
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
|
||||
/**
|
||||
* Base class providing common behavior for file-based message creators. The
|
||||
* subclasses will redefine the {@code readMessagePayload()} method. This class
|
||||
* allows to choose between keeping the file after message creation and removing
|
||||
* it, by setting the appropriate value in the constructor. The desired
|
||||
* behaviour depends on the nature of the created message (i.e. messages with a
|
||||
* {@link String} payload can safely remove the file after creation, but
|
||||
* messages with a {@link File} payload cannot do that) or of the collaborator
|
||||
* that uses the class instance (e.g. if the file is a locally created copy, it
|
||||
* can be always discarded).
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public abstract class AbstractFileMessageCreator<T> implements MessageCreator<File, T> {
|
||||
|
||||
protected Log logger = LogFactory.getLog(this.getClass());
|
||||
|
||||
private final boolean deleteFileAfterCreation;
|
||||
|
||||
|
||||
/**
|
||||
* @param deleteFileAfterCreation Indicates whether the file should be
|
||||
* deleted after the message has been created.
|
||||
*/
|
||||
public AbstractFileMessageCreator(boolean deleteFileAfterCreation) {
|
||||
this.deleteFileAfterCreation = deleteFileAfterCreation;
|
||||
}
|
||||
|
||||
|
||||
public final Message<T> createMessage(File file) {
|
||||
try {
|
||||
T payload = this.readMessagePayload(file);
|
||||
if (payload == null) {
|
||||
return null;
|
||||
}
|
||||
Message<T> message = new GenericMessage<T>(payload);
|
||||
if (this.deleteFileAfterCreation) {
|
||||
file.delete();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
catch (Exception e) {
|
||||
String description = "failure occurred mapping file to message";
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn(description, e);
|
||||
}
|
||||
throw new MessagingException(description, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract T readMessagePayload(File file) throws Exception;
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.integration.message.MessageCreator}
|
||||
* implementation for messages with a byte array payload.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class ByteArrayFileMessageCreator extends AbstractFileMessageCreator<byte[]> {
|
||||
|
||||
/**
|
||||
* Specifies whether the file should be removed after the message has been created.
|
||||
* See {@link AbstractFileMessageCreator}
|
||||
* @param deleteFilesAfterMessageCreation
|
||||
*/
|
||||
public ByteArrayFileMessageCreator(boolean deleteFilesAfterMessageCreation) {
|
||||
super(deleteFilesAfterMessageCreation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected byte[] readMessagePayload(File file) throws Exception {
|
||||
return FileCopyUtils.copyToByteArray(file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Default implementation of the filename generator strategy. Concatenates the
|
||||
* message id and the current timestamp.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultFileNameGenerator implements FileNameGenerator {
|
||||
|
||||
public String generateFileName(Message<?> message) {
|
||||
String filenameProperty = message.getHeaders().get(FILENAME_PROPERTY_KEY, String.class);
|
||||
return StringUtils.hasText(filenameProperty) ?
|
||||
filenameProperty : message.getHeaders().getId() + ".msg";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
|
||||
/**
|
||||
* A {@link MessageCreator} that creates {@link Message} instances with the
|
||||
* absolute path to the {@link File} as payload.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileMessageCreator extends AbstractFileMessageCreator<File> {
|
||||
|
||||
public FileMessageCreator() {
|
||||
// The file should never be removed, as just the reference to it is
|
||||
// passed to the message
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File readMessagePayload(File file) throws Exception {
|
||||
return file;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* Strategy interface for generating a file name from a message.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public interface FileNameGenerator {
|
||||
|
||||
String FILENAME_PROPERTY_KEY = "filename";
|
||||
|
||||
|
||||
String generateFileName(Message<?> message);
|
||||
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A messaging source that polls a directory to retrieve files.
|
||||
*
|
||||
* @deprecated Replaced by org.springframework.integration.file.PollableFileSource.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FileSource extends AbstractDirectorySource<File> implements MessageDeliveryAware<File> {
|
||||
|
||||
private final File directory;
|
||||
|
||||
private volatile FileFilter fileFilter;
|
||||
|
||||
private volatile FilenameFilter filenameFilter;
|
||||
|
||||
/**
|
||||
* Creates a default FileSource on the specified directory
|
||||
* @param directory
|
||||
*/
|
||||
public FileSource(Resource directory) {
|
||||
this(directory, new FileMessageCreator(), null);
|
||||
}
|
||||
|
||||
public FileSource(Resource directory, Comparator<FileSnapshot> comparator) {
|
||||
this(directory, new FileMessageCreator(), comparator);
|
||||
}
|
||||
|
||||
public FileSource(Resource directory, MessageCreator<File, File> messageCreator) {
|
||||
this(directory, messageCreator, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FileSource with the specified strategies.
|
||||
* @param directory
|
||||
* @param messageCreator the MessageCreator used to convert Files into
|
||||
* Messages
|
||||
* @param comparator the comparator is used to order the backlog. If
|
||||
* <code>null</code> natural order is used.
|
||||
*/
|
||||
public FileSource(Resource directory, MessageCreator<File, File> messageCreator, Comparator<FileSnapshot> comparator) {
|
||||
super(messageCreator, comparator);
|
||||
Assert.notNull(directory, "The directory must not be null");
|
||||
try {
|
||||
this.directory = directory.getFile();
|
||||
if (!this.directory.isDirectory()) {
|
||||
throw new ConfigurationException("The FileSource can't be instantiated because "
|
||||
+ this.directory.getAbsolutePath() + " is not a directory.");
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ConfigurationException("The FileSource can't be instantiated", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Message<File> buildNextMessage() throws IOException {
|
||||
File file = retrieveNextPayload();
|
||||
Message<File> message = this.getMessageCreator().createMessage(file);
|
||||
message = MessageBuilder.fromMessage(message)
|
||||
.setHeader(FileNameGenerator.FILENAME_PROPERTY_KEY, file.getName()).setHeader(FILE_INFO_PROPERTY,
|
||||
getBacklog().getProcessingBuffer().get(0)).build();
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a FilenameFilter to be used with the
|
||||
* <code>{@link File#listFiles()}</code> command. Note that either a
|
||||
* FileFilter or a FilenameFilter is used to filter the list of files.
|
||||
* Calling this setter overwrites the FileNameFilter if it was set before.
|
||||
* @param fileFilter
|
||||
*/
|
||||
public void setFileFilter(FileFilter fileFilter) {
|
||||
Assert.notNull(fileFilter);
|
||||
this.filenameFilter = null;
|
||||
this.fileFilter = fileFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a FilenameFilter to be used with the
|
||||
* <code>{@link File#listFiles()}</code> command. Note that either a
|
||||
* FileFilter or a FilenameFilter is used to filter the list of files.
|
||||
* Calling this setter overwrites the FileFilter if it was set before.
|
||||
* @param filenameFilter
|
||||
*/
|
||||
public void setFilenameFilter(FilenameFilter filenameFilter) {
|
||||
Assert.notNull(filenameFilter);
|
||||
this.fileFilter = null;
|
||||
this.filenameFilter = filenameFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void populateSnapshot(List<FileSnapshot> snapshot) throws IOException {
|
||||
File[] files;
|
||||
if (this.fileFilter != null) {
|
||||
files = this.directory.listFiles(this.fileFilter);
|
||||
}
|
||||
else if (this.filenameFilter != null) {
|
||||
files = this.directory.listFiles(this.filenameFilter);
|
||||
}
|
||||
else {
|
||||
files = this.directory.listFiles();
|
||||
}
|
||||
if (files == null) {
|
||||
throw new MessagingException("Problem occurred while polling for files. " + "Is '"
|
||||
+ directory.getAbsolutePath() + "' a directory?");
|
||||
}
|
||||
for (File file : files) {
|
||||
FileSnapshot fileInfo = new FileSnapshot(file);
|
||||
snapshot.add(fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected File retrieveNextPayload() throws IOException {
|
||||
List<FileSnapshot> selectedForProcessing = this.getBacklog().selectForProcessing(1);
|
||||
if (!selectedForProcessing.isEmpty()) {
|
||||
return selectedForProcessing.get(0).getFile();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
|
||||
/**
|
||||
* A message target for writing files. The actual file writing occurs in the
|
||||
* message mapper.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileTarget implements MessageConsumer {
|
||||
|
||||
private MessageMapper<?, File> messageMapper;
|
||||
|
||||
|
||||
public FileTarget(MessageMapper<?, File> messageMapper) {
|
||||
this.messageMapper = messageMapper;
|
||||
}
|
||||
|
||||
public void onMessage(Message message) {
|
||||
this.messageMapper.mapMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A {@link FilenameFilter} implementation for matching against
|
||||
* a regular expression {@link Pattern}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RegexPatternFilenameFilter implements FilenameFilter {
|
||||
|
||||
private volatile Pattern pattern;
|
||||
|
||||
|
||||
public void setPattern(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
Assert.notNull(pattern, "pattern must not be null");
|
||||
return (name != null) && this.pattern.matcher(name).matches();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageMapper;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* A default {@link MessageMapper} for {@link FileTarget}, converting payloads of the
|
||||
* {@link File}, {@code byte[]} and {@link String} types to files. The name of the newly
|
||||
* created file is defined by the {@link FileNameGenerator} instance configured with it.
|
||||
* By default, it uses a {@link DefaultFileNameGenerator}.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class SimpleFileMessageMapper implements MessageMapper<Object, File> {
|
||||
|
||||
private volatile FileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
|
||||
|
||||
private final File parentDirectory;
|
||||
|
||||
|
||||
public SimpleFileMessageMapper(String parentDirectoryPath) {
|
||||
this(new File(parentDirectoryPath));
|
||||
}
|
||||
|
||||
public SimpleFileMessageMapper(File parentDirectory) {
|
||||
this.parentDirectory = parentDirectory;
|
||||
}
|
||||
|
||||
|
||||
public void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
|
||||
this.fileNameGenerator = fileNameGenerator;
|
||||
}
|
||||
|
||||
public File mapMessage(Message<Object> message) {
|
||||
try {
|
||||
File file = new File(parentDirectory, this.fileNameGenerator.generateFileName(message));
|
||||
this.writeToFile(file, message.getPayload());
|
||||
return file;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new MessageHandlingException(message, "failure occurred mapping file to message", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToFile(File file, Object payload) throws IOException {
|
||||
if (payload instanceof byte[]) {
|
||||
FileCopyUtils.copy((byte[]) payload, file);
|
||||
}
|
||||
else if (payload instanceof String) {
|
||||
FileCopyUtils.copy((String) payload, new FileWriter(file));
|
||||
}
|
||||
else if (payload instanceof File) {
|
||||
FileCopyUtils.copy((File) payload, file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* A {@link org.springframework.integration.message.MessageCreator}
|
||||
* implementation for creating messages with a String payload from a File.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class TextFileMessageCreator extends AbstractFileMessageCreator<String> {
|
||||
|
||||
/**
|
||||
* Specifies whether the file should be removed after the message has been created.
|
||||
* See {@link AbstractFileMessageCreator}
|
||||
* @param deleteFilesAfterMessageCreation
|
||||
*/
|
||||
public TextFileMessageCreator(boolean deleteFilesAfterMessageCreation) {
|
||||
super(deleteFilesAfterMessageCreation);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected String readMessagePayload(File file) throws Exception {
|
||||
return FileCopyUtils.copyToString(new FileReader(file));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileSource;
|
||||
import org.springframework.integration.adapter.file.RegexPatternFilenameFilter;
|
||||
import org.springframework.integration.adapter.file.TextFileMessageCreator;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <file-source/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileSourceParser extends AbstractDirectorySourceParser {
|
||||
|
||||
public static final String TYPE_ATTRIBUTE = "type";
|
||||
|
||||
public static final String DIRECTORY_ATTRIBUTE = "directory";
|
||||
|
||||
public static final String FILE_FILTER_ATTRIBUTE = "file-filter";
|
||||
|
||||
public static final String FILENAME_FILTER_ATTRIBUTE = "filename-filter";
|
||||
|
||||
public static final String FILENAME_PATTERN_ATTRIBUTE = "filename-pattern";
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FileSource.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !DIRECTORY_ATTRIBUTE.equals(attributeName) && !FILE_FILTER_ATTRIBUTE.equals(attributeName)
|
||||
&& !FILENAME_FILTER_ATTRIBUTE.equals(attributeName)
|
||||
&& !FILENAME_PATTERN_ATTRIBUTE.equals(attributeName) && !TYPE_ATTRIBUTE.equals(attributeName)
|
||||
&& super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void postProcess(BeanDefinitionBuilder beanDefinition, Element element) {
|
||||
String directoryLocation = element.getAttribute(DIRECTORY_ATTRIBUTE);
|
||||
if (!directoryLocation.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX) && !isUrl(directoryLocation)) {
|
||||
directoryLocation = "file:" + directoryLocation;
|
||||
}
|
||||
beanDefinition.addConstructorArgValue(directoryLocation);
|
||||
String fileFilter = element.getAttribute(FILE_FILTER_ATTRIBUTE);
|
||||
String filenameFilter = element.getAttribute(FILENAME_FILTER_ATTRIBUTE);
|
||||
String filenamePattern = element.getAttribute(FILENAME_PATTERN_ATTRIBUTE);
|
||||
this.verifyAtMostOneAttributeSpecified(fileFilter, filenameFilter, filenamePattern);
|
||||
if (StringUtils.hasText(fileFilter)) {
|
||||
beanDefinition.addPropertyReference("fileFilter", fileFilter);
|
||||
}
|
||||
else if (StringUtils.hasText(filenameFilter)) {
|
||||
beanDefinition.addPropertyReference("filenameFilter", filenameFilter);
|
||||
}
|
||||
else if (StringUtils.hasLength(filenamePattern)) {
|
||||
RegexPatternFilenameFilter regexFilter = new RegexPatternFilenameFilter();
|
||||
regexFilter.setPattern(Pattern.compile(filenamePattern));
|
||||
beanDefinition.addPropertyValue("filenameFilter", regexFilter);
|
||||
}
|
||||
super.postProcess(beanDefinition, element);
|
||||
processTypeAttribute(beanDefinition, element);
|
||||
}
|
||||
|
||||
private void processTypeAttribute(BeanDefinitionBuilder beanDefinition, Element element) {
|
||||
if (beanDefinition.getRawBeanDefinition().getConstructorArgumentValues().getArgumentCount() == 2) {
|
||||
// message-creator already defined, ignore type property
|
||||
}
|
||||
else {
|
||||
String type = element.getAttribute(TYPE_ATTRIBUTE);
|
||||
if ("text".equals(type)) {
|
||||
beanDefinition.addConstructorArgValue(new TextFileMessageCreator(false));
|
||||
}
|
||||
else if ("binary".equals(type)) {
|
||||
beanDefinition.addConstructorArgValue(new ByteArrayFileMessageCreator(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isUrl(String directoryLocation) {
|
||||
try {
|
||||
new URL(directoryLocation);
|
||||
return true;
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyAtMostOneAttributeSpecified(String... attributes) {
|
||||
boolean attributeSpecified = false;
|
||||
for (String attribute : attributes) {
|
||||
if (StringUtils.hasText(attribute)) {
|
||||
if (attributeSpecified) {
|
||||
throw new ConfigurationException("FileSource supports at most one of '" + FILE_FILTER_ATTRIBUTE
|
||||
+ "', '" + FILENAME_FILTER_ATTRIBUTE + "', and '" + FILENAME_PATTERN_ATTRIBUTE + "'.");
|
||||
}
|
||||
attributeSpecified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
import org.springframework.integration.adapter.file.SimpleFileMessageMapper;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <file-target/> element.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileTargetParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
private static final String NAME_GENERATOR_PROPERTY = "fileNameGenerator";
|
||||
|
||||
public static final String DIRECTORY_ATTRIBUTE = "directory";
|
||||
|
||||
public static final String FILE_NAME_GENERATOR_ATTRIBUTE = "name-generator";
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FileTarget.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(String attributeName) {
|
||||
return !(DIRECTORY_ATTRIBUTE.equals(attributeName) || FILE_NAME_GENERATOR_ATTRIBUTE.equals(attributeName))
|
||||
&& super.isEligibleAttribute(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
super.doParse(element, parserContext, builder);
|
||||
BeanDefinition messageMapperDefinition = new RootBeanDefinition(SimpleFileMessageMapper.class);
|
||||
messageMapperDefinition.getConstructorArgumentValues().addGenericArgumentValue(
|
||||
element.getAttribute(DIRECTORY_ATTRIBUTE));
|
||||
if (StringUtils.hasText(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE))) {
|
||||
messageMapperDefinition.getPropertyValues().addPropertyValue(NAME_GENERATOR_PROPERTY,
|
||||
new RuntimeBeanReference(element.getAttribute(FILE_NAME_GENERATOR_ATTRIBUTE)));
|
||||
}
|
||||
String mapperBeanName = parserContext.getReaderContext().generateBeanName(messageMapperDefinition);
|
||||
parserContext.getRegistry().registerBeanDefinition(
|
||||
mapperBeanName, messageMapperDefinition);
|
||||
builder.addConstructorArgReference(mapperBeanName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -23,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.integration.message.MessageDeliveryAware;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -24,9 +24,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.springframework.integration.adapter.file.AbstractDirectorySource;
|
||||
import org.springframework.integration.adapter.file.Backlog;
|
||||
import org.springframework.integration.adapter.file.FileSnapshot;
|
||||
|
||||
import org.springframework.integration.message.DefaultMessageCreator;
|
||||
import org.springframework.integration.message.MessageCreator;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -46,6 +44,7 @@ public class FtpSource extends AbstractDirectorySource<List<File>> {
|
||||
|
||||
private final FTPClientPool clientPool;
|
||||
|
||||
|
||||
public FtpSource(FTPClientPool clientPool) {
|
||||
this(new DefaultMessageCreator<List<File>>(), clientPool);
|
||||
}
|
||||
@@ -55,6 +54,7 @@ public class FtpSource extends AbstractDirectorySource<List<File>> {
|
||||
this.clientPool = clientPool;
|
||||
}
|
||||
|
||||
|
||||
public void setMaxFilesPerMessage(int maxFilesPerMessage) {
|
||||
Assert.isTrue(maxFilesPerMessage > 0, "'maxFilesPerMessage' must be greater than 0");
|
||||
this.maxFilesPerMessage = maxFilesPerMessage;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.integration.adapter.file.config.AbstractDirectorySourceParser;
|
||||
import org.springframework.integration.adapter.ftp.FtpSource;
|
||||
import org.springframework.integration.adapter.ftp.QueuedFTPClientPool;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <ftp-source/> element.
|
||||
@@ -30,6 +30,7 @@ import org.w3c.dom.Element;
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FtpSourceParser extends AbstractDirectorySourceParser {
|
||||
|
||||
private static final String POOL_ATTRIBUTE_USER = "username";
|
||||
|
||||
private static final String POOL_ATTRIBUTE_PASS = "password";
|
||||
@@ -40,6 +41,7 @@ public class FtpSourceParser extends AbstractDirectorySourceParser {
|
||||
|
||||
private static final String POOL_ATTRIBUTE_REMOTEDIR = "remote-working-directory";
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return FtpSource.class;
|
||||
@@ -71,4 +73,5 @@ public class FtpSourceParser extends AbstractDirectorySourceParser {
|
||||
queuedFTPClientPool.setRemoteWorkingDirectory(remoteWorkingDirectory);
|
||||
beanDefinition.addConstructorArgValue(queuedFTPClientPool);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
file-source=org.springframework.integration.adapter.file.config.FileSourceParser
|
||||
file-target=org.springframework.integration.adapter.file.config.FileTargetParser
|
||||
ftp-source=org.springframework.integration.adapter.ftp.config.FtpSourceParser
|
||||
mail-target=org.springframework.integration.adapter.mail.config.MailTargetParser
|
||||
polling-mail-source=org.springframework.integration.adapter.mail.config.PollingMailSourceParser
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class DefaultFileNameGeneratorTests {
|
||||
|
||||
@Test
|
||||
public void testWithFileNamePropertyProvided() {
|
||||
Message<String> message = MessageBuilder.withPayload("testing")
|
||||
.setHeader(FileNameGenerator.FILENAME_PROPERTY_KEY, "foo.bar").build();
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertEquals("foo.bar", filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutFileNamePropertyProvided() {
|
||||
Message<String> message = new GenericMessage<String>("testing");
|
||||
FileNameGenerator generator = new DefaultFileNameGenerator();
|
||||
String filename = generator.generateFileName(message);
|
||||
assertTrue(filename.startsWith("" + message.getHeaders().getId()));
|
||||
assertTrue(filename.endsWith(".msg"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
*/
|
||||
public class FileSourceTests {
|
||||
|
||||
private FileSource fileSource;
|
||||
|
||||
private static final String INPUT_DIR = System.getProperty("java.io.tmpdir") + "/"
|
||||
+ FileSourceTests.class.getCanonicalName();
|
||||
|
||||
@BeforeClass
|
||||
public static void createTmpDir() {
|
||||
new File(INPUT_DIR).mkdirs();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void refreshFileSource() {
|
||||
fileSource = new FileSource(new FileSystemResource(INPUT_DIR));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanOutTmp() {
|
||||
for (File file : new File(INPUT_DIR).listFiles()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void removeTmp() {
|
||||
if (!new File(INPUT_DIR).delete()) {
|
||||
throw new RuntimeException("failed to clean up directory [" + INPUT_DIR + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoFile() {
|
||||
assertNull("There should be no message on the source", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedEmptyFile() throws Exception {
|
||||
new File(INPUT_DIR + "/test").createNewFile();
|
||||
assertNotNull("No file received after writing to input directory", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closedWriter() throws Exception {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(INPUT_DIR + "/test")));
|
||||
writer.write("some stuff");
|
||||
writer.close();
|
||||
assertNotNull("No file received after writing to input directory", fileSource.receive());
|
||||
}
|
||||
|
||||
@Test
|
||||
/*
|
||||
* This test shows the how not to do it (i.e. without a proper external
|
||||
* trigger)
|
||||
*/
|
||||
public void testOpenWriter() throws Exception {
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(INPUT_DIR + "/test")));
|
||||
writer.write("some stuff");
|
||||
// don't close the writer yet
|
||||
Message<File> received = fileSource.receive();
|
||||
assertNotNull("incomplete file was not received", received);
|
||||
fileSource.onSend(received);
|
||||
writer.write("some more stuff");
|
||||
writer.close();
|
||||
assertNotNull("something shoulda happened don't you think?", received);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class RegexPatternFilenameFilterTests {
|
||||
|
||||
@Test
|
||||
public void match() {
|
||||
File file = new File("/some/path/test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.setPattern(Pattern.compile("[a-z]+\\.txt"));
|
||||
assertTrue(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noMatch() {
|
||||
File file = new File("/some/path/Test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.setPattern(Pattern.compile("[a-z]+\\.txt"));
|
||||
assertFalse(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void patternNotSet() {
|
||||
File file = new File("/some/path/test.txt");
|
||||
RegexPatternFilenameFilter filter = new RegexPatternFilenameFilter();
|
||||
filter.accept(file.getParentFile(), file.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternEditorInContext() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"regexPatternFilenameFilterTests.xml", this.getClass());
|
||||
FilenameFilter filter = (FilenameFilter) context.getBean("filter");
|
||||
File file = new File("/some/path/foo.txt");
|
||||
assertTrue(filter.accept(file.getParentFile(), file.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPatternSyntax() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("invalidRegexPatternFilenameFilterTests.xml", this.getClass());
|
||||
throw new IllegalStateException("context creation should have failed");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertEquals(BeanCreationException.class, e.getClass());
|
||||
Throwable cause1 = e.getCause();
|
||||
assertEquals(TypeMismatchException.class, cause1.getClass());
|
||||
Throwable cause2 = cause1.getCause();
|
||||
assertEquals(PatternSyntaxException.class, cause2.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFileFilter implements FileFilter {
|
||||
|
||||
public boolean accept(File pathname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class CustomFilenameFilter implements FilenameFilter {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.integration.adapter.file.FileNameGenerator;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class CustomNameGenerator implements FileNameGenerator{
|
||||
|
||||
public String generateFileName(Message<?> message) {
|
||||
return "file" + new Date().getTime();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileSource;
|
||||
import org.springframework.integration.adapter.file.RegexPatternFilenameFilter;
|
||||
import org.springframework.integration.adapter.file.TextFileMessageCreator;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileSourceParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileSourceDefaultType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceDefault");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof FileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceTextType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceText");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof TextFileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceBinaryType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceBinary");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof ByteArrayFileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceFileType() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceFile");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof FileMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomMessageCreator");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof CustomMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithTypeAndCustomMessageCreator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceTypeAndCustom");
|
||||
DirectFieldAccessor sourceAccessor = new DirectFieldAccessor(fileSource);
|
||||
File directory = (File) sourceAccessor.getPropertyValue("directory");
|
||||
Object messageCreator = sourceAccessor.getPropertyValue("messageCreator");
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), directory.getAbsolutePath());
|
||||
assertTrue(messageCreator instanceof CustomMessageCreator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomFileFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFileFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FileFilter filter = (FileFilter) context.getBean("customFileFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("fileFilter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithCustomFilenameFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithCustomFilenameFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
FilenameFilter filter = (FilenameFilter) context.getBean("customFilenameFilter");
|
||||
assertEquals(filter, accessor.getPropertyValue("filenameFilter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithRegexPatternFilenameFilter() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileSourceParserTests.xml", this.getClass());
|
||||
FileSource fileSource = (FileSource) context.getBean("fileSourceWithRegexFilter");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(fileSource);
|
||||
RegexPatternFilenameFilter filter = (RegexPatternFilenameFilter) accessor.getPropertyValue("filenameFilter");
|
||||
assertFalse(filter.accept(null, "foo.htm"));
|
||||
assertTrue(filter.accept(null, "foo.txt"));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
public void testFileSourceWithFileFilterAndFilenameFilterNotAllowed() throws Throwable {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("fileSourceWithTooManyFilters.xml", this.getClass());
|
||||
fail();
|
||||
}
|
||||
catch (BeanDefinitionStoreException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileSourceWithFileAndNotDirectory() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext("fileSourceWithFileDirectory.xml", this.getClass());
|
||||
fail();
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertTrue(ex.getCause().getCause().getMessage().indexOf("is not a directory") > 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.adapter.file.DefaultFileNameGenerator;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
import org.springframework.integration.adapter.file.SimpleFileMessageMapper;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class FileTargetParserTests {
|
||||
|
||||
@Test
|
||||
public void testFileTarget() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetParserTests.xml", this.getClass());
|
||||
FileTarget target = (FileTarget) context.getBean("target");
|
||||
DirectFieldAccessor targetFieldAccessor = new DirectFieldAccessor(target);
|
||||
SimpleFileMessageMapper messageMapper = (SimpleFileMessageMapper) targetFieldAccessor
|
||||
.getPropertyValue("messageMapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(messageMapper);
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), ((File) mapperAccessor.getPropertyValue("parentDirectory"))
|
||||
.getAbsolutePath());
|
||||
assertTrue(mapperAccessor.getPropertyValue("fileNameGenerator") instanceof DefaultFileNameGenerator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFileTargetWithCustomFilenameGenerator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("fileTargetParserTests.xml", this.getClass());
|
||||
FileTarget target = (FileTarget) context.getBean("targetWithCustomNameGenerator");
|
||||
DirectFieldAccessor targetFieldAccessor = new DirectFieldAccessor(target);
|
||||
SimpleFileMessageMapper messageMapper = (SimpleFileMessageMapper) targetFieldAccessor
|
||||
.getPropertyValue("messageMapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(messageMapper);
|
||||
assertEquals(System.getProperty("java.io.tmpdir"), ((File) mapperAccessor.getPropertyValue("parentDirectory"))
|
||||
.getAbsolutePath());
|
||||
assertTrue(mapperAccessor.getPropertyValue("fileNameGenerator") instanceof CustomNameGenerator);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSourceDefault" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceText" type="text" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceBinary" type="binary" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceFile" type="file" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomMessageCreator" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFileFilter" file-filter="customFileFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithCustomFilenameFilter" filename-filter="customFilenameFilter" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceWithRegexFilter" filename-pattern="fo+\.[tx]{3}" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-source id="fileSourceTypeAndCustom" type="text" message-creator="customMessageCreator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customMessageCreator" class="org.springframework.integration.adapter.file.config.CustomMessageCreator"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSourceDefault" directory="fileSourceWithFileDirectory.xml"/>
|
||||
|
||||
</beans>
|
||||
@@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:file-source id="fileSource"
|
||||
directory="${java.io.tmpdir}"
|
||||
file-filter="customFileFilter"
|
||||
filename-filter="customFilenameFilter"/>
|
||||
|
||||
<bean id="customFileFilter" class="org.springframework.integration.adapter.file.config.CustomFileFilter"/>
|
||||
|
||||
<bean id="customFilenameFilter" class="org.springframework.integration.adapter.file.config.CustomFilenameFilter"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -1,25 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<si:message-bus/>
|
||||
|
||||
<si:channel id="testChannel"/>
|
||||
|
||||
<si:file-target id="target" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<si:file-target id="targetWithCustomNameGenerator" name-generator="customFileNameGenerator" directory="${java.io.tmpdir}"/>
|
||||
|
||||
<bean id="customFileNameGenerator" class="org.springframework.integration.adapter.file.config.CustomNameGenerator"/>
|
||||
|
||||
<context:property-placeholder/>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.adapter.file.RegexPatternFilenameFilter">
|
||||
<property name="pattern" value="[fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -1,11 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
|
||||
|
||||
<bean id="filter" class="org.springframework.integration.adapter.file.RegexPatternFilenameFilter">
|
||||
<property name="pattern" value="fo+\.[tx]{3}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file;
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
@@ -22,9 +22,10 @@ import java.util.concurrent.PriorityBlockingQueue;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.integration.adapter.file.Backlog;
|
||||
import org.springframework.integration.adapter.file.FileSnapshot;
|
||||
import org.springframework.integration.adapter.ftp.Backlog;
|
||||
import org.springframework.integration.adapter.ftp.FileSnapshot;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -1,4 +1,20 @@
|
||||
package org.springframework.integration.adapter.file;
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -9,6 +25,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -13,26 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.ftp;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertSame;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.createNiceMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.easymock.classextension.EasyMock.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPClient;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.adapter.file.FileTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Iwein Fuld
|
||||
*
|
||||
*/
|
||||
public class QueuedFTPClientPoolTest {
|
||||
|
||||
@@ -42,12 +43,14 @@ public class QueuedFTPClientPoolTest {
|
||||
|
||||
private Object[] allMocks = new Object[] { factoryMock };
|
||||
|
||||
|
||||
@Before
|
||||
public void initializeSubject() throws Exception {
|
||||
this.pool = new QueuedFTPClientPool(5);
|
||||
pool.setFactory(factoryMock);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void get() throws Exception {
|
||||
FTPClient expectedClient = new FTPClient();
|
||||
@@ -95,6 +98,7 @@ public class QueuedFTPClientPoolTest {
|
||||
verify(allMocks);
|
||||
}
|
||||
|
||||
|
||||
private FTPClient mockedFTPClient() throws Exception {
|
||||
FTPClient mock = createNiceMock(FTPClient.class);
|
||||
expect(mock.isConnected()).andReturn(true).anyTimes();
|
||||
@@ -102,4 +106,5 @@ public class QueuedFTPClientPoolTest {
|
||||
replay(mock);
|
||||
return mock;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
public class CollectionSplitter {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Splitter public List split(Message<? extends Collection> message) {
|
||||
return new ArrayList(message.getPayload());
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.adapter.file.config;
|
||||
package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -30,5 +30,5 @@ public class CustomMessageCreator implements MessageCreator<File, String>{
|
||||
public Message<String> createMessage(File object) {
|
||||
return new GenericMessage<String> (object.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,20 +18,14 @@ package org.springframework.integration.adapter.ftp.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.adapter.file.ByteArrayFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.FileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.TextFileMessageCreator;
|
||||
import org.springframework.integration.adapter.file.config.CustomMessageCreator;
|
||||
import org.springframework.integration.adapter.ftp.FtpSource;
|
||||
import org.springframework.integration.message.DefaultMessageCreator;
|
||||
|
||||
|
||||
@@ -52,6 +52,6 @@
|
||||
message-creator="customMessageCreator"/>
|
||||
|
||||
<bean id="customMessageCreator"
|
||||
class="org.springframework.integration.adapter.file.config.CustomMessageCreator"/>
|
||||
class="org.springframework.integration.adapter.ftp.config.CustomMessageCreator"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user