Как получить значение от SftpOutboundGateway - PullRequest
0 голосов
/ 08 октября 2019

Я пытаюсь получить список имен файлов, используя SftpOutboundGateway. До сих пор я пытался создать бин SftpOutboundGateway с аннотацией Service Activator и бином IntegrationFlow. Оба решения ничего не возвращают, кроме журналов; /.

Интерфейс шлюза

@MessagingGateway
public interface SftpCommandGateway {

    @Gateway(requestChannel = "lsChannel")
    List<String> lsRemote(@Payload String path);

}

Служба, которая вызывает lsRemote

@Service
public class SftpInboundDefaultServiceImpl implements SftpInboundService {

    private SftpCommandGateway sftpCommandGateway;

    @Autowired
    public SftpInboundDefaultServiceImpl(SftpCommandGateway sftpCommandGateway) {
        this.sftpCommandGateway = sftpCommandGateway;
    }

    @Override
    public List<String> availableFilenames() {
        return sftpCommandGateway.lsRemote("'sftpTest/'");
    }
}

Файл конфигурации:

@Configuration
@EnableIntegration
@IntegrationComponentScan("com.company.package")
public class SftpCommandConfiguration {

    private static final Logger LOGGER = LoggerFactory.getLogger(SftpCommandConfiguration.class);

    private SessionFactory sessionFactory;

    @Autowired
    public SftpCommandConfiguration(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

// Secound approche with IntegrationFlow 
//    @Bean
//    public IntegrationFlow lsIntegrationFlow() {
//        return IntegrationFlows
//                .from("lsChannel")
//                .handle(Sftp.outboundGateway(sessionFactory, AbstractRemoteFileOutboundGateway.Command.NLST, "payload"))
//                .log("info")
//                .get();
//    }

    @Bean
    @ServiceActivator(inputChannel = "lsChannel")
    public SftpOutboundGateway lsHandler() {
        SftpOutboundGateway gateway = buildSftpOutboundGateway("nlst");
        gateway.setOption(AbstractRemoteFileOutboundGateway.Option.NOSORT);
        gateway.setOutputChannelName("lsResults");
        return gateway;
    }

    private SftpOutboundGateway buildSftpOutboundGateway(String command) {
        SftpOutboundGateway gateway = new SftpOutboundGateway(sessionFactory,
                command, "payload");
        gateway.setLoggingEnabled(true);
        return gateway;
    }
}

Я ожидаю получить список имен файлов, но теперь это событие не возвращается к "availableFilenames ()"

дополнительные в журнале консоли Я вижу, что:

beanи пример активатора службы

o.s.integration.channel.DirectChannel    : preSend on channel 'lsChannel', message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, id=a5bd6c88-edbd-4f78-e521-aabf62827571, timestamp=1570521590725}]
2019-10-08 09:59:50.726 DEBUG 11880 --- [nio-8080-exec-6] o.s.i.sftp.gateway.SftpOutboundGateway   : lsHandler received message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@64f6e71a, id=a5bd6c88-edbd-4f78-e521-aabf62827571, timestamp=1570521590725}]

Пример IntegrationFlow

2019-10-08 09:21:03.430 DEBUG 15056 --- [nio-8080-exec-4] o.s.integration.channel.DirectChannel    : preSend on channel 'lsChannel', message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, id=9cc72ea7-152f-7a40-011a-90f56b7abdad, timestamp=1570519263430}]
2019-10-08 09:21:03.432 DEBUG 15056 --- [nio-8080-exec-4] o.s.i.sftp.gateway.SftpOutboundGateway   : lsIntegrationFlow.org.springframework.integration.sftp.gateway.SftpOutboundGateway#0 received message: GenericMessage [payload='sftpTest/', headers={replyChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, errorChannel=org.springframework.messaging.core.GenericMessagingTemplate$TemporaryReplyChannel@3368cbff, id=9cc72ea7-152f-7a40-011a-90f56b7abdad, timestamp=1570519263430}]

Можете ли вы сказать мне, что я делаю неправильно или чего не хватает.

1 Ответ

0 голосов
/ 08 октября 2019

Над конфигурацией все в порядке. У меня была ошибка в конфигурации сеанса, которая не возникала при запуске приложения, и я не знал о проблеме с соединением.

...