You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by tnk <ju...@gmail.com> on 2012/01/02 11:37:46 UTC

Camel sftp endpoint and exception handling.

Hello,

I have route (camel 2.7.1):

<route>
  <from uri="sftp://user@host/folder?password=password&delete=true" />
  <onException>
     <exception>java.lang.Exception</exception>
     <log message="ERROR receiving file" loggingLevel="ERROR" />
     <rollback/>
  </onException>
  <to uri="activemq:RECEIVED.FILES.QUEUE" />
</route>

If I don't have permissions to delete the remote file, the same file gets
processed and is put to activemq queue over and over again (onException
block doesn't make any sense, it should rollback message from queue). Using
"idempotent=true" may be a workarround, but in my case I need process files
with the same name after some time.

Exception is logged in DEBUG level:

2012-01-02 12:15:48,281 | DEBUG |  | GenericFileOnCompletion          |
ache.camel.processor.CamelLogger | 52 - org.apache.camel.camel-core -
2.7.1.fuse-00-43 | Caused by: [o
rg.apache.camel.component.file.GenericFileOperationFailedException - Cannot
delete file: /folder/file.xml]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
delete file: /folder/file.xml
        at
org.apache.camel.component.file.remote.SftpOperations.deleteFile(SftpOperations.java:258)[115:org.apache.camel.camel-ftp:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy.commit(GenericFileDeleteProcessStrategy.java:63)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:142)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileOnCompletion.onCompletion(GenericFileOnCompletion.java:84)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileOnCompletion.onComplete(GenericFileOnCompletion.java:53)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.util.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:60)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.impl.DefaultUnitOfWork.done(DefaultUnitOfWork.java:198)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.UnitOfWorkProcessor.doneUow(UnitOfWorkProcessor.java:156)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.UnitOfWorkProcessor.access$000(UnitOfWorkProcessor.java:36)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.UnitOfWorkProcessor$1.done(UnitOfWorkProcessor.java:109)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.DefaultChannel$1.done(DefaultChannel.java:275)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:345)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:269)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:102)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:80)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:330)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:157)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:121)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:88)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
        at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_27-ea]
        at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_27-ea]
        at
java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_27-ea]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_27-ea]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_27-ea]
        at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_27-ea]
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_27-ea]
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_27-ea]
        at java.lang.Thread.run(Thread.java:662)[:1.6.0_27-ea]
Caused by: 3: Permission denied
        at
com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)[117:org.apache.servicemix.bundles.jsch:0.1.44.1]
        at
com.jcraft.jsch.ChannelSftp.rm(ChannelSftp.java:1523)[117:org.apache.servicemix.bundles.jsch:0.1.44.1]
        at
org.apache.camel.component.file.remote.SftpOperations.deleteFile(SftpOperations.java:255)[115:org.apache.camel.camel-ftp:2.7.1.fuse-00-43]
        ... 32 more

		
		
How to catch such exceptions? Why <onException> block doesn't work?

Thanks.

--
View this message in context: http://camel.465427.n5.nabble.com/Camel-sftp-endpoint-and-exception-handling-tp5114385p5114385.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel sftp endpoint and exception handling.

Posted by Raul <lu...@gmail.com>.
Hello again,

I have relized that I must use a ProcessStrategy instead of PollStrategy.
ProcessStrategy can be used in the uri like pollStrategy

uri = "ftp://......&processStrategy=#myProcessStrategy";

This parameter is of Camel-File2 and FTP2 inherits it.

I am using the GenericFileRenameProcessStrategy. Now, The route doesn't
thrown the Exception, but I don't control what it's happening because I
don't know how I must design my ProcessStrategy, also I have seen in FTP-2.8
appeared a new "classs
"org.apache.camel.component.file.remote.strategy.*FtpProcessStrategyFactory*"
but I haven't found any example.

Someone has used a custom processStrategy or someone knows how use
FtpProcessStrategyFactory.

Thank you again.




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-sftp-endpoint-and-exception-handling-tp5114385p5432298.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel sftp endpoint and exception handling.

Posted by Raul <lu...@gmail.com>.
I have a similar problem. (.GenericFileOnCompletion)

[ad #0 - ftp://localhost/origen] GenericFileOnCompletion        ERROR Caused
by: [org.apache.camel.component.file.GenericFileOperationFailedException -
File operation failed:  Software caused connection abort: socket write
error. Code: 250]

In my case, I use a ftp URI with the parametrer move=.done

The route is something like that from(ftp...).to(bean)

In the ftp server there are 5 files. I am testing the route. During the
test, I permit that the first file finishes ok. but when the route is
processing the second file, I let  the file to be received completly and
when the bean is processing y shutdown the ftp server. In this moment the
exception appears because the route can not move the file in the server.

I am using a  DefaultPollingConsumerPollStrategy with ftp. The poll of the
route finishes with COMMIT, instead with a Rollback. I was expecting that
Rollback was executed and then I could catch the exception.

¿Is it posible to control this exception with
DefaultPollingConsumerPollStrategy?

Thank  you.


--
View this message in context: http://camel.465427.n5.nabble.com/Camel-sftp-endpoint-and-exception-handling-tp5114385p5157565.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel sftp endpoint and exception handling.

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

The OnException is handling exceptions as part of *routing* messages
in Camel routes.

There is a window in each consumer where exceptions can occur as well, that is
- before
- after
the Camel routing engine routes the message. If an exception occurs
before or after, then
its per consumer specific how they deal with exceptions.

Usually they will log the exception or something like that, as the
file/ftp consumer does.



On Mon, Jan 2, 2012 at 11:37 AM, tnk <ju...@gmail.com> wrote:
> Hello,
>
> I have route (camel 2.7.1):
>
> <route>
>  <from uri="sftp://user@host/folder?password=password&delete=true" />
>  <onException>
>     <exception>java.lang.Exception</exception>
>     <log message="ERROR receiving file" loggingLevel="ERROR" />
>     <rollback/>
>  </onException>
>  <to uri="activemq:RECEIVED.FILES.QUEUE" />
> </route>
>
> If I don't have permissions to delete the remote file, the same file gets
> processed and is put to activemq queue over and over again (onException
> block doesn't make any sense, it should rollback message from queue). Using
> "idempotent=true" may be a workarround, but in my case I need process files
> with the same name after some time.
>
> Exception is logged in DEBUG level:
>
> 2012-01-02 12:15:48,281 | DEBUG |  | GenericFileOnCompletion          |
> ache.camel.processor.CamelLogger | 52 - org.apache.camel.camel-core -
> 2.7.1.fuse-00-43 | Caused by: [o
> rg.apache.camel.component.file.GenericFileOperationFailedException - Cannot
> delete file: /folder/file.xml]
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> delete file: /folder/file.xml
>        at
> org.apache.camel.component.file.remote.SftpOperations.deleteFile(SftpOperations.java:258)[115:org.apache.camel.camel-ftp:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.strategy.GenericFileDeleteProcessStrategy.commit(GenericFileDeleteProcessStrategy.java:63)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:142)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileOnCompletion.onCompletion(GenericFileOnCompletion.java:84)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileOnCompletion.onComplete(GenericFileOnCompletion.java:53)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.util.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:60)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.impl.DefaultUnitOfWork.done(DefaultUnitOfWork.java:198)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.UnitOfWorkProcessor.doneUow(UnitOfWorkProcessor.java:156)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.UnitOfWorkProcessor.access$000(UnitOfWorkProcessor.java:36)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.UnitOfWorkProcessor$1.done(UnitOfWorkProcessor.java:109)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.DefaultChannel$1.done(DefaultChannel.java:275)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:345)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:269)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:102)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:80)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:98)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:89)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:330)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:157)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:121)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:88)[52:org.apache.camel.camel-core:2.7.1.fuse-00-43]
>        at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_27-ea]
>        at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_27-ea]
>        at
> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_27-ea]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_27-ea]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_27-ea]
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_27-ea]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_27-ea]
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_27-ea]
>        at java.lang.Thread.run(Thread.java:662)[:1.6.0_27-ea]
> Caused by: 3: Permission denied
>        at
> com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)[117:org.apache.servicemix.bundles.jsch:0.1.44.1]
>        at
> com.jcraft.jsch.ChannelSftp.rm(ChannelSftp.java:1523)[117:org.apache.servicemix.bundles.jsch:0.1.44.1]
>        at
> org.apache.camel.component.file.remote.SftpOperations.deleteFile(SftpOperations.java:255)[115:org.apache.camel.camel-ftp:2.7.1.fuse-00-43]
>        ... 32 more
>
>
>
> How to catch such exceptions? Why <onException> block doesn't work?
>
> Thanks.
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-sftp-endpoint-and-exception-handling-tp5114385p5114385.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/