http://jira.mfd.msk:8088/browse/CLS-358 sftp fix after review
This commit is contained in:
parent
79b65e0023
commit
49c836cbde
3 changed files with 31 additions and 61 deletions
|
|
@ -28,9 +28,14 @@ import static org.springframework.integration.file.remote.gateway.AbstractRemote
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SFTPNotificationsConfig {
|
public class SFTPNotificationsConfig {
|
||||||
|
private final ReportsServiceSettings settings;
|
||||||
|
|
||||||
|
public SFTPNotificationsConfig(ReportsServiceSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean("notificationsSftpSessionFactory")
|
@Bean("notificationsSftpSessionFactory")
|
||||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(ReportsServiceSettings settings) {
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
factory.setHost(settings.getNotificationsStore().getServerIp());
|
factory.setHost(settings.getNotificationsStore().getServerIp());
|
||||||
factory.setPort(settings.getNotificationsStore().getServerPort());
|
factory.setPort(settings.getNotificationsStore().getServerPort());
|
||||||
|
|
@ -42,11 +47,7 @@ public class SFTPNotificationsConfig {
|
||||||
|
|
||||||
@Bean("notificationsSftpHandler")
|
@Bean("notificationsSftpHandler")
|
||||||
@ServiceActivator(inputChannel = "notificationsToSftpChannel")
|
@ServiceActivator(inputChannel = "notificationsToSftpChannel")
|
||||||
public MessageHandler handler(
|
public MessageHandler handler(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("notificationsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
SftpMessageHandler handler = new SftpMessageHandler(sessionFactory);
|
SftpMessageHandler handler = new SftpMessageHandler(sessionFactory);
|
||||||
handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getNotificationsStore().getOutDir()));
|
handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getNotificationsStore().getOutDir()));
|
||||||
handler.setAutoCreateDirectory(true);
|
handler.setAutoCreateDirectory(true);
|
||||||
|
|
@ -61,44 +62,28 @@ public class SFTPNotificationsConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("notificationsListSftpChannel")
|
@Bean("notificationsListSftpChannel")
|
||||||
public MessageChannel listSftpChannel(
|
public MessageChannel listSftpChannel(@Qualifier("notificationsSftpHandlerList") MessageHandler handler) {
|
||||||
@Qualifier("notificationsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
DirectChannel dc = new DirectChannel();
|
DirectChannel dc = new DirectChannel();
|
||||||
dc.subscribe(handlerList(sessionFactory, settings));
|
dc.subscribe(handler);
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("notificationsToSftpChannel")
|
@Bean("notificationsToSftpChannel")
|
||||||
public MessageChannel toSftpChannel(
|
public MessageChannel toSftpChannel(@Qualifier("notificationsSftpHandler") MessageHandler handler) {
|
||||||
@Qualifier("notificationsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
DirectChannel dc = new DirectChannel();
|
DirectChannel dc = new DirectChannel();
|
||||||
dc.subscribe(handler(sessionFactory, settings));
|
dc.subscribe(handler);
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("notificationsHandlerList")
|
@Bean("notificationsSftpHandlerList")
|
||||||
@ServiceActivator(inputChannel = "notificationsListSftpChannel")
|
@ServiceActivator(inputChannel = "notificationsListSftpChannel")
|
||||||
public MessageHandler handlerList(
|
public MessageHandler handlerList(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("notificationsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
String expression = "'/%s'".formatted(settings.getNotificationsStore().getOutDir());
|
String expression = "'/%s'".formatted(settings.getNotificationsStore().getOutDir());
|
||||||
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression);
|
return new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression);
|
||||||
return sftpOutboundGateway;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("notificationsSftpOutboundListFlow")
|
@Bean("notificationsSftpOutboundListFlow")
|
||||||
public IntegrationFlow sftpOutboundListFlow(
|
public IntegrationFlow sftpOutboundListFlow(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("notificationsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory
|
|
||||||
) {
|
|
||||||
return IntegrationFlows.from("notificationsListSftpChannel")
|
return IntegrationFlows.from("notificationsListSftpChannel")
|
||||||
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
||||||
.get();
|
.get();
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,14 @@ import static org.springframework.integration.file.remote.gateway.AbstractRemote
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SFTPReportsConfig {
|
public class SFTPReportsConfig {
|
||||||
|
private final ReportsServiceSettings settings;
|
||||||
|
|
||||||
|
public SFTPReportsConfig(ReportsServiceSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean("reportsSftpSessionFactory")
|
@Bean("reportsSftpSessionFactory")
|
||||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(ReportsServiceSettings settings) {
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
||||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
factory.setHost(settings.getReportsStore().getServerIp());
|
factory.setHost(settings.getReportsStore().getServerIp());
|
||||||
factory.setPort(settings.getReportsStore().getServerPort());
|
factory.setPort(settings.getReportsStore().getServerPort());
|
||||||
|
|
@ -42,11 +47,7 @@ public class SFTPReportsConfig {
|
||||||
|
|
||||||
@Bean("reportsSftpHandler")
|
@Bean("reportsSftpHandler")
|
||||||
@ServiceActivator(inputChannel = "reportsToSftpChannel")
|
@ServiceActivator(inputChannel = "reportsToSftpChannel")
|
||||||
public MessageHandler handler(
|
public MessageHandler handler(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("reportsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
SftpMessageHandler handler = new SftpMessageHandler(sessionFactory);
|
SftpMessageHandler handler = new SftpMessageHandler(sessionFactory);
|
||||||
handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getReportsStore().getOutDir()));
|
handler.setRemoteDirectoryExpression(new LiteralExpression(settings.getReportsStore().getOutDir()));
|
||||||
handler.setAutoCreateDirectory(true);
|
handler.setAutoCreateDirectory(true);
|
||||||
|
|
@ -61,44 +62,28 @@ public class SFTPReportsConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("reportsListSftpChannel")
|
@Bean("reportsListSftpChannel")
|
||||||
public MessageChannel listSftpChannel(
|
public MessageChannel listSftpChannel(@Qualifier("reportsSftpHandlerList") MessageHandler handler) {
|
||||||
@Qualifier("reportsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
DirectChannel dc = new DirectChannel();
|
DirectChannel dc = new DirectChannel();
|
||||||
dc.subscribe(handlerList(sessionFactory, settings));
|
dc.subscribe(handler);
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("reportsToSftpChannel")
|
@Bean("reportsToSftpChannel")
|
||||||
public MessageChannel toSftpChannel(
|
public MessageChannel toSftpChannel(@Qualifier("reportsSftpHandler") MessageHandler handler) {
|
||||||
@Qualifier("reportsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
DirectChannel dc = new DirectChannel();
|
DirectChannel dc = new DirectChannel();
|
||||||
dc.subscribe(handler(sessionFactory, settings));
|
dc.subscribe(handler);
|
||||||
return dc;
|
return dc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("reportsHandlerList")
|
@Bean("reportsSftpHandlerList")
|
||||||
@ServiceActivator(inputChannel = "reportsListSftpChannel")
|
@ServiceActivator(inputChannel = "reportsListSftpChannel")
|
||||||
public MessageHandler handlerList(
|
public MessageHandler handlerList(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("reportsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory,
|
|
||||||
ReportsServiceSettings settings
|
|
||||||
) {
|
|
||||||
String expression = "'/%s'".formatted(settings.getReportsStore().getOutDir());
|
String expression = "'/%s'".formatted(settings.getReportsStore().getOutDir());
|
||||||
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression);
|
return new SftpOutboundGateway(sessionFactory, LS.getCommand(), expression);
|
||||||
return sftpOutboundGateway;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("reportsSftpOutboundListFlow")
|
@Bean("reportsSftpOutboundListFlow")
|
||||||
public IntegrationFlow sftpOutboundListFlow(
|
public IntegrationFlow sftpOutboundListFlow(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||||
@Qualifier("reportsSftpSessionFactory")
|
|
||||||
SessionFactory<ChannelSftp.LsEntry> sessionFactory
|
|
||||||
) {
|
|
||||||
return IntegrationFlows.from("reportsListSftpChannel")
|
return IntegrationFlows.from("reportsListSftpChannel")
|
||||||
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
||||||
.get();
|
.get();
|
||||||
|
|
|
||||||
|
|
@ -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.local-temp-dir=./reports_out_temp
|
||||||
reports-service.reports-store.out-dir=reports
|
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.password=password
|
||||||
reports-service.reports-store.server-ip=10.230.238.53
|
reports-service.reports-store.server-ip=10.230.238.53
|
||||||
reports-service.reports-store.server-port=2222
|
reports-service.reports-store.server-port=2222
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue