0

I have a requirement is to read file from a FTP remote directory insert payload values into database and then move file from remote directory /in to remote directory /archive of same FTP server.

I am using spring integration @InboundChannelAdapter and able to invoke ExpressionEvaluatingTransactionSynchronizationProcessor setAfterCommitExpression. I am struggling to find a way to construct a spel parse expression to move from inbound remote directory to another.

2 Answers 2

0

The setAfterCommitExpression is executed against Message as a root object. That message is exactly what FtpInboundFileSynchronizingMessageSource is producing. The payload of this message is an FTPFile. There are also some additional headers:

            messageBuilder.setHeader(FileHeaders.REMOTE_HOST_PORT, uri.getHost() + ':' + uri.getPort())
                    .setHeader(FileHeaders.REMOTE_DIRECTORY, uri.getPath())
                    .setHeader(FileHeaders.REMOTE_FILE, uri.getFragment());

So, you may call some service from that expression like @myFtpMoveService.moveRemoteFile(#root) and accept in that method a Message with all the info you needed to determine the remote file, its name and directory.

Sign up to request clarification or add additional context in comments.

Comments

0

I created a Messaging Gateway

@MessagingGateway
public interface FtpGateway {
  @Gateway(requestChannel = "ftpChannel")
  void sendFile(File file);
}

and @ServiceActivator

 @Bean
  @ServiceActivator(inputChannel = "ftpChannel")
  public MessageHandler ftpFileTransferMessageHandler() {
    // MessageHandler config..
  }

and provided @Gateway method "@ftpGateway.sendFileToArchive(payload)") as SPEL to the setAfterCommitExpression in TransactionSynchronizationFactory

  spelParser.parseExpression("@ftpGateway.sendFileToArchive(payload)"));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.