You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hebert Hu <ho...@zju.edu.cn> on 2009/12/28 09:18:15 UTC

Issue in upload with Camel

Hi, 

I've encountered a strange problem when using Camel Sftp component for
uploading.

Here's my code

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
                from(getFtpUrl()).to("mock:result");
            }
        };
    }

private String getFtpUrl(){
	return
"sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
	}

The problem is: When I start my upload procedure, for the files in the
c:\uploadfiles (multiples files), some of them will create a .camellock file
while others not. As in the remote server, some of the files that have a
.camellock copy will be uploaded while others not. Noted that not all the
files that has .camellock copies will be uploaded. And an exception is
thrown
SEVERE: Cannot retrieve file: ftpload/a.txt
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
retrieve file: ftpload/a.txt
	at
org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
	at
org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
	at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
	at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
	at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
	at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
	at java.lang.Thread.run(Thread.java:799)
When I run the upload procedure again, more .camellock files appeared, more
files been uploaded, and the exception is still thrown.
For example. 10 files in c:\uploadfiles, run the upload for the first time,
5 .camellock appeared, 1 file with .camellock uploaded, and an exception.
Run for the second time, 2 more .camellock appeared, 1 more file uploaded,
and an exception again.

Can any one shed some light on me?
-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26940685.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Issue in upload with Camel

Posted by Willem Jiang <wi...@gmail.com>.
How did you trigger the uploading thread ?
You can let the main thread wait for your uploading thread, if you start 
the uploading thread from the main thread.

Willem


Hebert Hu wrote:
> Thanks for your swift reply. 
> I think I found the problem just due to the uploading and downloading at the
> sametime.
> One more question, it seems that the uploading process is runing on a
> separate thread. Sometimes the main program finishes before the uploading
> thread returns, that stops the uploading. How I can prevent
> such situation?
> 
> Hebert Hu wrote:
>> Hi, 
>>
>> I've encountered a strange problem when using Camel Sftp component for
>> uploading.
>>
>> Here's my code
>>
>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>         return new RouteBuilder() {
>>             public void configure() throws Exception {
>>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>                 from(getFtpUrl()).to("mock:result");
>>             }
>>         };
>>     }
>>
>> private String getFtpUrl(){
>> 	return
>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>> 	}
>>
>> The problem is: When I start my upload procedure, for the files in the
>> c:\uploadfiles (multiples files), some of them will create a .camellock
>> file while others not. As in the remote server, some of the files that
>> have a .camellock copy will be uploaded while others not. Noted that not
>> all the files that has .camellock copies will be uploaded. And an
>> exception is thrown
>> SEVERE: Cannot retrieve file: ftpload/a.txt
>> org.apache.camel.component.file.GenericFileOperationFailedException:
>> Cannot retrieve file: ftpload/a.txt
>> 	at
>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>> 	at
>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>> 	at
>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>> 	at
>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>> 	at
>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>> 	at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>> 	at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>> 	at java.lang.Thread.run(Thread.java:799)
>> When I run the upload procedure again, more .camellock files appeared,
>> more files been uploaded, and the exception is still thrown.
>> For example. 10 files in c:\uploadfiles, run the upload for the first
>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>> file uploaded, and an exception again.
>>
>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>
>> Can any one shed some light on me?
>>
> 


Re: Issue in upload with Camel

Posted by Hebert Hu <ho...@zju.edu.cn>.
Thanks for your swift reply. 
I think I found the problem just due to the uploading and downloading at the
sametime.
One more question, it seems that the uploading process is runing on a
separate thread. Sometimes the main program finishes before the uploading
thread returns, that stops the uploading. How I can prevent
such situation?

Hebert Hu wrote:
> 
> Hi, 
> 
> I've encountered a strange problem when using Camel Sftp component for
> uploading.
> 
> Here's my code
> 
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         return new RouteBuilder() {
>             public void configure() throws Exception {
>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>                 from(getFtpUrl()).to("mock:result");
>             }
>         };
>     }
> 
> private String getFtpUrl(){
> 	return
> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
> 	}
> 
> The problem is: When I start my upload procedure, for the files in the
> c:\uploadfiles (multiples files), some of them will create a .camellock
> file while others not. As in the remote server, some of the files that
> have a .camellock copy will be uploaded while others not. Noted that not
> all the files that has .camellock copies will be uploaded. And an
> exception is thrown
> SEVERE: Cannot retrieve file: ftpload/a.txt
> org.apache.camel.component.file.GenericFileOperationFailedException:
> Cannot retrieve file: ftpload/a.txt
> 	at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
> 	at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
> 	at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
> 	at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
> 	at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
> 	at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
> 	at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
> 	at java.lang.Thread.run(Thread.java:799)
> When I run the upload procedure again, more .camellock files appeared,
> more files been uploaded, and the exception is still thrown.
> For example. 10 files in c:\uploadfiles, run the upload for the first
> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
> exception. Run for the second time, 2 more .camellock appeared, 1 more
> file uploaded, and an exception again.
> 
> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
> 
> Can any one shed some light on me?
> 

-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26950356.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Issue in upload with Camel

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

And uploading and downloading at the *same* time from the same JVM may
not be a good idea. You may start to download files while they are
being uploaded. I wonder if the FTP server supports locking the file
during upload process.

You can use tempPrefix to upload the files with a inprogress filename
and filter that name on the download side so you do not pick up files
being uploaded.

The options from file2 is also avail for the FTP
http://camel.apache.org/file2.html
http://camel.apache.org/ftp2.html


On Mon, Dec 28, 2009 at 9:18 AM, Hebert Hu <ho...@zju.edu.cn> wrote:
>
> Hi,
>
> I've encountered a strange problem when using Camel Sftp component for
> uploading.
>
> Here's my code
>
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        return new RouteBuilder() {
>            public void configure() throws Exception {
>                from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>                from(getFtpUrl()).to("mock:result");
>            }
>        };
>    }
>
> private String getFtpUrl(){
>        return
> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>        }
>
> The problem is: When I start my upload procedure, for the files in the
> c:\uploadfiles (multiples files), some of them will create a .camellock file
> while others not. As in the remote server, some of the files that have a
> .camellock copy will be uploaded while others not. Noted that not all the
> files that has .camellock copies will be uploaded. And an exception is
> thrown
> SEVERE: Cannot retrieve file: ftpload/a.txt
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> retrieve file: ftpload/a.txt
>        at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>        at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>        at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>        at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>        at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>        at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>        at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>        at java.lang.Thread.run(Thread.java:799)
> When I run the upload procedure again, more .camellock files appeared, more
> files been uploaded, and the exception is still thrown.
> For example. 10 files in c:\uploadfiles, run the upload for the first time,
> 5 .camellock appeared, 1 file with .camellock uploaded, and an exception.
> Run for the second time, 2 more .camellock appeared, 1 more file uploaded,
> and an exception again.
>
> Can any one shed some light on me?
> --
> View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26940685.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Issue in upload with Camel

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

What version of Camel are you using?

I can see you are using Windows which have some issues with its file
system locking files.
We have made some recent fixes in the 2.2 trunk code and 2.1 as well.
So try with latest version.



On Mon, Dec 28, 2009 at 9:18 AM, Hebert Hu <ho...@zju.edu.cn> wrote:
>
> Hi,
>
> I've encountered a strange problem when using Camel Sftp component for
> uploading.
>
> Here's my code
>
>    protected RouteBuilder createRouteBuilder() throws Exception {
>        return new RouteBuilder() {
>            public void configure() throws Exception {
>                from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>                from(getFtpUrl()).to("mock:result");
>            }
>        };
>    }
>
> private String getFtpUrl(){
>        return
> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>        }
>
> The problem is: When I start my upload procedure, for the files in the
> c:\uploadfiles (multiples files), some of them will create a .camellock file
> while others not. As in the remote server, some of the files that have a
> .camellock copy will be uploaded while others not. Noted that not all the
> files that has .camellock copies will be uploaded. And an exception is
> thrown
> SEVERE: Cannot retrieve file: ftpload/a.txt
> org.apache.camel.component.file.GenericFileOperationFailedException: Cannot
> retrieve file: ftpload/a.txt
>        at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>        at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>        at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>        at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>        at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>        at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>        at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>        at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>        at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>        at java.lang.Thread.run(Thread.java:799)
> When I run the upload procedure again, more .camellock files appeared, more
> files been uploaded, and the exception is still thrown.
> For example. 10 files in c:\uploadfiles, run the upload for the first time,
> 5 .camellock appeared, 1 file with .camellock uploaded, and an exception.
> Run for the second time, 2 more .camellock appeared, 1 more file uploaded,
> and an exception again.
>
> Can any one shed some light on me?
> --
> View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26940685.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Issue in upload with Camel

Posted by Hebert Hu <ho...@zju.edu.cn>.
Thanks, this worked.
And also I found out another way to implement the ftp uploading function
with camel-ftp

//Do the connection
CamelContext context = new DefaultCamelContext();
ConsumerTemplate consumer = context.createConsumerTemplate();
SftpComponent component = new SftpComponent(context);
SftpConfiguration conf = new SftpConfiguration(getFtpURI());
conf.setKnownHostsFile(knownHostsFile);
conf.setPassword(password);

SftpOperations sftp = new SftpOperations();
sftp.connect(new SftpEndpoint(null, component, conf));

//Do the upload
Exchange exchange = consumer.receive(getFileURI(), 3000);
sftp.storeFile(name, exchange);

For other function, refer to
org.apache.camel.component.file.remote.SftpOperations


willem.jiang wrote:
> 
> The sendTemplate.sendBody() is a sync API and it will return if the ftp 
> uploading processor is finished.
> So your main method could be
>      // create context
>      CamelContext context = new DefaultCamelContext();
>      // create consumer and producer template
>      ConsumerTemplate consumer = context.createConsumerTemplate();
>      ProducerTemplate producer = context.createProducerTemplate();
> 
> 
>      // loop to empty file directory
>          while (true) {
> 
>        // receive the message from the file directory, wait at most 3 sec
>              Exchange exchange = 
> consumer.receive("file:c:\\uploadfiles?noop=true", 3000);
>              if (msg == null) {
>                  // no more messages in queue
>                  break;
>              }
> 
>              // You can do the message transformation here
> 
>              // send it to the ftp endpoint
>              Exchange result = producer.send("FTP URI", exchange);
> 
>              // You may check the result state to see if there is any 
> exception is thrown
>          }
> 
> 
> Willem
> 
> 
> Hebert Hu wrote:
>> I looked into the example and still uncertain about how to check whether
>> the
>> sendTemplate is returned. Would you please show me a code snippet?
>> 
>> willem.jiang wrote:
>>> If you are using file endpoint to pull the directory, it is hard to tell 
>>> if the uploading processor is over,
>>> Can you take look at the camel polling consumer API[1] (Timer based 
>>> polling consumer example), in this way you can add you logic to check if 
>>> the file pulling is finished, and the sendTemplate will return when the 
>>>   uploading work is over.
>>>
>>> [1]http://camel.apache.org/polling-consumer.html
>>>
>>> Willem
>>>
>>> Hebert Hu wrote:
>>>> I started the upload like this
>>>>
>>>> CamelContext context = new DefaultCamelContext();
>>>> RouteBuilder route = createRouteBuilder();
>>>> context.addRoutes(route);
>>>> context.start();
>>>>
>>>> I'm able to get the route service status by 
>>>> RouteDefinition definition = context.getRouteDefinitions().get(0);
>>>> context.getRouteStatus(definition)
>>>>
>>>> But how can I tell whther the upload is finished?
>>>> As I always get "Started" even the upload is finished.
>>>>
>>>>
>>>> Hebert Hu wrote:
>>>>> Hi, 
>>>>>
>>>>> I've encountered a strange problem when using Camel Sftp component for
>>>>> uploading.
>>>>>
>>>>> Here's my code
>>>>>
>>>>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>>>>         return new RouteBuilder() {
>>>>>             public void configure() throws Exception {
>>>>>                
>>>>> from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>>>>                 from(getFtpUrl()).to("mock:result");
>>>>>             }
>>>>>         };
>>>>>     }
>>>>>
>>>>> private String getFtpUrl(){
>>>>> 	return
>>>>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>>>>> 	}
>>>>>
>>>>> The problem is: When I start my upload procedure, for the files in the
>>>>> c:\uploadfiles (multiples files), some of them will create a
>>>>> .camellock
>>>>> file while others not. As in the remote server, some of the files that
>>>>> have a .camellock copy will be uploaded while others not. Noted that
>>>>> not
>>>>> all the files that has .camellock copies will be uploaded. And an
>>>>> exception is thrown
>>>>> SEVERE: Cannot retrieve file: ftpload/a.txt
>>>>> org.apache.camel.component.file.GenericFileOperationFailedException:
>>>>> Cannot retrieve file: ftpload/a.txt
>>>>> 	at
>>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>>>>> 	at
>>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>>>>> 	at
>>>>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>>>>> 	at
>>>>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>>>>> 	at
>>>>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>>>>> 	at
>>>>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>>>>> 	at
>>>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>>>>> 	at
>>>>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>>>>> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>>>>> 	at
>>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>>>>> 	at
>>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>>>>> 	at
>>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>>>>> 	at
>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>>>>> 	at
>>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>>>>> 	at java.lang.Thread.run(Thread.java:799)
>>>>> When I run the upload procedure again, more .camellock files appeared,
>>>>> more files been uploaded, and the exception is still thrown.
>>>>> For example. 10 files in c:\uploadfiles, run the upload for the first
>>>>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>>>>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>>>>> file uploaded, and an exception again.
>>>>>
>>>>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>>>>
>>>>> Can any one shed some light on me?
>>>>>
>>>
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26976537.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Issue in upload with Camel

Posted by Willem Jiang <wi...@gmail.com>.
The sendTemplate.sendBody() is a sync API and it will return if the ftp 
uploading processor is finished.
So your main method could be
     // create context
     CamelContext context = new DefaultCamelContext();
     // create consumer and producer template
     ConsumerTemplate consumer = context.createConsumerTemplate();
     ProducerTemplate producer = context.createProducerTemplate();


     // loop to empty file directory
         while (true) {

       // receive the message from the file directory, wait at most 3 sec
             Exchange exchange = 
consumer.receive("file:c:\\uploadfiles?noop=true", 3000);
             if (msg == null) {
                 // no more messages in queue
                 break;
             }

             // You can do the message transformation here

             // send it to the ftp endpoint
             Exchange result = producer.send("FTP URI", exchange);

             // You may check the result state to see if there is any 
exception is thrown
         }


Willem


Hebert Hu wrote:
> I looked into the example and still uncertain about how to check whether the
> sendTemplate is returned. Would you please show me a code snippet?
> 
> willem.jiang wrote:
>> If you are using file endpoint to pull the directory, it is hard to tell 
>> if the uploading processor is over,
>> Can you take look at the camel polling consumer API[1] (Timer based 
>> polling consumer example), in this way you can add you logic to check if 
>> the file pulling is finished, and the sendTemplate will return when the 
>>   uploading work is over.
>>
>> [1]http://camel.apache.org/polling-consumer.html
>>
>> Willem
>>
>> Hebert Hu wrote:
>>> I started the upload like this
>>>
>>> CamelContext context = new DefaultCamelContext();
>>> RouteBuilder route = createRouteBuilder();
>>> context.addRoutes(route);
>>> context.start();
>>>
>>> I'm able to get the route service status by 
>>> RouteDefinition definition = context.getRouteDefinitions().get(0);
>>> context.getRouteStatus(definition)
>>>
>>> But how can I tell whther the upload is finished?
>>> As I always get "Started" even the upload is finished.
>>>
>>>
>>> Hebert Hu wrote:
>>>> Hi, 
>>>>
>>>> I've encountered a strange problem when using Camel Sftp component for
>>>> uploading.
>>>>
>>>> Here's my code
>>>>
>>>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>>>         return new RouteBuilder() {
>>>>             public void configure() throws Exception {
>>>>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>>>                 from(getFtpUrl()).to("mock:result");
>>>>             }
>>>>         };
>>>>     }
>>>>
>>>> private String getFtpUrl(){
>>>> 	return
>>>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>>>> 	}
>>>>
>>>> The problem is: When I start my upload procedure, for the files in the
>>>> c:\uploadfiles (multiples files), some of them will create a .camellock
>>>> file while others not. As in the remote server, some of the files that
>>>> have a .camellock copy will be uploaded while others not. Noted that not
>>>> all the files that has .camellock copies will be uploaded. And an
>>>> exception is thrown
>>>> SEVERE: Cannot retrieve file: ftpload/a.txt
>>>> org.apache.camel.component.file.GenericFileOperationFailedException:
>>>> Cannot retrieve file: ftpload/a.txt
>>>> 	at
>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>>>> 	at
>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>>>> 	at
>>>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>>>> 	at
>>>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>>>> 	at
>>>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>>>> 	at
>>>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>>>> 	at
>>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>>>> 	at
>>>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>>>> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>>>> 	at
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>>>> 	at
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>>>> 	at
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>>>> 	at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>>>> 	at
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>>>> 	at java.lang.Thread.run(Thread.java:799)
>>>> When I run the upload procedure again, more .camellock files appeared,
>>>> more files been uploaded, and the exception is still thrown.
>>>> For example. 10 files in c:\uploadfiles, run the upload for the first
>>>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>>>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>>>> file uploaded, and an exception again.
>>>>
>>>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>>>
>>>> Can any one shed some light on me?
>>>>
>>
>>
> 


Re: Issue in upload with Camel

Posted by Hebert Hu <ho...@zju.edu.cn>.
I looked into the example and still uncertain about how to check whether the
sendTemplate is returned. Would you please show me a code snippet?

willem.jiang wrote:
> 
> If you are using file endpoint to pull the directory, it is hard to tell 
> if the uploading processor is over,
> Can you take look at the camel polling consumer API[1] (Timer based 
> polling consumer example), in this way you can add you logic to check if 
> the file pulling is finished, and the sendTemplate will return when the 
>   uploading work is over.
> 
> [1]http://camel.apache.org/polling-consumer.html
> 
> Willem
> 
> Hebert Hu wrote:
>> I started the upload like this
>> 
>> CamelContext context = new DefaultCamelContext();
>> RouteBuilder route = createRouteBuilder();
>> context.addRoutes(route);
>> context.start();
>> 
>> I'm able to get the route service status by 
>> RouteDefinition definition = context.getRouteDefinitions().get(0);
>> context.getRouteStatus(definition)
>> 
>> But how can I tell whther the upload is finished?
>> As I always get "Started" even the upload is finished.
>> 
>> 
>> Hebert Hu wrote:
>>> Hi, 
>>>
>>> I've encountered a strange problem when using Camel Sftp component for
>>> uploading.
>>>
>>> Here's my code
>>>
>>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>>         return new RouteBuilder() {
>>>             public void configure() throws Exception {
>>>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>>                 from(getFtpUrl()).to("mock:result");
>>>             }
>>>         };
>>>     }
>>>
>>> private String getFtpUrl(){
>>> 	return
>>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>>> 	}
>>>
>>> The problem is: When I start my upload procedure, for the files in the
>>> c:\uploadfiles (multiples files), some of them will create a .camellock
>>> file while others not. As in the remote server, some of the files that
>>> have a .camellock copy will be uploaded while others not. Noted that not
>>> all the files that has .camellock copies will be uploaded. And an
>>> exception is thrown
>>> SEVERE: Cannot retrieve file: ftpload/a.txt
>>> org.apache.camel.component.file.GenericFileOperationFailedException:
>>> Cannot retrieve file: ftpload/a.txt
>>> 	at
>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>>> 	at
>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>>> 	at
>>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>>> 	at
>>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>>> 	at
>>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>>> 	at
>>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>>> 	at
>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>>> 	at
>>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>>> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>>> 	at
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>>> 	at
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>>> 	at
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>>> 	at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>>> 	at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>>> 	at java.lang.Thread.run(Thread.java:799)
>>> When I run the upload procedure again, more .camellock files appeared,
>>> more files been uploaded, and the exception is still thrown.
>>> For example. 10 files in c:\uploadfiles, run the upload for the first
>>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>>> file uploaded, and an exception again.
>>>
>>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>>
>>> Can any one shed some light on me?
>>>
>> 
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26964265.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Issue in upload with Camel

Posted by Hebert Hu <ho...@zju.edu.cn>.
Since I only need to check whether the upload is finished, I wrote
                from(fileUrl).onCompletion().to(ftpUrl).end()
am I writing the right syntax? Since it didn't work well
It seems that the in flight count way is more convenient, but I can't find
the function available neither in 2.0 or 2.1.Is it a new feature in 2.2?
BTW, the download link for 2.2 is not valid currently

Claus Ibsen-2 wrote:
> 
> On Tue, Dec 29, 2009 at 8:59 AM, Willem Jiang <wi...@gmail.com>
> wrote:
>> If you are using file endpoint to pull the directory, it is hard to tell
>> if
>> the uploading processor is over,
>> Can you take look at the camel polling consumer API[1] (Timer based
>> polling
>> consumer example), in this way you can add you logic to check if the file
>> pulling is finished, and the sendTemplate will return when the  uploading
>> work is over.
>>
>> [1]http://camel.apache.org/polling-consumer.html
>>
> 
> 
> You can also use onCompletion or check the inflight registry if there
> are any current exchanges.
> http://camel.apache.org/oncompletion.html
> 
> CamelContext.getInflightRegistry()
> 
> Which has a counter for the number of exchanges in flight. When it
> reaches 0 the file should have been transferred.
> 
> 
> 
>> Willem
>>
>> Hebert Hu wrote:
>>>
>>> I started the upload like this
>>>
>>> CamelContext context = new DefaultCamelContext();
>>> RouteBuilder route = createRouteBuilder();
>>> context.addRoutes(route);
>>> context.start();
>>>
>>> I'm able to get the route service status by RouteDefinition definition =
>>> context.getRouteDefinitions().get(0);
>>> context.getRouteStatus(definition)
>>>
>>> But how can I tell whther the upload is finished?
>>> As I always get "Started" even the upload is finished.
>>>
>>>
>>> Hebert Hu wrote:
>>>>
>>>> Hi,
>>>> I've encountered a strange problem when using Camel Sftp component for
>>>> uploading.
>>>>
>>>> Here's my code
>>>>
>>>>    protected RouteBuilder createRouteBuilder() throws Exception {
>>>>        return new RouteBuilder() {
>>>>            public void configure() throws Exception {
>>>>                from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>>>                from(getFtpUrl()).to("mock:result");
>>>>            }
>>>>        };
>>>>    }
>>>>
>>>> private String getFtpUrl(){
>>>>        return
>>>>
>>>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>>>>        }
>>>>
>>>> The problem is: When I start my upload procedure, for the files in the
>>>> c:\uploadfiles (multiples files), some of them will create a .camellock
>>>> file while others not. As in the remote server, some of the files that
>>>> have a .camellock copy will be uploaded while others not. Noted that
>>>> not
>>>> all the files that has .camellock copies will be uploaded. And an
>>>> exception is thrown
>>>> SEVERE: Cannot retrieve file: ftpload/a.txt
>>>> org.apache.camel.component.file.GenericFileOperationFailedException:
>>>> Cannot retrieve file: ftpload/a.txt
>>>>        at
>>>>
>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>>>>        at
>>>>
>>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>>>>        at
>>>>
>>>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>>>>        at
>>>>
>>>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>>>>        at
>>>>
>>>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>>>>        at
>>>>
>>>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>>>>        at
>>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>>>>        at
>>>>
>>>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>>>>        at
>>>> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>>>>        at
>>>>
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>>>>        at
>>>>
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>>>>        at
>>>>
>>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>>>>        at
>>>>
>>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>>>>        at java.lang.Thread.run(Thread.java:799)
>>>> When I run the upload procedure again, more .camellock files appeared,
>>>> more files been uploaded, and the exception is still thrown.
>>>> For example. 10 files in c:\uploadfiles, run the upload for the first
>>>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>>>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>>>> file uploaded, and an exception again.
>>>>
>>>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>>>
>>>> Can any one shed some light on me?
>>>>
>>>
>>
>>
> 
> 
> 
> -- 
> Claus Ibsen
> Apache Camel Committer
> 
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
> 
> 

-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26964320.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Issue in upload with Camel

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Dec 29, 2009 at 8:59 AM, Willem Jiang <wi...@gmail.com> wrote:
> If you are using file endpoint to pull the directory, it is hard to tell if
> the uploading processor is over,
> Can you take look at the camel polling consumer API[1] (Timer based polling
> consumer example), in this way you can add you logic to check if the file
> pulling is finished, and the sendTemplate will return when the  uploading
> work is over.
>
> [1]http://camel.apache.org/polling-consumer.html
>


You can also use onCompletion or check the inflight registry if there
are any current exchanges.
http://camel.apache.org/oncompletion.html

CamelContext.getInflightRegistry()

Which has a counter for the number of exchanges in flight. When it
reaches 0 the file should have been transferred.



> Willem
>
> Hebert Hu wrote:
>>
>> I started the upload like this
>>
>> CamelContext context = new DefaultCamelContext();
>> RouteBuilder route = createRouteBuilder();
>> context.addRoutes(route);
>> context.start();
>>
>> I'm able to get the route service status by RouteDefinition definition =
>> context.getRouteDefinitions().get(0);
>> context.getRouteStatus(definition)
>>
>> But how can I tell whther the upload is finished?
>> As I always get "Started" even the upload is finished.
>>
>>
>> Hebert Hu wrote:
>>>
>>> Hi,
>>> I've encountered a strange problem when using Camel Sftp component for
>>> uploading.
>>>
>>> Here's my code
>>>
>>>    protected RouteBuilder createRouteBuilder() throws Exception {
>>>        return new RouteBuilder() {
>>>            public void configure() throws Exception {
>>>                from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>>                from(getFtpUrl()).to("mock:result");
>>>            }
>>>        };
>>>    }
>>>
>>> private String getFtpUrl(){
>>>        return
>>>
>>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>>>        }
>>>
>>> The problem is: When I start my upload procedure, for the files in the
>>> c:\uploadfiles (multiples files), some of them will create a .camellock
>>> file while others not. As in the remote server, some of the files that
>>> have a .camellock copy will be uploaded while others not. Noted that not
>>> all the files that has .camellock copies will be uploaded. And an
>>> exception is thrown
>>> SEVERE: Cannot retrieve file: ftpload/a.txt
>>> org.apache.camel.component.file.GenericFileOperationFailedException:
>>> Cannot retrieve file: ftpload/a.txt
>>>        at
>>>
>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>>>        at
>>>
>>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>>>        at
>>>
>>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>>>        at
>>>
>>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>>>        at
>>>
>>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>>>        at
>>>
>>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>>>        at
>>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>>>        at
>>>
>>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>>>        at
>>> java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>>>        at
>>>
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>>>        at
>>>
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>>>        at
>>>
>>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>>>        at
>>>
>>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>>>        at
>>>
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>>>        at java.lang.Thread.run(Thread.java:799)
>>> When I run the upload procedure again, more .camellock files appeared,
>>> more files been uploaded, and the exception is still thrown.
>>> For example. 10 files in c:\uploadfiles, run the upload for the first
>>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>>> file uploaded, and an exception again.
>>>
>>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>>
>>> Can any one shed some light on me?
>>>
>>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Issue in upload with Camel

Posted by Willem Jiang <wi...@gmail.com>.
If you are using file endpoint to pull the directory, it is hard to tell 
if the uploading processor is over,
Can you take look at the camel polling consumer API[1] (Timer based 
polling consumer example), in this way you can add you logic to check if 
the file pulling is finished, and the sendTemplate will return when the 
  uploading work is over.

[1]http://camel.apache.org/polling-consumer.html

Willem

Hebert Hu wrote:
> I started the upload like this
> 
> CamelContext context = new DefaultCamelContext();
> RouteBuilder route = createRouteBuilder();
> context.addRoutes(route);
> context.start();
> 
> I'm able to get the route service status by 
> RouteDefinition definition = context.getRouteDefinitions().get(0);
> context.getRouteStatus(definition)
> 
> But how can I tell whther the upload is finished?
> As I always get "Started" even the upload is finished.
> 
> 
> Hebert Hu wrote:
>> Hi, 
>>
>> I've encountered a strange problem when using Camel Sftp component for
>> uploading.
>>
>> Here's my code
>>
>>     protected RouteBuilder createRouteBuilder() throws Exception {
>>         return new RouteBuilder() {
>>             public void configure() throws Exception {
>>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>>                 from(getFtpUrl()).to("mock:result");
>>             }
>>         };
>>     }
>>
>> private String getFtpUrl(){
>> 	return
>> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
>> 	}
>>
>> The problem is: When I start my upload procedure, for the files in the
>> c:\uploadfiles (multiples files), some of them will create a .camellock
>> file while others not. As in the remote server, some of the files that
>> have a .camellock copy will be uploaded while others not. Noted that not
>> all the files that has .camellock copies will be uploaded. And an
>> exception is thrown
>> SEVERE: Cannot retrieve file: ftpload/a.txt
>> org.apache.camel.component.file.GenericFileOperationFailedException:
>> Cannot retrieve file: ftpload/a.txt
>> 	at
>> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
>> 	at
>> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
>> 	at
>> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
>> 	at
>> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
>> 	at
>> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
>> 	at
>> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
>> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
>> 	at
>> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
>> 	at
>> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
>> 	at
>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
>> 	at java.lang.Thread.run(Thread.java:799)
>> When I run the upload procedure again, more .camellock files appeared,
>> more files been uploaded, and the exception is still thrown.
>> For example. 10 files in c:\uploadfiles, run the upload for the first
>> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
>> exception. Run for the second time, 2 more .camellock appeared, 1 more
>> file uploaded, and an exception again.
>>
>> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
>>
>> Can any one shed some light on me?
>>
> 


Re: Issue in upload with Camel

Posted by Hebert Hu <ho...@zju.edu.cn>.
I started the upload like this

CamelContext context = new DefaultCamelContext();
RouteBuilder route = createRouteBuilder();
context.addRoutes(route);
context.start();

I'm able to get the route service status by 
RouteDefinition definition = context.getRouteDefinitions().get(0);
context.getRouteStatus(definition)

But how can I tell whther the upload is finished?
As I always get "Started" even the upload is finished.


Hebert Hu wrote:
> 
> Hi, 
> 
> I've encountered a strange problem when using Camel Sftp component for
> uploading.
> 
> Here's my code
> 
>     protected RouteBuilder createRouteBuilder() throws Exception {
>         return new RouteBuilder() {
>             public void configure() throws Exception {
>                 from("file:c:\\uploadfiles?noop=true").to(getFtpUrl());
>                 from(getFtpUrl()).to("mock:result");
>             }
>         };
>     }
> 
> private String getFtpUrl(){
> 	return
> "sftp://username@sftpserver/ftpload?password=password&binary=true&knownHostsFile=c://.ssh//known_hosts";
> 	}
> 
> The problem is: When I start my upload procedure, for the files in the
> c:\uploadfiles (multiples files), some of them will create a .camellock
> file while others not. As in the remote server, some of the files that
> have a .camellock copy will be uploaded while others not. Noted that not
> all the files that has .camellock copies will be uploaded. And an
> exception is thrown
> SEVERE: Cannot retrieve file: ftpload/a.txt
> org.apache.camel.component.file.GenericFileOperationFailedException:
> Cannot retrieve file: ftpload/a.txt
> 	at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFileToStreamInBody(SftpOperations.java:326)
> 	at
> org.apache.camel.component.file.remote.SftpOperations.retrieveFile(SftpOperations.java:312)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:183)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:120)
> 	at
> org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:93)
> 	at
> org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:99)
> 	at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:432)
> 	at
> java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:295)
> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:80)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:157)
> 	at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:181)
> 	at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:665)
> 	at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:690)
> 	at java.lang.Thread.run(Thread.java:799)
> When I run the upload procedure again, more .camellock files appeared,
> more files been uploaded, and the exception is still thrown.
> For example. 10 files in c:\uploadfiles, run the upload for the first
> time, 5 .camellock appeared, 1 file with .camellock uploaded, and an
> exception. Run for the second time, 2 more .camellock appeared, 1 more
> file uploaded, and an exception again.
> 
> I'm using Camel-core 2.0.0, camel-ftp 2.0.0
> 
> Can any one shed some light on me?
> 

-- 
View this message in context: http://old.nabble.com/Issue-in-upload-with-Camel-tp26940685p26951787.html
Sent from the Camel - Users mailing list archive at Nabble.com.