You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by stefzar <st...@hotmail.com> on 2012/06/26 17:01:31 UTC

Changing from file-consumer to ftp-consumer

Hello Camel Users,

I have a Camel route consisting of a Polling Consumer and a Custom
Processor. The Polling Consumer is configured by a "file:" URI. The Custom
Processor recieves all polled messages and its logic relies on the
"sendEmptyMessageWhenIdle" parameter configured in the file URI.

Now I want to switch from file: to ftp:. How can I configure the ftp: URI to
still send this EmptyMessage? Or in other words: What is the FTP equivalent
of the "sendEmptyMessageWhenIdle" parameter supported in the file: URI?

Currently I am using Camel version: 2.9.2

Thank you in advance.


--
View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Changing from file-consumer to ftp-consumer

Posted by stefzar <st...@hotmail.com>.
Thank you for your help it works now. If someone is interested in the
solution, here it is:

1) I updated to Camel version 2.10-Snapshot (to use the
consumer.bridgeErrorHandler=true option)
2) implemented my own PollingConsumerPollStrategy which forwards Exceptions
to the Camel route:

public class EmptyMessagePollingStrategy implements
		org.apache.camel.spi.PollingConsumerPollStrategy {
	
	public boolean begin(Consumer arg0, Endpoint arg1) {
		return true;
	}

	public void commit(Consumer arg0, Endpoint arg1, int arg2) {
	}

	/**
	 * If an Exception occurs forward it to the Camel route
	 */
	public boolean rollback(Consumer consumer, Endpoint endpoint, int arg2,
Exception e)
			throws Exception {
		throw e;
	}
}

3) registered the strategy at the registry

SimpleRegistry registry = new SimpleRegistry();
registry.put("myPollStrategy", new EmptyMessagePollingStrategy());
context = new DefaultCamelContext(registry);

4) set the strategy in the route with pollStrategy=#myPollStrategy

5) the route code (EmptyMessageGenerator generates the emptyMessage and the
callbackProcessor relies on the empty message)

onException(org.apache.camel.component.file.GenericFileOperationFailedException.class)
	.process(new EmptyMessageGenerator()).process(callbackProcessor)
	.handled(true);
from(from_uri).routeId(routeId).autoStartup(false).process(callbackProcessor)
	.to(to_uri);



--
View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715224.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Changing from file-consumer to ftp-consumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 27, 2012 at 3:02 PM, stefzar <st...@hotmail.com> wrote:
> The consumer.bridgeErrorHandler option would be great, but I don't exactly
> get how to use it. My route looks like this now and the Exception still is
> not caught by the .onException clause. Should this code work if the folder
> "Notification1" does NOT exist?
>

That option requires Camel 2.10 which has NOT been released yet. But will soon.

For older Camel releases check out that other link I gave you.




> context.addRoutes(new RouteBuilder() {
>        public void configure() {
>
> onException(org.apache.camel.component.file.GenericFileOperationFailedException.class).log("Exception
> caught");
>
>
> from("ftp:stefan@127.0.0.1:21/Notification1/?noop=true&password=password&recursive=true&sendEmptyMessageWhenIdle=true&consumer.bridgeErrorHandler=true")
>                .to("file:storage");
>        }
> });
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715164.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.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Changing from file-consumer to ftp-consumer

Posted by stefzar <st...@hotmail.com>.
The consumer.bridgeErrorHandler option would be great, but I don't exactly
get how to use it. My route looks like this now and the Exception still is
not caught by the .onException clause. Should this code work if the folder
"Notification1" does NOT exist?

context.addRoutes(new RouteBuilder() {
	public void configure() {
	
onException(org.apache.camel.component.file.GenericFileOperationFailedException.class).log("Exception
caught");
				
	
from("ftp:stefan@127.0.0.1:21/Notification1/?noop=true&password=password&recursive=true&sendEmptyMessageWhenIdle=true&consumer.bridgeErrorHandler=true")
		.to("file:storage");
	}
});

--
View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715164.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Changing from file-consumer to ftp-consumer

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

See the pollStrategy option at
http://camel.apache.org/polling-consumer.html

And from Camel 2.10 onwards you can bridge this consumer error with
the Camel error handler in the route using the new
consumer.bridgeErrorHandler option
http://camel.apache.org/file2


On Wed, Jun 27, 2012 at 2:14 PM, stefzar <st...@hotmail.com> wrote:
> I have tried it with exception handling now.
>
> My route looks like this:
>
> context.addRoutes(new RouteBuilder() {
>        public void configure() {
>
> onException(org.apache.camel.component.file.GenericFileOperationFailedException.class).log("Exception
> caught");
>
>
> from("ftp:stefan@127.0.0.1:21/Notification/?noop=true&password=password&recursive=true&sendEmptyMessageWhenIdle=true").to("file:storage");
>        }
> });
>
> The onException-clause works fine if the folder "Notification" does exist
> (meaning the "Exception caught" string will be logged), but if it does not
> then there is also a GenericFileOperationFailedException but it won't be
> catched by the onException-clause.
>
> How can I catch the Exception if the folder does not exist? The difference
> is that in case of the existing folder the consumer sends an empty message
> and the exception occurs at the .to-clause and in case of the non existing
> folder the consumer throws the Exception. I guess the problem is that the
> exception won't pass the default error handler if it's thrown by the
> consumer.
>
> Or in other words: How can I catch Exceptions thrown by a consumer?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715161.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.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Changing from file-consumer to ftp-consumer

Posted by stefzar <st...@hotmail.com>.
I have tried it with exception handling now.

My route looks like this:

context.addRoutes(new RouteBuilder() {
	public void configure() {

onException(org.apache.camel.component.file.GenericFileOperationFailedException.class).log("Exception
caught");
				

from("ftp:stefan@127.0.0.1:21/Notification/?noop=true&password=password&recursive=true&sendEmptyMessageWhenIdle=true").to("file:storage");
	}
});

The onException-clause works fine if the folder "Notification" does exist
(meaning the "Exception caught" string will be logged), but if it does not
then there is also a GenericFileOperationFailedException but it won't be
catched by the onException-clause.

How can I catch the Exception if the folder does not exist? The difference
is that in case of the existing folder the consumer sends an empty message
and the exception occurs at the .to-clause and in case of the non existing
folder the consumer throws the Exception. I guess the problem is that the
exception won't pass the default error handler if it's thrown by the
consumer.

Or in other words: How can I catch Exceptions thrown by a consumer?

--
View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715161.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Changing from file-consumer to ftp-consumer

Posted by Donald Whytock <dw...@gmail.com>.
On Tue, Jun 26, 2012 at 11:34 AM, stefzar <st...@hotmail.com> wrote:
> Thank you for your answer so far but it is a bit more difficult.
>
> In our program it may happen that we are polling on folders which do not
> exist. With the file Component it sends an emptyMessage if the folder should
> not exist, but with the FTP Component we get an Exception instead which
> tells us that the directory was not found:
> org.apache.camel.component.file.GenericFileOperationFailedException: File
> operation failed: 550 CWD failed. "/Notification/IDCard/20120528-00":
> directory not found.
>
> How can I manage to get the same behaviour with the FTP-Component as we have
> with the file-Component, when polling on non existent folders?

Sounds like you'd need to catch the exception and generate an
emptyMessage.  Have a look at Error Handling:

http://camel.apache.org/error-handler.html

Don

Re: Changing from file-consumer to ftp-consumer

Posted by stefzar <st...@hotmail.com>.
Thank you for your answer so far but it is a bit more difficult.

In our program it may happen that we are polling on folders which do not
exist. With the file Component it sends an emptyMessage if the folder should
not exist, but with the FTP Component we get an Exception instead which
tells us that the directory was not found:
org.apache.camel.component.file.GenericFileOperationFailedException: File
operation failed: 550 CWD failed. "/Notification/IDCard/20120528-00":
directory not found.

How can I manage to get the same behaviour with the FTP-Component as we have
with the file-Component, when polling on non existent folders?

--
View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125p5715127.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Changing from file-consumer to ftp-consumer

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Jun 26, 2012 at 5:01 PM, stefzar <st...@hotmail.com> wrote:
> Hello Camel Users,
>
> I have a Camel route consisting of a Polling Consumer and a Custom
> Processor. The Polling Consumer is configured by a "file:" URI. The Custom
> Processor recieves all polled messages and its logic relies on the
> "sendEmptyMessageWhenIdle" parameter configured in the file URI.
>
> Now I want to switch from file: to ftp:. How can I configure the ftp: URI to
> still send this EmptyMessage? Or in other words: What is the FTP equivalent
> of the "sendEmptyMessageWhenIdle" parameter supported in the file: URI?
>
> Currently I am using Camel version: 2.9.2
>
> Thank you in advance.
>

The ftp component inherits 99% of the options from the file component.
So that options should also be avail for the ftp.

>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Changing-from-file-consumer-to-ftp-consumer-tp5715125.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.com
Author of Camel in Action: http://www.manning.com/ibsen