You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sarfaraj <sa...@gmail.com> on 2013/05/06 07:30:56 UTC

Exception handling for camel-ftp

Hi,

I am using camel-ftp (2.10.4) in my camel application(camel-route).

If the ftp related error occured like wrong credential or incorrect IP then
it throws
"org.apache.camel.component.file.GenericFileOperationFailedException"
exception. 

I want to retry 3 times if FTP error occured, for that i added below code in
route file.
<onException>

<exception>org.apache.camel.component.file.GenericFileOperationFailedException</exception>
	<redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="300000" />
<onException>

But what happen here I am also using <from uri="file:src/target" /> in same
file and in someof the case this code also throws the same
"org.apache.camel.component.file.GenericFileOperationFailedException"
exception.

So my question is how do i differe both exception ? I want to retry if FTP
error occrrued else not.


/Sarfaraj



--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling for camel-ftp

Posted by Claus Ibsen <cl...@gmail.com>.
Its the FTP server that returns the errors. So you should go look for
the FTP error codes. There is some standard codes. So google and find
them.

And as said you can use getCode on the exception to get the code, and
use that in your check instead of the error message text.

On Mon, May 6, 2013 at 9:54 AM, sarfaraj <sa...@gmail.com> wrote:
> I can see one more exception now
>
> org.apache.camel.component.file.GenericFileOperationFailedException: File
> operation failed:  Connection closed without indication
>
> How can I confirm that all exception covered using <onWhen>
>
> Its very difficult for me to find all . Can someone tell me what is the best
> way to cover all FTP exception? I don't want to miss any, also don't want to
> retry in case of local file error i.e. file:src/target.
>
> /Sarfaraj
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732070.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Exception handling for camel-ftp

Posted by sarfaraj <sa...@gmail.com>.
I can see one more exception now

org.apache.camel.component.file.GenericFileOperationFailedException: File
operation failed:  Connection closed without indication

How can I confirm that all exception covered using <onWhen>

Its very difficult for me to find all . Can someone tell me what is the best
way to cover all FTP exception? I don't want to miss any, also don't want to
retry in case of local file error i.e. file:src/target.

/Sarfaraj



--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732070.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling for camel-ftp

Posted by sarfaraj <sa...@gmail.com>.
Currently i am aware of these two only. I dont know others if any



--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732065.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling for camel-ftp

Posted by sarfaraj <sa...@gmail.com>.
Yes I want to do in XML only.

Adding below two lines will cover these two exception. But I am not sure
about other (all) FTP related exception.

Basically I need a list, what all exception will occur in case of FTP used.
So i can add that exception in <onWhen>

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
connect to <XXX file system location> OR 
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
store file: <XXX file system location>

>>>>>>>>>>>>>>> 
<onWhen><simple>${exception.message} contains 'connect to'</simple><onWhen>
<onWhen><simple>${exception.message} contains 'store file'</simple><onWhen>
>>>>>>>>>>>>>>>






--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732063.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling for camel-ftp

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

If you have a copy of Camel in Action, then see page 150.

If you want to do in XML then you can possible do

<onWhen><simple>${exception.message} contains 'connect to'</simple><onWhen>

But you can also use a java bean

public static boolean
isConnectError(GenericFileOperationFailedException cause) {
   ...
}

<bean id="myBean" class="com.foo.MyErrorBean"/>

<onWhen><method ref="myBean" method="isConnectError"/></onWhen>



On Mon, May 6, 2013 at 8:00 AM, sarfaraj <sa...@gmail.com> wrote:
> Thanks clause. Have follow up question.
>
> Currently I see two below exceptions in FTP
>
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> connect to <XXX file system location> OR
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> store file: <XXX file system location>
>
>
> But I am not sure about which predicate to use in <onWhen> which will make
> sure that to retry when FTP exception occurred. I tried few things also
> googled but no luck.
>
> /Sarfaraj
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732056.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Exception handling for camel-ftp

Posted by sarfaraj <sa...@gmail.com>.
Thanks clause. Have follow up question.

Currently I see two below exceptions in FTP

org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
connect to <XXX file system location> OR
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
store file: <XXX file system location>


But I am not sure about which predicate to use in <onWhen> which will make
sure that to retry when FTP exception occurred. I tried few things also
googled but no luck.

/Sarfaraj



--
View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051p5732056.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Exception handling for camel-ftp

Posted by Claus Ibsen <cl...@gmail.com>.
You can use <onWhen> in the <onException> and use a predicate to check
if you want to react or not. The GenericFileOperationFailedException
ought to have a getCode / getReason() or something that returns the
FTP error code.



On Mon, May 6, 2013 at 7:30 AM, sarfaraj <sa...@gmail.com> wrote:
> Hi,
>
> I am using camel-ftp (2.10.4) in my camel application(camel-route).
>
> If the ftp related error occured like wrong credential or incorrect IP then
> it throws
> "org.apache.camel.component.file.GenericFileOperationFailedException"
> exception.
>
> I want to retry 3 times if FTP error occured, for that i added below code in
> route file.
> <onException>
>
> <exception>org.apache.camel.component.file.GenericFileOperationFailedException</exception>
>         <redeliveryPolicy maximumRedeliveries="3" redeliveryDelay="300000" />
> <onException>
>
> But what happen here I am also using <from uri="file:src/target" /> in same
> file and in someof the case this code also throws the same
> "org.apache.camel.component.file.GenericFileOperationFailedException"
> exception.
>
> So my question is how do i differe both exception ? I want to retry if FTP
> error occrrued else not.
>
>
> /Sarfaraj
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Exception-handling-for-camel-ftp-tp5732051.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen