Re: Cannot write content of temp file to remote ftp

2016-04-05 Thread janvandeklok
Thnx Claus for your response.  If nesting of the .from is not allowwed I
would expect an exception to be thrown. Now the route just ends normally,
leaving the programmer is a desperate state :-).

I fixed it now. Not by using the pollEnrich but by setting the temp file in
the exchange body when the fillTempFileWithaLotOfData processor is done
writing the data to the temp file like this :


public void process(Exchange exchange) throws Exception {
try 
{
   .. lots of other code 
   //create a temp file
File myFile = new File(tmpFileUri);
BufferedWriter buffer = new BufferedWriter(new FileWriter(myFile));

// ... write lots of data to buffer 
   
buffer.close();
   * exchange.getIn().setBody(myFile);*
}
finally 
{
}
}

This seems to be working OK.

Thnx again.

Jan van de Klok



--
View this message in context: 
http://camel.465427.n5.nabble.com/Cannot-write-content-of-temp-file-to-remote-ftp-tp5780480p5780485.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Cannot write content of temp file to remote ftp

2016-04-05 Thread Claus Ibsen
You cannot have from in the nested route in the rest-dsl.

If you want to upload a file to a FTP server and write the file using
a temp name, then use the tempFileName or tempPrefix options. The
tempPrefix is the easiest to get started with
http://camel.apache.org/file2

And if you want to trigger the upload using rest GET call then do a

rest GET
 poll enrich file
  to ftp


On Tue, Apr 5, 2016 at 9:11 AM, janvandeklok  wrote:
> Hello, I need to create a file with lots of data  depending on a user request
> and transfer that temp file to a remote ftp.   I have everything running
> without errors and the remote file is created but the content of the created
> remote file is still 0 bytes while the temp file has lots of bytes.
> I don't understand what i'm doing wrong.
>
> Here's the essence of my code:
>
>
>
> public class MYRoute extends AbstractRoute {
>
> public void configure() throws Exception
> {
> super.configure();
>
>
>  File temp = File.createTempFile("mytempfile.json");
>
>  String uriOut = "sftp://"+ System.getenv("my_sftp_host")+
> "/INCOMMING?"
> + "eagerDeleteTargetFile=false&"
> + "exchangePattern=OutOnly&"
> + "allowNullBody=true&"
> + "fileName=my_gen_inf.json&"
> + "password="+ System.getenv("my_sftp_password")+ "&"
> + "username="+ System.getenv("my_sftp_username")+ "&"
> + "timeout=6&"
> + "useList=false";
>
>
> rest("some url")
> .get("/generic").produces(MIME_MEDIA_TYPE_JSON)
> .route()
> .routeId("MY_generic_interface")
> .process(new fillTempFileWithaLotOfData(temp.toURI()))
> .from(temp.toURI().toString())
> .to(uriOut)
> .setBody(constant("{ 'result': 'OK'}"));
>   }
>
>
> Any help is appreciated.
>
> Jan van de Klok
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Cannot-write-content-of-temp-file-to-remote-ftp-tp5780480.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2