Enable ModifierOrderCheck Checkstyle rule (#2673)
* Enable ModifierOrderCheck Checkstyle rule * Fix violations for `static` and `abstract` modifier * Remove redundant code in the `TcpNioConnection` * Mark `connectionFactoryName` as `@Nullable` in the `TcpConnectionSupport` ctor and its inheritors * Fix some smells according IDEA suggestions in the affected classes * This should fix some Sonar smells as well * * Fix `HeaderMapperTests` * * Polishing `TcpConnection` code style and fix Javdocs
This commit is contained in:
committed by
Gary Russell
parent
a01d09f0f1
commit
93d7c58b64
@@ -37,6 +37,7 @@ import org.springframework.integration.file.filters.FileListFilter;
|
||||
import org.springframework.integration.file.filters.ReversibleFileListFilter;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.support.FileUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -56,7 +57,7 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
|
||||
|
||||
private final RemoteFileTemplate<F> remoteFileTemplate;
|
||||
|
||||
private final BlockingQueue<AbstractFileInfo<F>> toBeReceived = new LinkedBlockingQueue<AbstractFileInfo<F>>();
|
||||
private final BlockingQueue<AbstractFileInfo<F>> toBeReceived = new LinkedBlockingQueue<>();
|
||||
|
||||
private final Comparator<F> comparator;
|
||||
|
||||
@@ -65,24 +66,25 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
|
||||
/**
|
||||
* the path on the remote server.
|
||||
*/
|
||||
private volatile Expression remoteDirectoryExpression;
|
||||
private Expression remoteDirectoryExpression;
|
||||
|
||||
private volatile String remoteFileSeparator = "/";
|
||||
private String remoteFileSeparator = "/";
|
||||
|
||||
/**
|
||||
* An {@link FileListFilter} that runs against the <em>remote</em> file system view.
|
||||
*/
|
||||
private volatile FileListFilter<F> filter;
|
||||
private FileListFilter<F> filter;
|
||||
|
||||
protected AbstractRemoteFileStreamingMessageSource(RemoteFileTemplate<F> template,
|
||||
Comparator<F> comparator) {
|
||||
@Nullable Comparator<F> comparator) {
|
||||
|
||||
Assert.notNull(template, "'template' must not be null");
|
||||
this.remoteFileTemplate = template;
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the full path to the remote directory.
|
||||
*
|
||||
* @param remoteDirectory The remote directory.
|
||||
*/
|
||||
public void setRemoteDirectory(String remoteDirectory) {
|
||||
@@ -91,7 +93,6 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
|
||||
|
||||
/**
|
||||
* Specify an expression that evaluates to the full path to the remote directory.
|
||||
*
|
||||
* @param remoteDirectoryExpression The remote directory expression.
|
||||
*/
|
||||
public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) {
|
||||
@@ -183,10 +184,9 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
|
||||
}
|
||||
|
||||
protected String remotePath(AbstractFileInfo<F> file) {
|
||||
String remotePath = file.getRemoteDirectory().endsWith(this.remoteFileSeparator)
|
||||
return file.getRemoteDirectory().endsWith(this.remoteFileSeparator)
|
||||
? file.getRemoteDirectory() + file.getFilename()
|
||||
: file.getRemoteDirectory() + this.remoteFileSeparator + file.getFilename();
|
||||
return remotePath;
|
||||
}
|
||||
|
||||
private void listFiles() {
|
||||
@@ -219,8 +219,8 @@ public abstract class AbstractRemoteFileStreamingMessageSource<F>
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected List<AbstractFileInfo<F>> asFileInfoList(Collection<F> files);
|
||||
protected abstract List<AbstractFileInfo<F>> asFileInfoList(Collection<F> files);
|
||||
|
||||
abstract protected boolean isDirectory(F file);
|
||||
protected abstract boolean isDirectory(F file);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -27,7 +27,6 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -53,6 +52,7 @@ import org.springframework.integration.handler.AbstractReplyProducingMessageHand
|
||||
import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor;
|
||||
import org.springframework.integration.support.MutableMessage;
|
||||
import org.springframework.integration.support.PartialSuccessException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -70,185 +70,42 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
protected final RemoteFileTemplate<F> remoteFileTemplate;
|
||||
|
||||
protected final Command command;
|
||||
protected final RemoteFileTemplate<F> remoteFileTemplate; // NOSONAR
|
||||
|
||||
/**
|
||||
* Enumeration of commands supported by the gateways.
|
||||
*/
|
||||
public enum Command {
|
||||
protected final Command command; // NOSONAR
|
||||
|
||||
/**
|
||||
* (ls) List remote files.
|
||||
*/
|
||||
LS("ls"),
|
||||
|
||||
/**
|
||||
* (nlst) List remote file names.
|
||||
*/
|
||||
NLST("nlst"),
|
||||
|
||||
/**
|
||||
* (get) Retrieve a remote file.
|
||||
*/
|
||||
GET("get"),
|
||||
|
||||
/**
|
||||
* (rm) Remove a remote file (path - including wildcards).
|
||||
*/
|
||||
RM("rm"),
|
||||
|
||||
/**
|
||||
* (mget) Retrieve multiple files matching a wildcard path.
|
||||
*/
|
||||
MGET("mget"),
|
||||
|
||||
/**
|
||||
* (mv) Move (rename) a remote file.
|
||||
*/
|
||||
MV("mv"),
|
||||
|
||||
/**
|
||||
* (put) Put a local file to the remote system.
|
||||
*/
|
||||
PUT("put"),
|
||||
|
||||
/**
|
||||
* (mput) Put multiple local files to the remote system.
|
||||
*/
|
||||
MPUT("mput");
|
||||
|
||||
private String command;
|
||||
|
||||
Command(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public static Command toCommand(String cmd) {
|
||||
for (Command command : values()) {
|
||||
if (command.getCommand().equals(cmd)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No Command with value '" + cmd + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumeration of options supported by various commands.
|
||||
*
|
||||
*/
|
||||
public enum Option {
|
||||
|
||||
/**
|
||||
* (-1) Don't return full file information; just the name (ls).
|
||||
*/
|
||||
NAME_ONLY("-1"),
|
||||
|
||||
/**
|
||||
* (-a) Include files beginning with {@code .}, including directories {@code .}
|
||||
* and {@code ..} in the results (ls).
|
||||
*/
|
||||
ALL("-a"),
|
||||
|
||||
/**
|
||||
* (-f) Do not sort the results (ls with NAME_ONLY).
|
||||
*/
|
||||
NOSORT("-f"),
|
||||
|
||||
/**
|
||||
* (-dirs) Include directories in the results (ls).
|
||||
*/
|
||||
SUBDIRS("-dirs"),
|
||||
|
||||
/**
|
||||
* (-links) Include links in the results (ls).
|
||||
*/
|
||||
LINKS("-links"),
|
||||
|
||||
/**
|
||||
* (-P) Preserve the server timestamp (get, mget).
|
||||
*/
|
||||
PRESERVE_TIMESTAMP("-P"),
|
||||
|
||||
/**
|
||||
* (-x) Throw an exception if no files returned (mget).
|
||||
*/
|
||||
EXCEPTION_WHEN_EMPTY("-x"),
|
||||
|
||||
/**
|
||||
* (-R) Recursive (ls, mget)
|
||||
*/
|
||||
RECURSIVE("-R"),
|
||||
|
||||
/**
|
||||
* (-stream) Streaming 'get' (returns InputStream); user must call {@link Session#close()}.
|
||||
*/
|
||||
STREAM("-stream"),
|
||||
|
||||
/**
|
||||
* (-D) Delete the remote file after successful transfer (get, mget).
|
||||
*/
|
||||
DELETE("-D");
|
||||
|
||||
private String option;
|
||||
|
||||
Option(String option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public String getOption() {
|
||||
return this.option;
|
||||
}
|
||||
|
||||
public static Option toOption(String opt) {
|
||||
for (Option option : values()) {
|
||||
if (option.getOption().equals(opt)) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No option with value '" + opt + "'");
|
||||
}
|
||||
|
||||
}
|
||||
protected final Set<Option> options = new HashSet<>();
|
||||
|
||||
private final ExpressionEvaluatingMessageProcessor<String> fileNameProcessor;
|
||||
|
||||
private final MessageSessionCallback<F, ?> messageSessionCallback;
|
||||
|
||||
protected final Set<Option> options = new HashSet<>();
|
||||
|
||||
private volatile ExpressionEvaluatingMessageProcessor<String> renameProcessor =
|
||||
private ExpressionEvaluatingMessageProcessor<String> renameProcessor =
|
||||
new ExpressionEvaluatingMessageProcessor<>(
|
||||
new FunctionExpression<Message<?>>(m ->
|
||||
m.getHeaders().get(FileHeaders.RENAME_TO)));
|
||||
|
||||
private volatile Expression localDirectoryExpression;
|
||||
private Expression localDirectoryExpression;
|
||||
|
||||
private volatile boolean autoCreateLocalDirectory = true;
|
||||
private boolean autoCreateLocalDirectory = true;
|
||||
|
||||
/**
|
||||
* A {@link FileListFilter} that runs against the <em>remote</em> file system view.
|
||||
*/
|
||||
private volatile FileListFilter<F> filter;
|
||||
private FileListFilter<F> filter;
|
||||
|
||||
/**
|
||||
* A {@link FileListFilter} that runs against the <em>local</em> file system view when
|
||||
* using MPUT.
|
||||
*/
|
||||
private volatile FileListFilter<File> mputFilter;
|
||||
private FileListFilter<File> mputFilter;
|
||||
|
||||
private volatile Expression localFilenameGeneratorExpression;
|
||||
private Expression localFilenameGeneratorExpression;
|
||||
|
||||
private volatile FileExistsMode fileExistsMode;
|
||||
private FileExistsMode fileExistsMode;
|
||||
|
||||
private volatile Integer chmod;
|
||||
private Integer chmod;
|
||||
|
||||
/**
|
||||
* Construct an instance using the provided session factory and callback for
|
||||
@@ -258,6 +115,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(SessionFactory<F> sessionFactory,
|
||||
MessageSessionCallback<F, ?> messageSessionCallback) {
|
||||
|
||||
this(new RemoteFileTemplate<F>(sessionFactory), messageSessionCallback);
|
||||
}
|
||||
|
||||
@@ -269,6 +127,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplate,
|
||||
MessageSessionCallback<F, ?> messageSessionCallback) {
|
||||
|
||||
Assert.notNull(remoteFileTemplate, "'remoteFileTemplate' cannot be null");
|
||||
Assert.notNull(messageSessionCallback, "'messageSessionCallback' cannot be null");
|
||||
this.remoteFileTemplate = remoteFileTemplate;
|
||||
@@ -285,7 +144,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(SessionFactory<F> sessionFactory, String command,
|
||||
String expression) {
|
||||
@Nullable String expression) {
|
||||
|
||||
this(sessionFactory, Command.toCommand(command), expression);
|
||||
}
|
||||
|
||||
@@ -296,7 +156,9 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* @param command the command.
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(SessionFactory<F> sessionFactory, Command command, String expression) {
|
||||
public AbstractRemoteFileOutboundGateway(SessionFactory<F> sessionFactory, Command command,
|
||||
@Nullable String expression) {
|
||||
|
||||
this(new RemoteFileTemplate<F>(sessionFactory), command, expression);
|
||||
}
|
||||
|
||||
@@ -308,7 +170,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplate, String command,
|
||||
String expression) {
|
||||
@Nullable String expression) {
|
||||
|
||||
this(remoteFileTemplate, Command.toCommand(command), expression);
|
||||
}
|
||||
|
||||
@@ -320,7 +183,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
* @param expression the filename expression.
|
||||
*/
|
||||
public AbstractRemoteFileOutboundGateway(RemoteFileTemplate<F> remoteFileTemplate, Command command,
|
||||
String expression) {
|
||||
@Nullable String expression) {
|
||||
|
||||
Assert.notNull(remoteFileTemplate, "'remoteFileTemplate' cannot be null");
|
||||
this.remoteFileTemplate = remoteFileTemplate;
|
||||
this.command = command;
|
||||
@@ -913,7 +777,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
purgeDots(lsFiles);
|
||||
}
|
||||
if (this.options.contains(Option.NAME_ONLY)) {
|
||||
List<String> results = new ArrayList<String>();
|
||||
List<String> results = new ArrayList<>();
|
||||
for (F file : lsFiles) {
|
||||
results.add(getFilename(file));
|
||||
}
|
||||
@@ -934,7 +798,9 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
}
|
||||
}
|
||||
|
||||
private List<F> listFilesInRemoteDir(Session<F> session, String directory, String subDirectory) throws IOException {
|
||||
private List<F> listFilesInRemoteDir(Session<F> session, String directory, String subDirectory)
|
||||
throws IOException {
|
||||
|
||||
List<F> lsFiles = new ArrayList<F>();
|
||||
String remoteDirectory = buildRemotePath(directory, subDirectory);
|
||||
|
||||
@@ -986,21 +852,11 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
}
|
||||
|
||||
protected void purgeLinks(List<F> lsFiles) {
|
||||
Iterator<F> iterator = lsFiles.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (this.isLink(iterator.next())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
lsFiles.removeIf(this::isLink);
|
||||
}
|
||||
|
||||
protected void purgeDots(List<F> lsFiles) {
|
||||
Iterator<F> iterator = lsFiles.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (getFilename(iterator.next()).startsWith(".")) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
lsFiles.removeIf(f -> getFilename(f).startsWith("."));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1119,9 +975,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
if (logger.isWarnEnabled() && !("*".equals(remoteFilename))) {
|
||||
logger.warn("File name pattern must be '*' when using recursion");
|
||||
}
|
||||
if (this.options.contains(Option.NAME_ONLY)) {
|
||||
this.options.remove(Option.NAME_ONLY);
|
||||
}
|
||||
this.options.remove(Option.NAME_ONLY);
|
||||
return mGetWithRecursion(message, session, remoteDirectory, remoteFilename);
|
||||
}
|
||||
else {
|
||||
@@ -1131,7 +985,8 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
|
||||
private List<File> mGetWithoutRecursion(Message<?> message, Session<F> session, String remoteDirectory,
|
||||
String remoteFilename) throws IOException {
|
||||
List<File> files = new ArrayList<File>();
|
||||
|
||||
List<File> files = new ArrayList<>();
|
||||
String remotePath = buildRemotePath(remoteDirectory, remoteFilename);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<AbstractFileInfo<F>> remoteFiles = (List<AbstractFileInfo<F>>) ls(message, session, remotePath);
|
||||
@@ -1179,7 +1034,7 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
|
||||
private List<File> mGetWithRecursion(Message<?> message, Session<F> session, String remoteDirectory,
|
||||
String remoteFilename) throws IOException {
|
||||
List<File> files = new ArrayList<File>();
|
||||
List<File> files = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<AbstractFileInfo<F>> fileNames = (List<AbstractFileInfo<F>>) ls(message, session, remoteDirectory);
|
||||
if (fileNames.size() == 0 && this.options.contains(Option.EXCEPTION_WHEN_EMPTY)) {
|
||||
@@ -1268,18 +1123,162 @@ public abstract class AbstractRemoteFileOutboundGateway<F> extends AbstractReply
|
||||
return remoteFileName;
|
||||
}
|
||||
|
||||
abstract protected boolean isDirectory(F file);
|
||||
protected abstract boolean isDirectory(F file);
|
||||
|
||||
abstract protected boolean isLink(F file);
|
||||
protected abstract boolean isLink(F file);
|
||||
|
||||
abstract protected String getFilename(F file);
|
||||
protected abstract String getFilename(F file);
|
||||
|
||||
abstract protected String getFilename(AbstractFileInfo<F> file);
|
||||
protected abstract String getFilename(AbstractFileInfo<F> file);
|
||||
|
||||
abstract protected long getModified(F file);
|
||||
protected abstract long getModified(F file);
|
||||
|
||||
abstract protected List<AbstractFileInfo<F>> asFileInfoList(Collection<F> files);
|
||||
protected abstract List<AbstractFileInfo<F>> asFileInfoList(Collection<F> files);
|
||||
|
||||
abstract protected F enhanceNameWithSubDirectory(F file, String directory);
|
||||
protected abstract F enhanceNameWithSubDirectory(F file, String directory);
|
||||
|
||||
/**
|
||||
* Enumeration of commands supported by the gateways.
|
||||
*/
|
||||
public enum Command {
|
||||
|
||||
/**
|
||||
* (ls) List remote files.
|
||||
*/
|
||||
LS("ls"),
|
||||
|
||||
/**
|
||||
* (nlst) List remote file names.
|
||||
*/
|
||||
NLST("nlst"),
|
||||
|
||||
/**
|
||||
* (get) Retrieve a remote file.
|
||||
*/
|
||||
GET("get"),
|
||||
|
||||
/**
|
||||
* (rm) Remove a remote file (path - including wildcards).
|
||||
*/
|
||||
RM("rm"),
|
||||
|
||||
/**
|
||||
* (mget) Retrieve multiple files matching a wildcard path.
|
||||
*/
|
||||
MGET("mget"),
|
||||
|
||||
/**
|
||||
* (mv) Move (rename) a remote file.
|
||||
*/
|
||||
MV("mv"),
|
||||
|
||||
/**
|
||||
* (put) Put a local file to the remote system.
|
||||
*/
|
||||
PUT("put"),
|
||||
|
||||
/**
|
||||
* (mput) Put multiple local files to the remote system.
|
||||
*/
|
||||
MPUT("mput");
|
||||
|
||||
private final String command;
|
||||
|
||||
Command(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public static Command toCommand(String cmd) {
|
||||
for (Command command : values()) {
|
||||
if (command.getCommand().equals(cmd)) {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No Command with value '" + cmd + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumeration of options supported by various commands.
|
||||
*
|
||||
*/
|
||||
public enum Option {
|
||||
|
||||
/**
|
||||
* (-1) Don't return full file information; just the name (ls).
|
||||
*/
|
||||
NAME_ONLY("-1"),
|
||||
|
||||
/**
|
||||
* (-a) Include files beginning with {@code .}, including directories {@code .}
|
||||
* and {@code ..} in the results (ls).
|
||||
*/
|
||||
ALL("-a"),
|
||||
|
||||
/**
|
||||
* (-f) Do not sort the results (ls with NAME_ONLY).
|
||||
*/
|
||||
NOSORT("-f"),
|
||||
|
||||
/**
|
||||
* (-dirs) Include directories in the results (ls).
|
||||
*/
|
||||
SUBDIRS("-dirs"),
|
||||
|
||||
/**
|
||||
* (-links) Include links in the results (ls).
|
||||
*/
|
||||
LINKS("-links"),
|
||||
|
||||
/**
|
||||
* (-P) Preserve the server timestamp (get, mget).
|
||||
*/
|
||||
PRESERVE_TIMESTAMP("-P"),
|
||||
|
||||
/**
|
||||
* (-x) Throw an exception if no files returned (mget).
|
||||
*/
|
||||
EXCEPTION_WHEN_EMPTY("-x"),
|
||||
|
||||
/**
|
||||
* (-R) Recursive (ls, mget)
|
||||
*/
|
||||
RECURSIVE("-R"),
|
||||
|
||||
/**
|
||||
* (-stream) Streaming 'get' (returns InputStream); user must call {@link Session#close()}.
|
||||
*/
|
||||
STREAM("-stream"),
|
||||
|
||||
/**
|
||||
* (-D) Delete the remote file after successful transfer (get, mget).
|
||||
*/
|
||||
DELETE("-D");
|
||||
|
||||
private final String option;
|
||||
|
||||
Option(String option) {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public String getOption() {
|
||||
return this.option;
|
||||
}
|
||||
|
||||
public static Option toOption(String opt) {
|
||||
for (Option option : values()) {
|
||||
if (option.getOption().equals(opt)) {
|
||||
return option;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("No option with value '" + opt + "'");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -120,7 +121,7 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
@Autowired
|
||||
MessageFlushPredicate predicate;
|
||||
|
||||
private volatile static int adviceCalled;
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Test
|
||||
public void simpleAdapter() {
|
||||
@@ -237,10 +238,10 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
usageChannel.send(new GenericMessage<String>("Initial File Content:"));
|
||||
usageChannel.send(new GenericMessage<String>("String content:"));
|
||||
usageChannel.send(new GenericMessage<byte[]>("byte[] content:".getBytes()));
|
||||
usageChannel.send(new GenericMessage<File>(new File("test/input.txt")));
|
||||
usageChannel.send(new GenericMessage<>("Initial File Content:"));
|
||||
usageChannel.send(new GenericMessage<>("String content:"));
|
||||
usageChannel.send(new GenericMessage<>("byte[] content:".getBytes()));
|
||||
usageChannel.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -259,10 +260,10 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<String>("Initial File Content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<String>("String content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<byte[]>("byte[] content:".getBytes()));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<File>(new File("test/input.txt")));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<>("Initial File Content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<>("String content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<>("byte[] content:".getBytes()));
|
||||
adapterUsageWithAppendAndAppendNewLineTrue.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -277,10 +278,10 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<String>("Initial File Content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<String>("String content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<byte[]>("byte[] content:".getBytes()));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<File>(new File("test/input.txt")));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<>("Initial File Content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<>("String content:"));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<>("byte[] content:".getBytes()));
|
||||
adapterUsageWithAppendAndAppendNewLineFalse.send(new GenericMessage<>(new File("test/input.txt")));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -288,20 +289,20 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adapterUsageWithFailMode() throws Exception {
|
||||
public void adapterUsageWithFailMode() {
|
||||
|
||||
File testFile = new File("test/fileToFail.txt");
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
usageChannelWithFailMode.send(new GenericMessage<String>("Initial File Content:"));
|
||||
usageChannelWithFailMode.send(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
try {
|
||||
usageChannelWithFailMode.send(new GenericMessage<String>("String content:"));
|
||||
usageChannelWithFailMode.send(new GenericMessage<>("String content:"));
|
||||
}
|
||||
catch (MessagingException e) {
|
||||
assertTrue(e.getMessage().contains("The destination file already exists at"));
|
||||
assertThat(e.getMessage(), containsString("The destination file already exists at"));
|
||||
testFile.delete();
|
||||
return;
|
||||
}
|
||||
@@ -320,8 +321,8 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
usageChannelWithIgnoreMode.send(new GenericMessage<String>("Initial File Content:"));
|
||||
usageChannelWithIgnoreMode.send(new GenericMessage<String>("String content:"));
|
||||
usageChannelWithIgnoreMode.send(new GenericMessage<>("Initial File Content:"));
|
||||
usageChannelWithIgnoreMode.send(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -347,8 +348,8 @@ public class FileOutboundChannelAdapterParserTests {
|
||||
String bString = bBuffer.toString();
|
||||
|
||||
for (int i = 0; i < 1; i++) {
|
||||
usageChannelConcurrent.send(new GenericMessage<String>(aString));
|
||||
usageChannelConcurrent.send(new GenericMessage<String>(bString));
|
||||
usageChannelConcurrent.send(new GenericMessage<>(aString));
|
||||
usageChannelConcurrent.send(new GenericMessage<>(bString));
|
||||
}
|
||||
|
||||
assertTrue(this.fileWriteLatch.await(10, TimeUnit.SECONDS));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
package org.springframework.integration.file.config;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -84,11 +86,10 @@ public class FileOutboundGatewayParserTests {
|
||||
@Autowired
|
||||
EventDrivenConsumer gatewayWithAppendNewLine;
|
||||
|
||||
private volatile static int adviceCalled;
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Test
|
||||
public void checkOrderedGateway() throws Exception {
|
||||
|
||||
public void checkOrderedGateway() {
|
||||
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(ordered);
|
||||
FileWritingMessageHandler handler = (FileWritingMessageHandler)
|
||||
gatewayAccessor.getPropertyValue("handler");
|
||||
@@ -109,13 +110,13 @@ public class FileOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutboundGatewayWithDirectoryExpression() throws Exception {
|
||||
public void testOutboundGatewayWithDirectoryExpression() {
|
||||
FileWritingMessageHandler handler =
|
||||
TestUtils.getPropertyValue(gatewayWithDirectoryExpression, "handler", FileWritingMessageHandler.class);
|
||||
assertEquals("'build/foo'",
|
||||
TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class)
|
||||
.getExpressionString());
|
||||
handler.handleMessage(new GenericMessage<String>("foo"));
|
||||
handler.handleMessage(new GenericMessage<>("foo"));
|
||||
assertEquals(1, adviceCalled);
|
||||
}
|
||||
|
||||
@@ -130,7 +131,6 @@ public class FileOutboundGatewayParserTests {
|
||||
*/
|
||||
@Test
|
||||
public void gatewayWithIgnoreMode() throws Exception {
|
||||
|
||||
final MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
messagingTemplate.setDefaultDestination(this.gatewayWithIgnoreModeChannel);
|
||||
|
||||
@@ -141,9 +141,9 @@ public class FileOutboundGatewayParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
Message<?> replyMessage = messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
|
||||
Message<?> replyMessage = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -166,7 +166,6 @@ public class FileOutboundGatewayParserTests {
|
||||
*/
|
||||
@Test
|
||||
public void gatewayWithFailMode() throws Exception {
|
||||
|
||||
final MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
messagingTemplate.setDefaultDestination(this.gatewayWithFailModeChannel);
|
||||
|
||||
@@ -178,18 +177,18 @@ public class FileOutboundGatewayParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
final String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
|
||||
try {
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertTrue(e.getMessage().startsWith("The destination file already exists at '"));
|
||||
assertThat(e.getMessage(), startsWith("The destination file already exists at '"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -219,18 +218,18 @@ public class FileOutboundGatewayParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
|
||||
final String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
|
||||
try {
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
assertTrue(e.getMessage().startsWith("The destination file already exists at '"));
|
||||
assertThat(e.getMessage(), startsWith("The destination file already exists at '"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -262,8 +261,8 @@ public class FileOutboundGatewayParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -301,8 +300,8 @@ public class FileOutboundGatewayParserTests {
|
||||
testFile.delete();
|
||||
}
|
||||
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
|
||||
messagingTemplate.sendAndReceive(new GenericMessage<>("Initial File Content:"));
|
||||
Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<>("String content:"));
|
||||
|
||||
String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
|
||||
assertEquals(expectedFileContent, actualFileContent);
|
||||
@@ -327,7 +326,7 @@ public class FileOutboundGatewayParserTests {
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) {
|
||||
adviceCalled++;
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user