Results 1 to 6 of 6

Thread: sftp channel adapter

  1. #1
    Join Date
    Feb 2012
    Posts
    101

    Default sftp channel adapter

    Hi,

    I'm using sftp channel adapter to transfer a bulk of files.I would like to know, in case of failure if the exact reason can be determined.

    like i tried "sftp user@host" and it says permission denied ,

    but when I try through the channel adapter all I'm getting is file transfer failed.

    Please let me know of more exceptions that I can handle to get more elaborate message failures.

    Thanks

  2. #2
    Join Date
    Aug 2005
    Location
    Atlanta
    Posts
    124

    Default

    Hi,

    Did you set up an error channel? Also, do you use SFTP Inbound or Outbound Channel Adapters? If you could, please provide a little bit more context around your issue.

    Thanks!

    Cheers,

    Gunnar
    Gunnar Hillert
    SpringSource/VMWare, Spring Integration team
    SpringSource Team - Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/ghillert
    http://blog.hillert.com/
    http://blog.springsource.com/author/ghillert/

  3. #3
    Join Date
    Feb 2012
    Posts
    101

    Default

    Hi Gunnar,

    Thanks for the reply.

    I have set up the ftp channel adapter.

    I also set up the error channel but it does not see to work for me..

    Here is the code snippet

    This is the sftp Channel adapter.

    <Code>
    <sftp:outbound-channel-adapter channel="sendChannel"
    session-factory="sftpSessionFactory" id="sftpInboundAdapter1"
    auto-create-directory="true" temporary-file-suffix="temp"
    remote-directory-expression="headers['remote-directory']" />
    </Code>

    xml configuration for handling error
    <Code>

    <bean id="errorException"
    class="org.springframework.integration.router.Erro rMessageExceptionTypeRouter">
    <property name="channelMappings">
    <util:map>
    <entry key="java.lang.Exception" value="retrySftpChannel1" />
    </util:map>
    </property>
    <property name="defaultOutputChannel" ref="processChannel1" />
    </bean>

    <int:channel id="processChannel1" />
    <int:channel id="retrySftpCahnnel1" />

    <int:service-activator input-channel="processChannel1"
    ref="pmExporter" method="messageException" />

    <!-- using a transformer to get the failed message -->
    <int:transformer input-channel="retrySftpChannel1"
    output-channel="retryChannel1"
    expression="T(org.springframework.integration.supp ort.MessageBuilder).
    withPayload(payload.getFailedMessage().getPayload( )).build()" />

    <!-- the file will be written to a failed directory -->

    <int:service-activator input-channel="retryChannel1"
    ref="pmExporter" method="retryMessage">
    </int:service-activator>


    </Code>

    I'm assuming the above code is the error channel.Please let me know if it is not,
    These above exceptions do not work for me so,I have the try ,catch blocks and within the java program and there I handle
    these below exception once the message is sent in the sftp channel and within the catch blocks of the exceptions I individually handle the messages in case of failure for any resaon.

    <Code>
    catch(MessageHandlingException ex)
    catch(com.jcraft.jsch.JSchException ex)
    catch(java.net.SocketException ex)

    </code>

    Please let me know if this makes sense otherwise I will put in more code

    Thanks

  4. #4
    Join Date
    Feb 2012
    Posts
    101

    Default error handling

    Hi Gunnar,

    Thanks for the reply.

    I have set up the ftp channel adapter.

    I also set up the error channel but it does not see to work for me..

    Here is the code snippet

    This is the sftp Channel adapter.

    Code:
    <sftp:outbound-channel-adapter channel="sendChannel"
             session-factory="sftpSessionFactory" id="sftpInboundAdapter1"
             auto-create-directory="true" temporary-file-suffix="temp"
             remote-directory-expression="headers['remote-directory']" />
    xml configuration for handling error


    Code:
    <bean id="errorException"
             class="org.springframework.integration.router.Erro  rMessageExceptionTypeRouter">
             <property name="channelMappings">
                 <util:map>
                     <entry key="java.lang.Exception" value="retrySftpChannel1" />
                 </util:map>
             </property>
             <property name="defaultOutputChannel" ref="processChannel1" />
         </bean>
     
         <int:channel id="processChannel1" />
         <int:channel id="retrySftpCahnnel1" />
     
         <int:service-activator input-channel="processChannel1"
             ref="pmExporter" method="messageException" />
     
         <!-- using a transformer to get the failed message -->
         <int:transformer input-channel="retrySftpChannel1"
             output-channel="retryChannel1"
             expression="T(org.springframework.integration.supp  ort.MessageBuilder).
                  withPayload(payload.getFailedMessage().getPayload(  )).build()" />
     
         <!-- the file will be written to a failed directory -->
     
         <int:service-activator input-channel="retryChannel1"
             ref="pmExporter" method="retryMessage">
         </int:service-activator>

    I'm assuming the above code is the error channel.Please let me know if it is not,
    These above exceptions do not work for me so,I have the try ,catch blocks and within the java program and there I handle
    these below exception once the message is sent in the sftp channel and within the catch blocks of the exceptions I individually handle the messages in case of failure for any resaon.




    Code:
    catch(MessageHandlingException ex)
     catch(com.jcraft.jsch.JSchException ex)
     catch(java.net.SocketException ex)
    Please let me know if this makes sense otherwise I will put in more code

    Thanks

  5. #5
    Join Date
    Aug 2005
    Location
    Atlanta
    Posts
    124

    Default

    Hi,

    The question is - How did you configure your "sendChannel"? It looks too me you have configured it as a 'DirectChannel', which operates on the same thread as the calling endpoint. In that instance calling try+catch is the correct approach.

    For more asynchronous handling, configure your "sendChannel" as a QueueChannel, e.g.:

    Code:
    	<int:channel id="sendChannel">
    		<int:queue capacity="500"/>
    	</int:channel>
    Then, you can provide an "error-channel" attribute on the Poller, that retrieves messages from the queue channel. Alternatively, you can use a global "errorChannel", or provide the "errorChannel" Message header (org.springframework.integration.MessageHeaders.ER ROR_CHANNEL) for each message for the most fine-grained routing of error messages.

    For more information see Appendix "B.4 Error Handling" of the reference manual:

    http://static.springsource.org/sprin...e-errorhandler

    I hope this steers you into the right direction.

    Cheers,

    Gunnar
    Gunnar Hillert
    SpringSource/VMWare, Spring Integration team
    SpringSource Team - Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/ghillert
    http://blog.hillert.com/
    http://blog.springsource.com/author/ghillert/

  6. #6
    Join Date
    Feb 2012
    Posts
    101

    Default

    Yes,you are correct.

    I only set it as Direct channel

    <CODE>
    <int:channel id="sendChannel" />
    </CODE>

    Please let me know how to configure a global error channel.Will also take a look at the link.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •