0

Im trying to download a file with dynamic filenames using pollEnrich in a loop , when there is a conenction exception at pollEnrich it was not handled in onException block even io cannot us docatch after the pollenrich statment.

i also tried using throwExceptionOnConnectFailed=true in endpoint uri. Not no use.

do this have any workaround?

onException(Exception.class)    
.log( "${exception.stacktrace}")
.end();

from("direct:DownloadFiles")
.loop(exchangeProperty("FileCount"))
.pollEnrich().simple("sftp://testeruser:password@localhost:24?
    move=Processed&antInclude=*${property.soNumber}*.*").timeout(30000)
.to("TARGET SFTP endpoint")
.end();
burki
  • 6,741
  • 1
  • 15
  • 31
  • You should at least post your Camel route in your question. Otherwise it is almost impossible to help you. – burki Jun 28 '18 at 07:40
  • Updated the post with sample snippet – user1651118 Jun 28 '18 at 10:09
  • I don't see any obvious problems. How do you mean the Exceptions are not handled in the onException block? That the onException block is not called at all or that the Exception is rethrow to the caller? – burki Jun 29 '18 at 11:07
  • Im seeing just a WARN log and the next step of execution is continured assuming body received is null from pollEnrich endpoint – user1651118 Jul 02 '18 at 06:48
  • Do you even have a connect exception? Or is just the timeout reached and therefore the routing continues without fetched file? – burki Jul 02 '18 at 07:33
  • In Either of the scenarios im trying to catch the exception. – user1651118 Jul 02 '18 at 15:04
  • But in case you just reach the timeout, there is AFAIK no Exception thrown. I suspect you don't get an Exception. Therefore you will not be able to catch something that does not exist. – burki Jul 02 '18 at 15:30
  • If you want to know if your Exception handler works, add for example a bean or processor to your route that throws an Exception. – burki Jul 02 '18 at 15:31
  • Yes if an exception is thrown from bean or processor it works, but i want to handle connect exception when using consumerTemplate or pollenrich.. is there any way to handle it?? – user1651118 Jul 11 '18 at 04:41

1 Answers1

1

By default Camel ignores connection problems

} catch (Exception e) {
        loggedIn = false;

        // login failed should we thrown exception
        if (getEndpoint().getConfiguration().isThrowExceptionOnConnectFailed()) {
            throw e;
        }
}

Therefore you have to enable the option throwExceptionOnConnectFailed on the SFTP consumer. In your case this would be

.pollEnrich()
     .simple("sftp://testeruser:password@localhost:24?move=Processed&throwExceptionOnConnectFailed=true&antInclude=*${property.soNumber}*.*")
     .timeout(30000)

I know you write in your question that you tried that option without success, but in my test it is this option that decides (according to the Camel code above) if the ConnectException is reaching the error handler or is ignored.

burki
  • 6,741
  • 1
  • 15
  • 31