diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPNotificationsConfig.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPNotificationsConfig.java index cb93816da..23d9c8e6d 100644 --- a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPNotificationsConfig.java +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPNotificationsConfig.java @@ -28,9 +28,14 @@ import static org.springframework.integration.file.remote.gateway.AbstractRemote @Configuration public class SFTPNotificationsConfig { + private final ReportsServiceSettings settings; + + public SFTPNotificationsConfig(ReportsServiceSettings settings) { + this.settings = settings; + } @Bean("notificationsSftpSessionFactory") - public SessionFactory sftpSessionFactory(ReportsServiceSettings settings) { + public SessionFactory sftpSessionFactory() { DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true); factory.setHost(settings.getNotificationsStore().getServerIp()); factory.setPort(settings.getNotificationsStore().getServerPort()); @@ -42,11 +47,7 @@ public class SFTPNotificationsConfig { @Bean("notificationsSftpHandler") @ServiceActivator(inputChannel = "notificationsToSftpChannel") - public MessageHandler handler( - @Qualifier("notificationsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageHandler handler(@Qualifier("notificationsSftpSessionFactory") SessionFactory sessionFactory) { SftpMessageHandler handler = new SftpMessageHandler(sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getNotificationsStore().getOutDir())); handler.setAutoCreateDirectory(true); @@ -61,44 +62,28 @@ public class SFTPNotificationsConfig { } @Bean("notificationsListSftpChannel") - public MessageChannel listSftpChannel( - @Qualifier("notificationsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageChannel listSftpChannel(@Qualifier("notificationsSftpHandlerList") MessageHandler handler) { DirectChannel dc = new DirectChannel(); - dc.subscribe(handlerList(sessionFactory, settings)); + dc.subscribe(handler); return dc; } @Bean("notificationsToSftpChannel") - public MessageChannel toSftpChannel( - @Qualifier("notificationsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageChannel toSftpChannel(@Qualifier("notificationsSftpHandler") MessageHandler handler) { DirectChannel dc = new DirectChannel(); - dc.subscribe(handler(sessionFactory, settings)); + dc.subscribe(handler); return dc; } - @Bean("notificationsHandlerList") + @Bean("notificationsSftpHandlerList") @ServiceActivator(inputChannel = "notificationsListSftpChannel") - public MessageHandler handlerList( - @Qualifier("notificationsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageHandler handlerList(@Qualifier("notificationsSftpSessionFactory") SessionFactory sessionFactory) { String expression = "'/%s'".formatted(settings.getNotificationsStore().getOutDir()); - SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression); - return sftpOutboundGateway; + return new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression); } @Bean("notificationsSftpOutboundListFlow") - public IntegrationFlow sftpOutboundListFlow( - @Qualifier("notificationsSftpSessionFactory") - SessionFactory sessionFactory - ) { + public IntegrationFlow sftpOutboundListFlow(@Qualifier("notificationsSftpSessionFactory") SessionFactory sessionFactory) { return IntegrationFlows.from("notificationsListSftpChannel") .handle(new SftpOutboundGateway(sessionFactory, "ls", "payload")) .get(); diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPReportsConfig.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPReportsConfig.java index 1fa057fc2..9d0e4d1e2 100644 --- a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPReportsConfig.java +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/config/SFTPReportsConfig.java @@ -28,9 +28,14 @@ import static org.springframework.integration.file.remote.gateway.AbstractRemote @Configuration public class SFTPReportsConfig { + private final ReportsServiceSettings settings; + + public SFTPReportsConfig(ReportsServiceSettings settings) { + this.settings = settings; + } @Bean("reportsSftpSessionFactory") - public SessionFactory sftpSessionFactory(ReportsServiceSettings settings) { + public SessionFactory sftpSessionFactory() { DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true); factory.setHost(settings.getReportsStore().getServerIp()); factory.setPort(settings.getReportsStore().getServerPort()); @@ -42,11 +47,7 @@ public class SFTPReportsConfig { @Bean("reportsSftpHandler") @ServiceActivator(inputChannel = "reportsToSftpChannel") - public MessageHandler handler( - @Qualifier("reportsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageHandler handler(@Qualifier("reportsSftpSessionFactory") SessionFactory sessionFactory) { SftpMessageHandler handler = new SftpMessageHandler(sessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getReportsStore().getOutDir())); handler.setAutoCreateDirectory(true); @@ -61,44 +62,28 @@ public class SFTPReportsConfig { } @Bean("reportsListSftpChannel") - public MessageChannel listSftpChannel( - @Qualifier("reportsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageChannel listSftpChannel(@Qualifier("reportsSftpHandlerList") MessageHandler handler) { DirectChannel dc = new DirectChannel(); - dc.subscribe(handlerList(sessionFactory, settings)); + dc.subscribe(handler); return dc; } @Bean("reportsToSftpChannel") - public MessageChannel toSftpChannel( - @Qualifier("reportsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageChannel toSftpChannel(@Qualifier("reportsSftpHandler") MessageHandler handler) { DirectChannel dc = new DirectChannel(); - dc.subscribe(handler(sessionFactory, settings)); + dc.subscribe(handler); return dc; } - @Bean("reportsHandlerList") + @Bean("reportsSftpHandlerList") @ServiceActivator(inputChannel = "reportsListSftpChannel") - public MessageHandler handlerList( - @Qualifier("reportsSftpSessionFactory") - SessionFactory sessionFactory, - ReportsServiceSettings settings - ) { + public MessageHandler handlerList(@Qualifier("reportsSftpSessionFactory") SessionFactory sessionFactory) { String expression = "'/%s'".formatted(settings.getReportsStore().getOutDir()); - SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression); - return sftpOutboundGateway; + return new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression); } @Bean("reportsSftpOutboundListFlow") - public IntegrationFlow sftpOutboundListFlow( - @Qualifier("reportsSftpSessionFactory") - SessionFactory sessionFactory - ) { + public IntegrationFlow sftpOutboundListFlow(@Qualifier("reportsSftpSessionFactory") SessionFactory sessionFactory) { return IntegrationFlows.from("reportsListSftpChannel") .handle(new SftpOutboundGateway(sessionFactory, "ls", "payload")) .get(); diff --git a/clearing-parent/reports-service/src/main/resources/application.properties b/clearing-parent/reports-service/src/main/resources/application.properties index 1fb917da7..93625597f 100644 --- a/clearing-parent/reports-service/src/main/resources/application.properties +++ b/clearing-parent/reports-service/src/main/resources/application.properties @@ -19,7 +19,7 @@ reports-service.kafka-producer.buffer-memory=33554432 reports-service.reports-store.local-temp-dir=./reports_out_temp reports-service.reports-store.out-dir=reports -reports-service.reports-store.user=teste +reports-service.reports-store.user=tester reports-service.reports-store.password=password reports-service.reports-store.server-ip=10.230.238.53 reports-service.reports-store.server-port=2222