Я пытаюсь подключить оба шлюза Http и SFTP с помощью Spring Integeration ... и хочет прочитать список файлов, т.е. с помощью команды LS.
Это мой код:
// Spring Integration Configuration ..
@Bean(name = "sftp.session.factory")
public SessionFactory<LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
factory.setPort(port);
factory.setHost(host);
factory.setUser(user);
factory.setPassword(password);
factory.setAllowUnknownKeys(allowUnknownKeys);
return new CachingSessionFactory<LsEntry>(factory);
}
@Bean(name = "remote.file.template")
public RemoteFileTemplate<LsEntry> remoteFileTemplate() {
RemoteFileTemplate<LsEntry> remoteFileTemplate = new RemoteFileTemplate<LsEntry>(sftpSessionFactory());
remoteFileTemplate.setRemoteDirectoryExpression(new LiteralExpression(remoteDirectory));
return remoteFileTemplate;
}
@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata poller() {
return Pollers.fixedRate(500).get();
}
/* SFTP READ OPERATION CONFIGURATIONS */
@Bean(name = "http.get.integration.flow")
@DependsOn("http.get.error.channel")
public IntegrationFlow httpGetIntegrationFlow() {
return IntegrationFlows
.from(httpGetGate())
.channel(httpGetRequestChannel())
.handle("sftpService", "performSftpReadOperation")
.get();
}
@Bean
public MessagingGatewaySupport httpGetGate() {
RequestMapping requestMapping = new RequestMapping();
requestMapping.setMethods(HttpMethod.GET);
requestMapping.setPathPatterns("/api/sftp/ping");
HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway();
gateway.setRequestMapping(requestMapping);
gateway.setRequestChannel(httpGetRequestChannel());
gateway.setReplyChannel(httpGetResponseChannel());
gateway.setReplyTimeout(20000);
return gateway;
}
@Bean(name = "http.get.error.channel")
public IntegrationFlow httpGetErrorChannel() {
return IntegrationFlows.from("rejected").transform("'Error while processing request; got' + payload").get();
}
@Bean
@ServiceActivator(inputChannel = "sftp.read.request.channel")
public MessageHandler sftpReadHandler(){
return new SftpOutboundGateway(remoteFileTemplate(), Command.LS.getCommand(), "payload");
}
@Bean(name = "http.get.request.channel")
public MessageChannel httpGetRequestChannel(){
return new DirectChannel(); //new QueueChannel(25);
}
@Bean(name = "http.get.response.channel")
public MessageChannel httpGetResponseChannel(){
return new DirectChannel(); //new QueueChannel(25);
}
@Bean(name = "sftp.read.request.channel")
public MessageChannel sftpReadRequestChannel(){
return new DirectChannel(); //new QueueChannel(25);
}
@Bean(name = "sftp.read.response.channel")
public MessageChannel sftpReadResponseChannel(){
return new DirectChannel(); //new QueueChannel(25);
}
// Шлюз
@MessagingGateway(name="sftpGateway")
public interface SftpMessagingGateway {
@Gateway(requestChannel = "sftp.read.request.channel", replyChannel = "sftp.read.response.channel")
@Description("Handles Sftp Outbound READ Request")
Future<Message> readListOfFiles();
}
// ServiceActivator, то есть основная логика.
@Autowired
private SftpMessagingGateway sftpGateway;
@ServiceActivator(inputChannel = "http.get.request.channel", outputChannel="http.get.response.channel")
public ResponseEntity<String> performSftpReadOperation(Message<?> message) throws ExecutionException, InterruptedException {
System.out.println("performSftpReadOperation()");
ResponseEntity<String> responseEntity;
Future<Message> result = sftpGateway.readListOfFiles();
while(!result.isDone()){
Thread.sleep(300);
System.out.println("Waitign.....");
}
if(Objects.nonNull(result)){
List<SftpFileInfo> listOfFiles = (List<SftpFileInfo>) result.get().getPayload();
System.out.println("Sftp File Info: "+listOfFiles);
responseEntity = new ResponseEntity<String>("Sftp Server is UP and Running", HttpStatus.OK);
}
else {
responseEntity = new ResponseEntity<String>("Error while acessing Sftp Server. Please try again later!!!", HttpStatus.SERVICE_UNAVAILABLE);
}
return responseEntity;
}
Всякий раз, когда я достигаю конца-точка ("/ api / sftp / ping") перешла в цикл:
executeSftpReadOperation () Waitign .....
executeSftpReadOperation () Waitign .....
executeSftpReadOperation () Waitign .....
executeSftpReadOperation () Waitign .....
executeSftpReadOperation () Waitign .....
Kindlyнаправьте меня, как решить эту проблему.Может быть некоторая проблема с httpGetIntegrationFlow ().Спасибо