SFTPConfig fixed
This commit is contained in:
parent
e2d043e322
commit
c0c6a9813a
4 changed files with 50 additions and 20 deletions
|
|
@ -13,12 +13,12 @@ import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.expression.ExpressionParser;
|
import org.springframework.expression.ExpressionParser;
|
||||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||||
import org.springframework.integration.annotation.Gateway;
|
import org.springframework.integration.annotation.Gateway;
|
||||||
import org.springframework.integration.annotation.MessagingGateway;
|
|
||||||
import org.springframework.integration.annotation.ServiceActivator;
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.channel.DirectChannel;
|
import org.springframework.integration.channel.DirectChannel;
|
||||||
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
|
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
|
||||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||||
|
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
|
||||||
import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
|
import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
|
||||||
import org.springframework.integration.sftp.outbound.SftpMessageHandler;
|
import org.springframework.integration.sftp.outbound.SftpMessageHandler;
|
||||||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
||||||
|
|
@ -29,8 +29,8 @@ import org.springframework.messaging.handler.annotation.Header;
|
||||||
import org.springframework.messaging.handler.annotation.Payload;
|
import org.springframework.messaging.handler.annotation.Payload;
|
||||||
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
|
import ru.spcex.clearing.xml.exporter.config.settings.ExportXMLServiceSettings;
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Profile("!test")
|
@Profile("!test")
|
||||||
|
@Configuration
|
||||||
public class SFTPConfig {
|
public class SFTPConfig {
|
||||||
protected Logger log = LoggerFactory.getLogger(getClass());
|
protected Logger log = LoggerFactory.getLogger(getClass());
|
||||||
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
protected static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
||||||
|
|
@ -55,14 +55,19 @@ public class SFTPConfig {
|
||||||
handler.setFileNameGenerator(message -> {
|
handler.setFileNameGenerator(message -> {
|
||||||
if (message.getPayload() instanceof File) {
|
if (message.getPayload() instanceof File) {
|
||||||
return ((File) message.getPayload()).getName();
|
return ((File) message.getPayload()).getName();
|
||||||
}else {
|
} else {
|
||||||
throw new IllegalArgumentException("File must expected as payload.");
|
throw new IllegalArgumentException("File must expected as payload.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagingGateway
|
// https://stackoverflow.com/questions/53655208/profile-doesnt-work-with-messaging-gateway
|
||||||
|
@Bean("xmlGateway")
|
||||||
|
public AnnotationGatewayProxyFactoryBean xmlGateway() {
|
||||||
|
return new AnnotationGatewayProxyFactoryBean(XmlGateway.class);
|
||||||
|
}
|
||||||
|
|
||||||
public interface XmlGateway {
|
public interface XmlGateway {
|
||||||
@Gateway(requestChannel = "toSftpChannel")
|
@Gateway(requestChannel = "toSftpChannel")
|
||||||
void sendToSftp(@Payload File file, @Header("path") String path);
|
void sendToSftp(@Payload File file, @Header("path") String path);
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,18 @@
|
||||||
package ru.spcex.clearing.xml.exporter.config;
|
package ru.spcex.clearing.xml.exporter.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.integration.sftp.session.SftpFileInfo;
|
import org.springframework.integration.sftp.session.SftpFileInfo;
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@Profile("test")
|
@Profile("test")
|
||||||
public class SFTPTestConfig {
|
@Configuration
|
||||||
@Bean
|
public class SFTPMockConfig {
|
||||||
@Qualifier("mockSFTP")
|
@Bean("xmlGateway")
|
||||||
public SFTPConfig.XmlGateway xmlGateway(){
|
public SFTPConfig.XmlGateway dbfGateway(){
|
||||||
return new XGateway();
|
return new XGateway();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -26,8 +25,7 @@ public class SFTPTestConfig {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SftpFileInfo> listFiles(String dir) {
|
public List<SftpFileInfo> listFiles(String dir) {
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,30 +9,27 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
import org.springframework.integration.annotation.Gateway;
|
import org.springframework.integration.annotation.Gateway;
|
||||||
import org.springframework.integration.annotation.MessagingGateway;
|
|
||||||
import org.springframework.integration.annotation.ServiceActivator;
|
import org.springframework.integration.annotation.ServiceActivator;
|
||||||
import org.springframework.integration.channel.DirectChannel;
|
import org.springframework.integration.channel.DirectChannel;
|
||||||
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
|
import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway;
|
||||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||||
|
import org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean;
|
||||||
import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
|
import org.springframework.integration.sftp.gateway.SftpOutboundGateway;
|
||||||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
||||||
import org.springframework.messaging.MessageChannel;
|
import org.springframework.messaging.MessageChannel;
|
||||||
import org.springframework.messaging.MessageHandler;
|
import org.springframework.messaging.MessageHandler;
|
||||||
import ru.spcex.clearing.xml.importer.config.settings.ImportXMLServiceSettings;
|
import ru.spcex.clearing.xml.importer.config.settings.ImportXMLServiceSettings;
|
||||||
|
|
||||||
|
@Profile("!test")
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SFTPConfig {
|
public class SFTPConfig {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final ImportXMLServiceSettings settings;
|
|
||||||
|
|
||||||
public SFTPConfig(ImportXMLServiceSettings settings) {
|
|
||||||
this.settings = settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
|
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory(ImportXMLServiceSettings settings) {
|
||||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
|
||||||
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
factory.setHost(settings.getStore().getSftpIn().getServerIp());
|
||||||
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
factory.setPort(settings.getStore().getSftpIn().getServerPort());
|
||||||
|
|
@ -42,7 +39,12 @@ public class SFTPConfig {
|
||||||
return new CachingSessionFactory<>(factory);
|
return new CachingSessionFactory<>(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagingGateway
|
// https://stackoverflow.com/questions/53655208/profile-doesnt-work-with-messaging-gateway
|
||||||
|
@Bean("xmlGateway")
|
||||||
|
public AnnotationGatewayProxyFactoryBean xmlGateway() {
|
||||||
|
return new AnnotationGatewayProxyFactoryBean(XmlGateway.class);
|
||||||
|
}
|
||||||
|
|
||||||
public interface XmlGateway {
|
public interface XmlGateway {
|
||||||
@Gateway(requestChannel = "listSftpChannel")
|
@Gateway(requestChannel = "listSftpChannel")
|
||||||
List<File> listFiles(String dir);
|
List<File> listFiles(String dir);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ru.spcex.clearing.xml.importer.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
||||||
|
@Profile("test")
|
||||||
|
@Configuration
|
||||||
|
public class SFTPMockConfig {
|
||||||
|
@Bean("xmlGateway")
|
||||||
|
public SFTPConfig.XmlGateway xmlGateway(){
|
||||||
|
return new XGateway();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class XGateway implements SFTPConfig.XmlGateway{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<File> listFiles(String dir) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue