GH-9129: SFTP: Remove extra / for the file_remoteDirectory header
Fixes: #9129
If `.remoteDirectory("/sftpSource")`, then `FileHeaders.REMOTE_DIRECTORY` is `//sftpSource`
* Fix `AbstractInboundFileSynchronizer` to not add `/` if one is already present in the beginning of the `remoteDirectoryPath`
(cherry picked from commit d87a7098ca)
This commit is contained in:
committed by
Spring Builds
parent
a7a9d47850
commit
f18626fdce
@@ -505,7 +505,10 @@ public abstract class AbstractInboundFileSynchronizer<F>
|
||||
try {
|
||||
String remoteFileMetadata =
|
||||
new URI(protocol(), null, host, Integer.parseInt(port),
|
||||
'/' + remoteDirectoryPath, null, remoteFileName)
|
||||
remoteDirectoryPath.charAt(0) == '/'
|
||||
? remoteDirectoryPath :
|
||||
'/' + remoteDirectoryPath,
|
||||
null, remoteFileName)
|
||||
.toString();
|
||||
this.remoteFileMetadataStore.put(buildMetadataKey(localFile), remoteFileMetadata);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class SftpTests extends SftpTestSupport {
|
||||
IntegrationFlow flow = IntegrationFlow
|
||||
.from(Sftp.inboundAdapter(sessionFactory())
|
||||
.preserveTimestamp(true)
|
||||
.remoteDirectory("sftpSource")
|
||||
.remoteDirectory("/sftpSource")
|
||||
.regexFilter(".*\\.txt$")
|
||||
.localFilenameExpression("#this.toUpperCase() + '.a'")
|
||||
.localDirectory(getTargetLocalDirectory())
|
||||
@@ -91,6 +91,7 @@ public class SftpTests extends SftpTestSupport {
|
||||
File file = (File) payload;
|
||||
assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a");
|
||||
assertThat(file.getAbsolutePath()).contains("localTarget");
|
||||
assertThat(message.getHeaders()).containsEntry(FileHeaders.REMOTE_DIRECTORY, "/sftpSource");
|
||||
|
||||
message = out.receive(10_000);
|
||||
assertThat(message).isNotNull();
|
||||
|
||||
Reference in New Issue
Block a user