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
|
||||
public class SFTPNotificationsConfig {
|
||||
private final ReportsServiceSettings settings;
|
||||
|
||||
public SFTPNotificationsConfig(ReportsServiceSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Bean("notificationsSftpSessionFactory")
|
||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(ReportsServiceSettings settings) {
|
||||
public SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory,
|
||||
ReportsServiceSettings settings
|
||||
) {
|
||||
public MessageHandler handler(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory,
|
||||
ReportsServiceSettings settings
|
||||
) {
|
||||
public MessageHandler handlerList(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory
|
||||
) {
|
||||
public IntegrationFlow sftpOutboundListFlow(@Qualifier("notificationsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||
return IntegrationFlows.from("notificationsListSftpChannel")
|
||||
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
||||
.get();
|
||||
|
|
|
|||
|
|
@ -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<ChannelSftp.LsEntry> sftpSessionFactory(ReportsServiceSettings settings) {
|
||||
public SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory,
|
||||
ReportsServiceSettings settings
|
||||
) {
|
||||
public MessageHandler handler(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory,
|
||||
ReportsServiceSettings settings
|
||||
) {
|
||||
public MessageHandler handlerList(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> 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<ChannelSftp.LsEntry> sessionFactory
|
||||
) {
|
||||
public IntegrationFlow sftpOutboundListFlow(@Qualifier("reportsSftpSessionFactory") SessionFactory<ChannelSftp.LsEntry> sessionFactory) {
|
||||
return IntegrationFlows.from("reportsListSftpChannel")
|
||||
.handle(new SftpOutboundGateway(sessionFactory, "ls", "payload"))
|
||||
.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.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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue