Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camel 3.14 sftp fix #11855

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "stepwise": target.getConfiguration().setStepwise(property(camelContext, boolean.class, value)); return true;
case "streamdownload":
case "streamDownload": target.getConfiguration().setStreamDownload(property(camelContext, boolean.class, value)); return true;
case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true;
case "tempfilename":
case "tempFileName": target.setTempFileName(property(camelContext, java.lang.String.class, value)); return true;
case "tempprefix":
Expand Down Expand Up @@ -399,7 +398,6 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "stepwise": return boolean.class;
case "streamdownload":
case "streamDownload": return boolean.class;
case "synchronous": return boolean.class;
case "tempfilename":
case "tempFileName": return java.lang.String.class;
case "tempprefix":
Expand Down Expand Up @@ -603,7 +601,6 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "stepwise": return target.getConfiguration().isStepwise();
case "streamdownload":
case "streamDownload": return target.getConfiguration().isStreamDownload();
case "synchronous": return target.isSynchronous();
case "tempfilename":
case "tempFileName": return target.getTempFileName();
case "tempprefix":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class FtpEndpointUriFactory extends org.apache.camel.support.component.En
private static final Set<String> PROPERTY_NAMES;
private static final Set<String> SECRET_PROPERTY_NAMES;
static {
Set<String> props = new HashSet<>(114);
Set<String> props = new HashSet<>(113);
props.add("disconnect");
props.add("moveExistingFileStrategy");
props.add("fileName");
props.add("synchronous");
props.add("idempotent");
props.add("password");
props.add("preSort");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class FtpsEndpointUriFactory extends org.apache.camel.support.component.E
private static final Set<String> PROPERTY_NAMES;
private static final Set<String> SECRET_PROPERTY_NAMES;
static {
Set<String> props = new HashSet<>(122);
Set<String> props = new HashSet<>(121);
props.add("disconnect");
props.add("moveExistingFileStrategy");
props.add("fileName");
props.add("synchronous");
props.add("idempotent");
props.add("password");
props.add("preSort");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "streamDownload": target.getConfiguration().setStreamDownload(property(camelContext, boolean.class, value)); return true;
case "stricthostkeychecking":
case "strictHostKeyChecking": target.getConfiguration().setStrictHostKeyChecking(property(camelContext, java.lang.String.class, value)); return true;
case "synchronous": target.setSynchronous(property(camelContext, boolean.class, value)); return true;
case "tempfilename":
case "tempFileName": target.setTempFileName(property(camelContext, java.lang.String.class, value)); return true;
case "tempprefix":
Expand Down Expand Up @@ -459,7 +458,6 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "streamDownload": return boolean.class;
case "stricthostkeychecking":
case "strictHostKeyChecking": return java.lang.String.class;
case "synchronous": return boolean.class;
case "tempfilename":
case "tempFileName": return java.lang.String.class;
case "tempprefix":
Expand Down Expand Up @@ -691,7 +689,6 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "streamDownload": return target.getConfiguration().isStreamDownload();
case "stricthostkeychecking":
case "strictHostKeyChecking": return target.getConfiguration().getStrictHostKeyChecking();
case "synchronous": return target.isSynchronous();
case "tempfilename":
case "tempFileName": return target.getTempFileName();
case "tempprefix":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ public class SftpEndpointUriFactory extends org.apache.camel.support.component.E
private static final Set<String> PROPERTY_NAMES;
private static final Set<String> SECRET_PROPERTY_NAMES;
static {
Set<String> props = new HashSet<>(129);
Set<String> props = new HashSet<>(128);
props.add("disconnect");
props.add("moveExistingFileStrategy");
props.add("fileName");
props.add("strictHostKeyChecking");
props.add("synchronous");
props.add("idempotent");
props.add("password");
props.add("privateKeyPassphrase");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
"siteCommand": { "kind": "parameter", "displayName": "Site Command", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.file.remote.FtpConfiguration", "configurationField": "configuration", "description": "Sets optional site command(s) to be executed after successful login. Multiple site commands can be separated using a new line character." },
"soTimeout": { "kind": "parameter", "displayName": "So Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "300000", "configurationClass": "org.apache.camel.component.file.remote.FtpConfiguration", "configurationField": "configuration", "description": "Sets the so timeout FTP and FTPS Is the SocketOptions.SO_TIMEOUT value in millis. Recommended option is to set this to 300000 so as not have a hanged connection. On SFTP this option is set as timeout on the JSCH Session instance." },
"stepwise": { "kind": "parameter", "displayName": "Stepwise", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.file.remote.FtpConfiguration", "configurationField": "configuration", "description": "Sets whether we should stepwise change directories while traversing file structures when downloading files, or as well when uploading a file to a directory. You can disable this if you for example are in a situation where you cannot change directory on the FTP server due security reasons. Stepwise cannot be used together with streamDownload." },
"synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" },
"throwExceptionOnConnectFailed": { "kind": "parameter", "displayName": "Throw Exception On Connect Failed", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.file.remote.FtpConfiguration", "configurationField": "configuration", "description": "Should an exception be thrown if connection failed (exhausted)By default exception is not thrown and a WARN is logged. You can use this to enable exception being thrown and handle the thrown exception from the org.apache.camel.spi.PollingConsumerPollStrategy rollback method." },
"timeout": { "kind": "parameter", "displayName": "Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "30000", "configurationClass": "org.apache.camel.component.file.remote.FtpConfiguration", "configurationField": "configuration", "description": "Sets the data timeout for waiting for reply Used only by FTPClient" },
"antExclude": { "kind": "parameter", "displayName": "Ant Exclude", "group": "filter", "label": "consumer,filter", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Ant style filter exclusion. If both antInclude and antExclude are used, antExclude takes precedence over antInclude. Multiple exclusions may be specified in comma-delimited format." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
"siteCommand": { "kind": "parameter", "displayName": "Site Command", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.file.remote.FtpsConfiguration", "configurationField": "configuration", "description": "Sets optional site command(s) to be executed after successful login. Multiple site commands can be separated using a new line character." },
"soTimeout": { "kind": "parameter", "displayName": "So Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "300000", "configurationClass": "org.apache.camel.component.file.remote.FtpsConfiguration", "configurationField": "configuration", "description": "Sets the so timeout FTP and FTPS Is the SocketOptions.SO_TIMEOUT value in millis. Recommended option is to set this to 300000 so as not have a hanged connection. On SFTP this option is set as timeout on the JSCH Session instance." },
"stepwise": { "kind": "parameter", "displayName": "Stepwise", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.file.remote.FtpsConfiguration", "configurationField": "configuration", "description": "Sets whether we should stepwise change directories while traversing file structures when downloading files, or as well when uploading a file to a directory. You can disable this if you for example are in a situation where you cannot change directory on the FTP server due security reasons. Stepwise cannot be used together with streamDownload." },
"synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" },
"throwExceptionOnConnectFailed": { "kind": "parameter", "displayName": "Throw Exception On Connect Failed", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.file.remote.FtpsConfiguration", "configurationField": "configuration", "description": "Should an exception be thrown if connection failed (exhausted)By default exception is not thrown and a WARN is logged. You can use this to enable exception being thrown and handle the thrown exception from the org.apache.camel.spi.PollingConsumerPollStrategy rollback method." },
"timeout": { "kind": "parameter", "displayName": "Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "30000", "configurationClass": "org.apache.camel.component.file.remote.FtpsConfiguration", "configurationField": "configuration", "description": "Sets the data timeout for waiting for reply Used only by FTPClient" },
"antExclude": { "kind": "parameter", "displayName": "Ant Exclude", "group": "filter", "label": "consumer,filter", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Ant style filter exclusion. If both antInclude and antExclude are used, antExclude takes precedence over antInclude. Multiple exclusions may be specified in comma-delimited format." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
"serverAliveInterval": { "kind": "parameter", "displayName": "Server Alive Interval", "group": "advanced", "label": "advanced", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.file.remote.SftpConfiguration", "configurationField": "configuration", "description": "Sets the interval (millis) to send a keep-alive message. If zero is specified, any keep-alive message must not be sent. The default interval is zero." },
"soTimeout": { "kind": "parameter", "displayName": "So Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "300000", "configurationClass": "org.apache.camel.component.file.remote.SftpConfiguration", "configurationField": "configuration", "description": "Sets the so timeout FTP and FTPS Is the SocketOptions.SO_TIMEOUT value in millis. Recommended option is to set this to 300000 so as not have a hanged connection. On SFTP this option is set as timeout on the JSCH Session instance." },
"stepwise": { "kind": "parameter", "displayName": "Stepwise", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.file.remote.SftpConfiguration", "configurationField": "configuration", "description": "Sets whether we should stepwise change directories while traversing file structures when downloading files, or as well when uploading a file to a directory. You can disable this if you for example are in a situation where you cannot change directory on the FTP server due security reasons. Stepwise cannot be used together with streamDownload." },
"synchronous": { "kind": "parameter", "displayName": "Synchronous", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Sets whether synchronous processing should be strictly used" },
"throwExceptionOnConnectFailed": { "kind": "parameter", "displayName": "Throw Exception On Connect Failed", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.file.remote.SftpConfiguration", "configurationField": "configuration", "description": "Should an exception be thrown if connection failed (exhausted)By default exception is not thrown and a WARN is logged. You can use this to enable exception being thrown and handle the thrown exception from the org.apache.camel.spi.PollingConsumerPollStrategy rollback method." },
"timeout": { "kind": "parameter", "displayName": "Timeout", "group": "advanced", "label": "advanced", "required": false, "type": "duration", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "30000", "configurationClass": "org.apache.camel.component.file.remote.SftpConfiguration", "configurationField": "configuration", "description": "Sets the data timeout for waiting for reply Used only by FTPClient" },
"antExclude": { "kind": "parameter", "displayName": "Ant Exclude", "group": "filter", "label": "consumer,filter", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Ant style filter exclusion. If both antInclude and antExclude are used, antExclude takes precedence over antInclude. Multiple exclusions may be specified in comma-delimited format." },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
+ "readLockIdempotentReleaseDelay,readLockIdempotentReleaseExecutorService,"
+ "directoryMustExist,extendedAttributes,probeContentType,startingDirectoryMustExist,"
+ "startingDirectoryMustHaveAccess,chmodDirectory,forceWrites,copyAndDeleteOnRenameFail,"
+ "renameUsingCopy")
+ "renameUsingCopy,synchronous")
@ManagedResource(description = "Managed FtpEndpoint")
public class FtpEndpoint<T extends FTPFile> extends RemoteFileEndpoint<FTPFile> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
+ "readLockIdempotentReleaseDelay,readLockIdempotentReleaseExecutorService,"
+ "directoryMustExist,extendedAttributes,probeContentType,startingDirectoryMustExist,"
+ "startingDirectoryMustHaveAccess,chmodDirectory,forceWrites,copyAndDeleteOnRenameFail,"
+ "renameUsingCopy")
+ "renameUsingCopy,synchronous")
@ManagedResource(description = "Managed FtpsEndpoint")
public class FtpsEndpoint extends FtpEndpoint<FTPFile> {
private static final Logger LOG = LoggerFactory.getLogger(FtpsEndpoint.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public abstract class RemoteFileEndpoint<T> extends GenericFileEndpoint<T> {
private boolean download = true;

public RemoteFileEndpoint() {
// ftp must be synchronous as the ftp-client is not thread-safe
setSynchronous(true);
// no args constructor for spring bean endpoint configuration
// for ftp we need to use higher interval/checkout that for files
setReadLockTimeout(20000);
Expand All @@ -80,6 +82,8 @@ public RemoteFileEndpoint() {
public RemoteFileEndpoint(String uri, RemoteFileComponent<T> component, RemoteFileConfiguration configuration) {
super(uri, component);
this.configuration = configuration;
// ftp must be synchronous as the ftp-client is not thread-safe
setSynchronous(true);
// for ftp we need to use higher interval/checkout that for files
setReadLockTimeout(20000);
setReadLockCheckInterval(5000);
Expand Down Expand Up @@ -180,12 +184,16 @@ public PollingConsumer createPollingConsumer() throws Exception {
/**
* Validates this endpoint if its configured properly.
*
* @throws Exception is thrown if endpoint is invalid configured for its mandatory options
* @throws IllegalArgumentException is thrown if endpoint is invalid configured for its mandatory options
*/
protected void afterPropertiesSet() {
RemoteFileConfiguration config = getConfiguration();
StringHelper.notEmpty(config.getHost(), "host");
StringHelper.notEmpty(config.getProtocol(), "protocol");

if (!isSynchronous()) {
throw new IllegalArgumentException("Using synchronous=false is not supported for camel-ftp");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@Metadata(excludeProperties = "appendChars,bufferSize,siteCommand,"
+ "directoryMustExist,extendedAttributes,probeContentType,startingDirectoryMustExist,"
+ "startingDirectoryMustHaveAccess,forceWrites,copyAndDeleteOnRenameFail,"
+ "renameUsingCopy")
+ "renameUsingCopy,synchronous")
public class SftpEndpoint extends RemoteFileEndpoint<SftpRemoteFile> {

@UriParam
Expand Down
Loading