1

Is there any sane way to handle authentication failure at an sftp endpoint?

I have a camel route with sftp endpoint, specifically it moves files to sftp. When the sftp location is not available, i want to:

  • If its an authentication failure, log, and do not retry. Move original files to failure folder.
  • If the host is unknow, log and dont retry. Move original files to failure folder.
  • Otherwise: retry a few times before failure.

Unfortunately SftpOperations always keeps on retrying. In the case of authentication failure (which can easily happen if the person deploying the app makes a typo in the properties file) this means repeated attempts with the wrong credentials. If it's just the password that is wrong, it may lead to the user being blocked.

Ivana
  • 643
  • 10
  • 27

1 Answers1

0

In my specific case i decided i wasn't going to retry at all in case of an error at the sftp endpoint. This is achieved by adding the following to the route configuration:

   &maximumReconnectAttempts=0&throwExceptionOnConnectFailed=true&consumer.bridgeErrorHandler=true

The route now fails after the first attempt. In a more general case if you want to handle different exceptions (see this question) you can use onException like this:

        from(route.getDownloadFromUri())
            .routeId(route.getRouteId())
            .routePolicy(getRoutePolicy())
            .onException(JSchException.class)
                .maximumRedeliveries(2)
                .handled(true)
                .log(LoggingLevel.ERROR, LOG, "!!!! Caught JSchException")
                .to(SEND_EMAIL_ROUTE)
                .end()
            .onException(Throwable.class)
                .maximumRedeliveries(5)
                .handled(true)
                .log(LoggingLevel.ERROR, LOG, "Error moving file ${file:name}: ${exception}")
                .to(SEND_EMAIL_ROUTE)
                .end()
            .onException(IgnoreException.class) // Do nothing, just end processing so routePolicy onEchangeDone is executed
                .handled(true)
                .end()
Ivana
  • 643
  • 10
  • 27