From 70d89c7a3b7b809b39c3e28baa4098a31e8e0692 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Tue, 2 Feb 2021 20:41:19 -0500 Subject: [PATCH] GH-145: Some SFTP consumer props were not applied Fixes https://github.com/spring-cloud/stream-applications/issues/145 --- .../fn/consumer/sftp/SftpConsumerConfiguration.java | 13 +++++++------ .../consumer/sftp/SftpConsumerPropertiesTests.java | 13 +++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/functions/consumer/sftp-consumer/src/main/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerConfiguration.java b/functions/consumer/sftp-consumer/src/main/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerConfiguration.java index 5273dc45..932f80d2 100644 --- a/functions/consumer/sftp-consumer/src/main/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerConfiguration.java +++ b/functions/consumer/sftp-consumer/src/main/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2020 the original author or authors. + * Copyright 2015-2021 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. @@ -40,22 +40,23 @@ import org.springframework.messaging.Message; @Import(SftpConsumerSessionFactoryConfiguration.class) public class SftpConsumerConfiguration { - private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); - @Bean - public IntegrationFlow ftpInboundFlow(SftpConsumerProperties properties, SessionFactory ftpSessionFactory) { + public IntegrationFlow ftpOutboundFlow(SftpConsumerProperties properties, + SessionFactory ftpSessionFactory) { + IntegrationFlowBuilder integrationFlowBuilder = IntegrationFlows.from(MessageConsumer.class, (gateway) -> gateway.beanName("sftpConsumer")); SftpMessageHandlerSpec handlerSpec = Sftp.outboundAdapter(new SftpRemoteFileTemplate(ftpSessionFactory), properties.getMode()) .remoteDirectory(properties.getRemoteDir()) + .temporaryRemoteDirectory(properties.getTemporaryRemoteDir()) .remoteFileSeparator(properties.getRemoteFileSeparator()) .autoCreateDirectory(properties.isAutoCreateDir()) + .useTemporaryFileName(properties.isUseTemporaryFilename()) .temporaryFileSuffix(properties.getTmpFileSuffix()); if (properties.getFilenameExpression() != null) { - handlerSpec.fileNameExpression(EXPRESSION_PARSER.parseExpression(properties.getFilenameExpression()) - .getExpressionString()); + handlerSpec.fileNameExpression(properties.getFilenameExpression()); } return integrationFlowBuilder .handle(handlerSpec) diff --git a/functions/consumer/sftp-consumer/src/test/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerPropertiesTests.java b/functions/consumer/sftp-consumer/src/test/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerPropertiesTests.java index a9e88d72..6793538f 100644 --- a/functions/consumer/sftp-consumer/src/test/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerPropertiesTests.java +++ b/functions/consumer/sftp-consumer/src/test/java/org/springframework/cloud/fn/consumer/sftp/SftpConsumerPropertiesTests.java @@ -16,6 +16,10 @@ package org.springframework.cloud.fn.consumer.sftp; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; + import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -42,8 +46,6 @@ import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.file.support.FileExistsMode; import org.springframework.integration.test.util.TestUtils; -import static org.assertj.core.api.Assertions.assertThat; - /** * @author David Turanski * @author Gary Russell @@ -138,8 +140,9 @@ public class SftpConsumerPropertiesTests { context.register(Factory.class); context.refresh(); SessionFactory sessionFactory = context.getBean(SessionFactory.class); - assertThat(TestUtils.getPropertyValue(sessionFactory, "sessionFactory.knownHosts").toString().endsWith( - "/.ssh/known_hosts]")).isTrue(); + assertThat(TestUtils.getPropertyValue(sessionFactory, "sessionFactory.knownHosts") + .toString().replaceAll(java.util.regex.Matcher.quoteReplacement(File.separator), "/") + .endsWith("/.ssh/known_hosts]")).isTrue(); context.close(); } @@ -199,5 +202,7 @@ public class SftpConsumerPropertiesTests { } } + } + }