GH-9427: Improve nullability for remote path expression (#9434)

Fixes: #9427

Issue link: https://github.com/spring-projects/spring-integration/issues/9427

The `expression` of the `AbstractRemoteFileOutboundGateway` could be `null` and
ignored for some expressions making a DSL factories inconsistent

* Improve `AbstractRemoteFileOutboundGateway` constructor JavaDocs explaining
`expression` argument in more details
* Add `@Nullable` for this `expression` arg in all the `AbstractRemoteFileOutboundGateway` implementations
* Add new DSL factory method for `outboundGateway()` without this `expression` for those commands when it is not needed
This commit is contained in:
Artem Bilan
2024-08-30 11:52:44 -04:00
committed by GitHub
parent dc02dec4de
commit c27cc4b11c
7 changed files with 267 additions and 70 deletions

View File

@@ -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<FTPFile> 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<FTPFile> 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<FTPFile> 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<FTPFile> 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<FTPFile> 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<FTPFile> 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<FTPFile> remoteFileTemplate,
String command, String expression) {
String command, @Nullable String expression) {
return new FtpOutboundGatewaySpec(new FtpOutboundGateway(remoteFileTemplate, command, expression));
}

View File

@@ -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<FTPFil
/**
* Construct an instance with the supplied session factory, a command ('ls', 'get'
* etc), and an expression to determine the filename.
* etc.), and an expression to determine the remote path.
* @param sessionFactory the session factory.
* @param command the command.
* @param expression the filename expression.
* @param expression the remote path expression.
*/
public FtpOutboundGateway(SessionFactory<FTPFile> sessionFactory, String command, String expression) {
public FtpOutboundGateway(SessionFactory<FTPFile> 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<FTPFil
/**
* 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 FtpOutboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate, String command, String expression) {
public FtpOutboundGateway(RemoteFileTemplate<FTPFile> remoteFileTemplate, String command,
@Nullable String expression) {
super(remoteFileTemplate, command, expression);
}