2

I'm using the DSL API way for configuring an SftpOutboundGateway for issuing custom commands. In the example below I'm uploading a file and move it remotely afterwards:

public IntegrationFlow sftpOutboundFlow() {
    return from(getFileToSftpChannel()).handle(Sftp.outboundGateway(getSftpSessionFactory(), PUT, "dir")).handle(Sftp.outboundGateway(getSftpSessionFactory(), MV, "dir")).channel(new NullChannel()).get();

But, when I run this, I get:

Caused by: java.lang.IllegalArgumentException: 'remoteDirectoryExpression' is required
at org.springframework.util.Assert.notNull(Assert.java:115)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:276)
at org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:272)
at org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.doPut(AbstractRemoteFileOutboundGateway.java:597)

The reason is that RemoteFileTemplate is supposed to be initialized by Spring (InitializingBean, BeanFactoryAware) but it is not:

AbstractRemoteFileOutboundGateway

/**
 * Construct an instance with the supplied session factory, a command ('ls', 'get'
 * etc), and an expression to determine the filename.
 * @param sessionFactory the session factory.
 * @param command the command.
 * @param expression the filename expression.
 */
public AbstractRemoteFileOutboundGateway(SessionFactory<F> sessionFactory, Command command, String expression) {
    this(new RemoteFileTemplate<F>(sessionFactory), command, expression);
}

Is this a bug or am I using this incorrectly? Thanks.

1 Answers1

0

Well, it's not fully a bug...

The remoteDirectoryExpression is an option of RemoteFileTemplate which can be injected to the Sftp.outboundGateway() since Spring Integration Java DSL 1.1.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Ok, so I read that the way I'm using it is not working because of a bug (where I can log this ticket?) and the alternative/workaround is injecting the RemoteFileTemplate myself. Correct? – Koen Serneels Sep 24 '15 at 20:00
  • OK. If you'd like you can raise it here: https://github.com/spring-projects/spring-integration-java-dsl/issues. And even contribute the fix ! – Artem Bilan Sep 24 '15 at 20:21