diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java index 7976615ad7..4c1f7e5655 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java @@ -153,10 +153,14 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * Construct an instance with the supplied session factory, - * a command ('ls', 'get' etc.), and an expression to determine the filename. + * a command ('ls', 'get' etc.), and an expression to determine the remote path (file or directory). + * The expression is treated as a remote directory for {@code ls} and {@code nlst} commands + * and can be {@code null} if remote file protocol supports it with a meaning of root directory (or use home). + * The {@code put} and {@code mput} commands ignore this expression and fully rely on the payload. + * If expression is not provided, it falls back to the {@code payload}. * @param sessionFactory the session factory. * @param command the command. - * @param expression the filename expression. + * @param expression the remote path. */ public AbstractRemoteFileOutboundGateway(SessionFactory sessionFactory, String command, @Nullable String expression) { @@ -166,10 +170,14 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * Construct an instance with the supplied session factory, - * a command ('ls', 'get' etc.), and an expression to determine the filename. + * a command ('ls', 'get' etc.), and an expression to determine the remote path (file or directory). + * The expression is treated as a remote directory for {@code ls} and {@code nlst} commands + * and can be {@code null} if remote file protocol supports it with a meaning of root directory (or use home). + * The {@code put} and {@code mput} commands ignore this expression and fully rely on the payload. + * If expression is not provided, it falls back to the {@code payload}. * @param sessionFactory the session factory. * @param command the command. - * @param expression the filename expression. + * @param expression the remote path. */ public AbstractRemoteFileOutboundGateway(SessionFactory sessionFactory, Command command, @Nullable String expression) { @@ -180,10 +188,14 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * Construct an instance with the supplied remote file template, - * a command ('ls', 'get' etc.), and an expression to determine the filename. + * a command ('ls', 'get' etc.), and an expression to determine the remote path (file or directory). + * The expression is treated as a remote directory for {@code ls} and {@code nlst} commands + * and can be {@code null} if remote file protocol supports it with a meaning of root directory (or use home). + * The {@code put} and {@code mput} commands ignore this expression and fully rely on the payload. + * If expression is not provided, it falls back to the {@code payload}. * @param remoteFileTemplate the remote file template. * @param command the command. - * @param expression the filename expression. + * @param expression the remote path. */ public AbstractRemoteFileOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, @Nullable String expression) { @@ -193,10 +205,14 @@ public abstract class AbstractRemoteFileOutboundGateway extends AbstractReply /** * Construct an instance with the supplied remote file template, - * a command ('ls', 'get' etc.), and an expression to determine the filename. + * a command ('ls', 'get' etc.), and an expression to determine the remote path (file or directory). + * The expression is treated as a remote directory for {@code ls} and {@code nlst} commands + * and can be {@code null} if remote file protocol supports it with a meaning of root directory (or use home). + * The {@code put} and {@code mput} commands ignore this expression and fully rely on the payload. + * If expression is not provided, it falls back to the {@code payload}. * @param remoteFileTemplate the remote file template. * @param command the command. - * @param expressionArg the filename expression. + * @param expressionArg the remote path. */ public AbstractRemoteFileOutboundGateway(RemoteFileTemplate remoteFileTemplate, Command command, @Nullable String expressionArg) { diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/Ftp.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/Ftp.java index 84d1bae3c4..5b01f0789e 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/Ftp.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/dsl/Ftp.java @@ -134,42 +134,84 @@ public final class Ftp { /** * Produce a {@link FtpOutboundGatewaySpec} based on the {@link SessionFactory}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param sessionFactory the {@link SessionFactory}. * @param command the command to perform on the FTP. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link FtpOutboundGatewaySpec} + * @since 6.4 + */ + public static FtpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, + AbstractRemoteFileOutboundGateway.Command command) { + + return outboundGateway(sessionFactory, command.getCommand(), null); + } + + /** + * Produce a {@link FtpOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the FTP. + * @param expression the remote path SpEL expression. * @return the {@link FtpOutboundGatewaySpec} */ public static FtpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - AbstractRemoteFileOutboundGateway.Command command, String expression) { + AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) { return outboundGateway(sessionFactory, command.getCommand(), expression); } /** * Produce a {@link FtpOutboundGatewaySpec} based on the {@link SessionFactory}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param sessionFactory the {@link SessionFactory}. * @param command the command to perform on the FTP. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link FtpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static FtpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, String command) { + return outboundGateway(sessionFactory, command, null); + } + + /** + * Produce a {@link FtpOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the FTP. + * @param expression the remote path SpEL expression. * @return the {@link FtpOutboundGatewaySpec} * @see RemoteFileTemplate */ public static FtpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - String command, String expression) { + String command, @Nullable String expression) { return new FtpOutboundGatewaySpec(new FtpOutboundGateway(sessionFactory, command, expression)); } /** * Produce a {@link FtpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param remoteFileTemplate the {@link RemoteFileTemplate}. * @param command the command to perform on the FTP. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link FtpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + AbstractRemoteFileOutboundGateway.Command command) { + + return outboundGateway(remoteFileTemplate, command, null); + } + + /** + * Produce a {@link FtpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param remoteFileTemplate the {@link RemoteFileTemplate}. + * @param command the command to perform on the FTP. + * @param expression the remote path SpEL expression. * @return the {@link FtpOutboundGatewaySpec} * @see RemoteFileTemplate */ @@ -181,16 +223,31 @@ public final class Ftp { /** * Produce a {@link FtpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param remoteFileTemplate the {@link RemoteFileTemplate}. * @param command the command to perform on the FTP. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link FtpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + String command) { + + return outboundGateway(remoteFileTemplate, command, null); + } + + /** + * Produce a {@link FtpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param remoteFileTemplate the {@link RemoteFileTemplate}. + * @param command the command to perform on the FTP. + * @param expression the remote path SpEL expression. * @return the {@link FtpOutboundGatewaySpec} * @see RemoteFileTemplate */ public static FtpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, - String command, String expression) { + String command, @Nullable String expression) { return new FtpOutboundGatewaySpec(new FtpOutboundGateway(remoteFileTemplate, command, expression)); } diff --git a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java index 18d55ef6f5..089e0fd310 100644 --- a/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java +++ b/spring-integration-ftp/src/main/java/org/springframework/integration/ftp/gateway/FtpOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2024 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. @@ -41,6 +41,7 @@ import org.springframework.integration.file.remote.session.Session; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.ftp.session.FtpFileInfo; import org.springframework.integration.ftp.session.FtpRemoteFileTemplate; +import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -85,12 +86,12 @@ public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway sessionFactory, String command, String expression) { + public FtpOutboundGateway(SessionFactory sessionFactory, String command, @Nullable String expression) { this(new FtpRemoteFileTemplate(sessionFactory), command, expression); ((FtpRemoteFileTemplate) getRemoteFileTemplate()).setExistsMode(FtpRemoteFileTemplate.ExistsMode.NLST); remoteFileTemplateExplicitlySet(false); @@ -98,12 +99,14 @@ public class FtpOutboundGateway extends AbstractRemoteFileOutboundGateway remoteFileTemplate, String command, String expression) { + public FtpOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, + @Nullable String expression) { + super(remoteFileTemplate, command, expression); } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/Sftp.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/Sftp.java index f588aff130..ad5877e501 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/Sftp.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/dsl/Sftp.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2023 the original author or authors. + * Copyright 2014-2024 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. @@ -132,6 +132,20 @@ public final class Sftp { return new SftpMessageHandlerSpec(sftpRemoteFileTemplate, fileExistsMode); } + /** + * Produce a {@link SftpOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command}. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the FTP. + * @return the {@link SftpOutboundGatewaySpec} + * @since 6.4 + */ + public static SftpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, + AbstractRemoteFileOutboundGateway.Command command) { + + return outboundGateway(sessionFactory, command, null); + } + /** * Produce a {@link SftpOutboundGatewaySpec} based on the {@link SessionFactory}, * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the @@ -142,11 +156,26 @@ public final class Sftp { * @return the {@link SftpOutboundGatewaySpec} */ public static SftpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - AbstractRemoteFileOutboundGateway.Command command, String expression) { + AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) { return outboundGateway(sessionFactory, command.getCommand(), expression); } + /** + * Produce a {@link SftpOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command}. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the FTP. + * @return the {@link SftpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static SftpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, + String command) { + + return outboundGateway(sessionFactory, command, null); + } + /** * Produce a {@link SftpOutboundGatewaySpec} based on the {@link SessionFactory}, * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the @@ -158,26 +187,56 @@ public final class Sftp { * @see RemoteFileTemplate */ public static SftpOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - String command, String expression) { + String command, @Nullable String expression) { return new SftpOutboundGatewaySpec(new SftpOutboundGateway(sessionFactory, command, expression)); } /** * Produce a {@link SftpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param remoteFileTemplate the {@link RemoteFileTemplate} to be based on. * @param command the command to perform on the SFTP. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link SftpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static SftpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + AbstractRemoteFileOutboundGateway.Command command) { + + return outboundGateway(remoteFileTemplate, command, null); + } + + /** + * Produce a {@link SftpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the remote path. + * @param remoteFileTemplate the {@link RemoteFileTemplate} to be based on. + * @param command the command to perform on the SFTP. + * @param expression the remote path SpEL expression. * @return the {@link SftpOutboundGatewaySpec} * @see RemoteFileTemplate */ public static SftpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, - AbstractRemoteFileOutboundGateway.Command command, String expression) { + AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) { return outboundGateway(remoteFileTemplate, command.getCommand(), expression); } + /** + * Produce a {@link SftpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command}. + * @param remoteFileTemplate the {@link RemoteFileTemplate} to be based on. + * @param command the command to perform on the SFTP. + * @return the {@link SftpOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static SftpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + String command) { + + return outboundGateway(remoteFileTemplate, command, null); + } + /** * Produce a {@link SftpOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the remoteFilePath. @@ -188,7 +247,7 @@ public final class Sftp { * @see RemoteFileTemplate */ public static SftpOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, - String command, String expression) { + String command, @Nullable String expression) { return new SftpOutboundGatewaySpec(new SftpOutboundGateway(remoteFileTemplate, command, expression)); } diff --git a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java index 6eb308b222..94d691dbbf 100644 --- a/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java +++ b/spring-integration-sftp/src/main/java/org/springframework/integration/sftp/gateway/SftpOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -33,6 +33,7 @@ import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOut import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.sftp.session.SftpFileInfo; import org.springframework.integration.sftp.session.SftpRemoteFileTemplate; +import org.springframework.lang.Nullable; /** * Outbound Gateway for performing remote file operations via SFTP. @@ -71,24 +72,28 @@ public class SftpOutboundGateway extends AbstractRemoteFileOutboundGateway sessionFactory, String command, String expression) { + public SftpOutboundGateway(SessionFactory sessionFactory, String command, + @Nullable String expression) { + this(new SftpRemoteFileTemplate(sessionFactory), command, expression); remoteFileTemplateExplicitlySet(false); } /** * Construct an instance with the supplied remote file template, a command ('ls', - * 'get' etc), and an expression to determine the filename. + * 'get' etc.), and an expression to determine the remote path. * @param remoteFileTemplate the remote file template. * @param command the command. - * @param expression the filename expression. + * @param expression the remote path expression. */ - public SftpOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, String expression) { + public SftpOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, + @Nullable String expression) { + super(remoteFileTemplate, command, expression); } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/dsl/Smb.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/dsl/Smb.java index 9e1de71ea6..3705d7a967 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/dsl/Smb.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/dsl/Smb.java @@ -131,49 +131,75 @@ public final class Smb { /** * Produce a {@link SmbOutboundGatewaySpec} based on the {@link SessionFactory}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param sessionFactory the {@link SessionFactory}. * @param command the command to perform on the SMB. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link SmbOutboundGatewaySpec} + * @since 6.4 + */ + public static SmbOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, + AbstractRemoteFileOutboundGateway.Command command) { + + return outboundGateway(sessionFactory, command, null); + } + + /** + * Produce a {@link SmbOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the SMB. + * @param expression the remote path SpEL expression. * @return the {@link SmbOutboundGatewaySpec} */ public static SmbOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - AbstractRemoteFileOutboundGateway.Command command, String expression) { + AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) { return outboundGateway(sessionFactory, command.getCommand(), expression); } /** * Produce a {@link SmbOutboundGatewaySpec} based on the {@link SessionFactory}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param sessionFactory the {@link SessionFactory}. * @param command the command to perform on the SMB. - * @param expression the remoteFilePath SpEL expression. + * @return the {@link SmbOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static SmbOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, String command) { + return outboundGateway(sessionFactory, command, null); + } + + /** + * Produce a {@link SmbOutboundGatewaySpec} based on the {@link SessionFactory}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remote path. + * @param sessionFactory the {@link SessionFactory}. + * @param command the command to perform on the SMB. + * @param expression the remote path SpEL expression. * @return the {@link SmbOutboundGatewaySpec} * @see RemoteFileTemplate */ public static SmbOutboundGatewaySpec outboundGateway(SessionFactory sessionFactory, - String command, String expression) { + String command, @Nullable String expression) { return new SmbOutboundGatewaySpec(new SmbOutboundGateway(sessionFactory, command, expression)); } /** * Produce a {@link SmbOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, - * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the - * remoteFilePath. + * {@link AbstractRemoteFileOutboundGateway.Command}. * @param remoteFileTemplate the {@link RemoteFileTemplate}. * @param command the command to perform on the SMB. - * @param expression the remoteFilePath SpEL expression. * @return the {@link SmbOutboundGatewaySpec} + * @since 6.4 * @see RemoteFileTemplate */ public static SmbOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, - AbstractRemoteFileOutboundGateway.Command command, String expression) { + AbstractRemoteFileOutboundGateway.Command command) { - return outboundGateway(remoteFileTemplate, command.getCommand(), expression); + return outboundGateway(remoteFileTemplate, command, null); } /** @@ -187,7 +213,38 @@ public final class Smb { * @see RemoteFileTemplate */ public static SmbOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, - String command, String expression) { + AbstractRemoteFileOutboundGateway.Command command, @Nullable String expression) { + + return outboundGateway(remoteFileTemplate, command.getCommand(), expression); + } + + /** + * Produce a {@link SmbOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command}. + * @param remoteFileTemplate the {@link RemoteFileTemplate}. + * @param command the command to perform on the SMB. + * @return the {@link SmbOutboundGatewaySpec} + * @since 6.4 + * @see RemoteFileTemplate + */ + public static SmbOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + String command) { + + return outboundGateway(remoteFileTemplate, command, null); + } + + /** + * Produce a {@link SmbOutboundGatewaySpec} based on the {@link RemoteFileTemplate}, + * {@link AbstractRemoteFileOutboundGateway.Command} and {@code expression} for the + * remoteFilePath. + * @param remoteFileTemplate the {@link RemoteFileTemplate}. + * @param command the command to perform on the SMB. + * @param expression the remoteFilePath SpEL expression. + * @return the {@link SmbOutboundGatewaySpec} + * @see RemoteFileTemplate + */ + public static SmbOutboundGatewaySpec outboundGateway(RemoteFileTemplate remoteFileTemplate, + String command, @Nullable String expression) { return new SmbOutboundGatewaySpec(new SmbOutboundGateway(remoteFileTemplate, command, expression)); } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/outbound/SmbOutboundGateway.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/outbound/SmbOutboundGateway.java index dd8737f46a..9f35c6660c 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/outbound/SmbOutboundGateway.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/outbound/SmbOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2022-2023 the original author or authors. + * Copyright 2022-2024 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. @@ -22,8 +22,6 @@ import java.util.List; import jcifs.smb.SmbException; import jcifs.smb.SmbFile; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.integration.file.remote.AbstractFileInfo; import org.springframework.integration.file.remote.MessageSessionCallback; @@ -32,18 +30,18 @@ import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOut import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.smb.session.SmbFileInfo; import org.springframework.integration.smb.session.SmbRemoteFileTemplate; +import org.springframework.lang.Nullable; /** * Outbound Gateway for performing remote file operations via SMB. * * @author Gregory Bragg + * @author Artem Bilan * * @since 6.0 */ public class SmbOutboundGateway extends AbstractRemoteFileOutboundGateway { - private static final Log logger = LogFactory.getLog(SmbOutboundGateway.class); - /** * Construct an instance using the provided session factory and callback for * performing operations on the session. @@ -71,24 +69,26 @@ public class SmbOutboundGateway extends AbstractRemoteFileOutboundGateway sessionFactory, String command, String expression) { + public SmbOutboundGateway(SessionFactory sessionFactory, String command, @Nullable String expression) { this(new SmbRemoteFileTemplate(sessionFactory), command, expression); remoteFileTemplateExplicitlySet(false); } /** * Construct an instance with the supplied remote file template, a command ('ls', - * 'get' etc), and an expression to determine the filename. + * 'get' etc.), and an expression to determine the remote path. * @param remoteFileTemplate the remote file template. * @param command the command. - * @param expression the filename expression. + * @param expression the remote path expression. */ - public SmbOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, String expression) { + public SmbOutboundGateway(RemoteFileTemplate remoteFileTemplate, String command, + @Nullable String expression) { + super(remoteFileTemplate, command, expression); } @@ -127,7 +127,7 @@ public class SmbOutboundGateway extends AbstractRemoteFileOutboundGateway