How to invoke sftp:outbound-gateway from spring batch?

emph

I would like to invoke sftp:outbound-gateway from batch tasklet in order to download a file from sftp server. I've seen other posts related to this subject but I'm not sure what am I doing wrong. Could anybody give me a hint based on my configuration? My batch works so the problem is just to ivoke the sftp component in batch step. I've marked the Spring Integration section with comment so it is easier to read just a relevant configuration.

I can see in my logs: DEBUG [o.s.i.e.SourcePollingChannelAdapter] Received no Message during the poll, returning 'false'. So I am not receiving a file but why?

Thanks in advance for your time spend on analysis!

<bean id="ftsSftpClientFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
    <property name="host" value="${my.import.sftp.localhost}"/>
    <property name="user" value="${my.import.sftp.username}"/>
    <property name="password" value="${my.import.sftp.passwort}"/>
</bean>

  <!-- Start: Spring Integration -->

    <int:channel id="replyChannel" >
        <int:queue/>
    </int:channel>

    <int:channel id="requestChannel" />

    <int-sftp:outbound-gateway id="sftpGateway"
                               session-factory="ftsSftpClientFactory"
                               request-channel="requestChannel"
                               reply-channel="replyChannel"
                               auto-startup="true"
                               command="get"
                               command-options="-P"
                               expression="payload"
                               remote-directory="."
                               local-directory="${my.import.sftp.copy.file.destinationpath}">
    </int-sftp:outbound-gateway>

<bean name="copyFileTasklet" class="com.mydomain.CopyFileTasklet">
    <property name="channel" ref="replyChannel" />
    <property name="pollableChannel" ref="requestChannel" />
</bean>
<!-- Start: Spring Batch -->
<bean name="myImportTask" class="com.mydomain.MyImportTask">
    <property name="job" ref="unternehmungImportJob"/>
    <property name="jobLauncher" ref="jobLauncher"/>
</bean>

<bean id="jobDetail"
      class="com.mydomain.MyImportJob">
    <property name="myImportTask" ref="myImportTask" />
</bean>

<!--suppress SpringBatchModel -->
<batch:job id="myImportJob">
    <batch:step id="copy-file-step" next="my-import-step">
        <batch:tasklet ref="copyFileTasklet"/>
    </batch:step>
    <batch:step id="my-import-step">
        <batch:tasklet>
            <batch:chunk reader="myItemReader"
                         writer="myItemWriter"
                         commit-interval="10000">
                <!--
                skip-limit="10000"
                <batch:skippable-exception-classes>
                   <batch:include class="java.lang.Exception"/>
                   <batch:exclude class="java.io.FileNotFoundException"/>
                </batch:skippable-exception-classes> -->
            </batch:chunk>
            <batch:transaction-attributes isolation="DEFAULT" propagation="REQUIRED"/>
        </batch:tasklet>
    </batch:step>
</batch:job>

<bean id="myItemReader" scope="step" class="org.springframework.batch.item.file.FlatFileItemReader">
    <property name="linesToSkip" value="1"/>
    <property name="encoding" value="${my.import.batch.encoding}" />
    <property name="resource" value="${my.import.batch.input.resource}"/>
    <property name="lineMapper">
        <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
            <property name="lineTokenizer" ref="lineTokenizer"/>
            <property name="fieldSetMapper">
                <bean class="com.mydomain.MyImportMapper"/>
            </property>
        </bean>
    </property>
</bean>

<bean id="myItemWriter" class="com.mydomain.MyItemWriter">
    <property name="myApplicationService" ref="defaultmyApplicationService" />
</bean>

<bean id="lineTokenizer" class="com.mydomain.DelimitedLineTokenizerWithEOF">
    <property name="delimiter" value="${my.import.batch.delimiter}" />
    <property name="eofMarker" value="${my.import.batch.eof.marker}" />
</bean>

public class CopyFileTasklet implements Tasklet {

private MessageChannel requestChannel;

private PollableChannel replyChannel;

public void setRequestChannel(MessageChannel requestChannel) {
    this.requestChannel = requestChannel;
}

public void setReplyChannel(PollableChannel replyChannel) {
    this.replyChannel = replyChannel;
}

@Override
public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {

    Message<?> result = replyChannel.receive(10000);
    Object file = result.getPayload();       
    return RepeatStatus.FINISHED;
}

}

Artem Bilan

Your issue that you don't inititate Integration Flow from your custom Tasklet. Of course you can't receive anything from the replyChannel, if you haven't sent request before.

If you just need to process Integration Flow and get result from it, it would be better to use POJI <gateway> from that Tasklet:

public interface SftpGateway {

   File download(String fileName);

}

<gateway id="sftpGateway" service-interface="com.my.proj.SftpGateway"
    default-request-channel="requestChannel"/>


<bean name="copyFileTasklet" class="com.mydomain.CopyFileTasklet">
    <property name="sftpGateway" ref="sftpGateway" />
</bean>

Something like that.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to invoke sftp:outbound-gateway from spring batch?

From Dev

spring integration sftp outbound gateway remove

From Dev

SFTP Outbound Gateway not working

From Dev

Spring Integration Java DSL - How to invoke int-http:outbound-gateway?

From Dev

Spring Integration Java DSL - How to invoke int-http:outbound-gateway?

From Dev

spring SFTP outbound gateway transfer file to other location

From Dev

How to configure SFTP Outbound Gateway using Java Config?

From Dev

spring amqp-outbound gateway to produce reply from a different thead (Like jms-outbound gateway)

From Dev

Spring Integration - how to send POST parameters with http outbound-gateway

From Dev

Spring integration: How to post request params with http outbound gateway

From Dev

Spring integration how to handle Json Payload in ws:outbound-gateway

From Dev

Callback in Outbound Gateway Spring Integration

From Dev

Spring Integration with Spring Data Rest: empty payload in response from outbound-gateway

From Dev

Spring Integration | jdbc outbound gateway/adapter

From Dev

Spring integration http outbound gateway logging errors

From Dev

Spring Integration: Programmatically send request to outbound gateway

From Dev

Spring Integration Http Outbound Gateway Header Mapper

From Dev

Spring Integration stored procedure outbound gateway

From Dev

Spring integration dsl: http outbound gateway

From Dev

Spring Integration DSL - Outbound Gateway with access to Headers

From Dev

Spring integration file outbound-gateway and webService

From Dev

Spring Integration Outbound Gateway is not encoding the URL

From Dev

Spring Integration FTP Outbound Gateway console output

From Dev

Passing arguments from Java to url-expression in Spring Integration outbound-gateway

From Dev

Spring Integration : How to guarantee the transaction two more jdbc-outbound-gateway?

From Dev

How to Implement Spring Integration int-jdbc:stored-proc-outbound-gateway with advanced Oracle type IN parameter

From Dev

How can I create http outbound-gateway with JAVA config in Spring integration?

From Dev

How to send JSONP request using int-http:outbound-gateway in Spring Integration?

From Dev

Spring Integration: how to send a Byte Array as POST parameter with an http:outbound-gateway?

Related Related

  1. 1

    How to invoke sftp:outbound-gateway from spring batch?

  2. 2

    spring integration sftp outbound gateway remove

  3. 3

    SFTP Outbound Gateway not working

  4. 4

    Spring Integration Java DSL - How to invoke int-http:outbound-gateway?

  5. 5

    Spring Integration Java DSL - How to invoke int-http:outbound-gateway?

  6. 6

    spring SFTP outbound gateway transfer file to other location

  7. 7

    How to configure SFTP Outbound Gateway using Java Config?

  8. 8

    spring amqp-outbound gateway to produce reply from a different thead (Like jms-outbound gateway)

  9. 9

    Spring Integration - how to send POST parameters with http outbound-gateway

  10. 10

    Spring integration: How to post request params with http outbound gateway

  11. 11

    Spring integration how to handle Json Payload in ws:outbound-gateway

  12. 12

    Callback in Outbound Gateway Spring Integration

  13. 13

    Spring Integration with Spring Data Rest: empty payload in response from outbound-gateway

  14. 14

    Spring Integration | jdbc outbound gateway/adapter

  15. 15

    Spring integration http outbound gateway logging errors

  16. 16

    Spring Integration: Programmatically send request to outbound gateway

  17. 17

    Spring Integration Http Outbound Gateway Header Mapper

  18. 18

    Spring Integration stored procedure outbound gateway

  19. 19

    Spring integration dsl: http outbound gateway

  20. 20

    Spring Integration DSL - Outbound Gateway with access to Headers

  21. 21

    Spring integration file outbound-gateway and webService

  22. 22

    Spring Integration Outbound Gateway is not encoding the URL

  23. 23

    Spring Integration FTP Outbound Gateway console output

  24. 24

    Passing arguments from Java to url-expression in Spring Integration outbound-gateway

  25. 25

    Spring Integration : How to guarantee the transaction two more jdbc-outbound-gateway?

  26. 26

    How to Implement Spring Integration int-jdbc:stored-proc-outbound-gateway with advanced Oracle type IN parameter

  27. 27

    How can I create http outbound-gateway with JAVA config in Spring integration?

  28. 28

    How to send JSONP request using int-http:outbound-gateway in Spring Integration?

  29. 29

    Spring Integration: how to send a Byte Array as POST parameter with an http:outbound-gateway?

HotTag

Archive