You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by eswar <ea...@gmail.com> on 2014/06/25 22:42:49 UTC

convertBody - To SFTP component

hi - 

I have a message with body content with string value of file name and
directory in it. That I need to send to a different server using sftp
component. I am sure we need to convert the message body to a File class to
be able to send it using the sftp, do we need to scan through the file to
convert this or is there an alternative to this ?please suggest.


thanks



--
View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: convertBody - To SFTP component

Posted by eswar <ea...@gmail.com>.
thanks Claus, if I transform using simple predicate the map value gets
converted into String and get sent as File contents, in this case file
content is "C:/Temp/Test.txt". So I had to write a bean to convert this
using FileInputStream and I am able to successfully send over. But this
original file is lost in the subsequent endpoints. for ex.,

<from uri="vm:message">
<bean ref="converttoinputStream"/> /* convert the value in hashmap into File
*/
<to uri="{{sftp:remoteServer}}" /> /* file moves to remote server
successfully */
<bean ref="businessProcess" />
<to uri="C:/Temp/Complete"/> /* This endpoint fails as the
CamelFileNameProduced now refers to the path in the remote server, which
cause this route fail while moving the file to completed dir in local server
*/

do I have to create another bean(after the file is sent over to remote) to
move the files around locally? 




--
View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815p5752998.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: convertBody - To SFTP component

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

Yeah you need to use the message translate eip
http://camel.apache.org/message-translator.html

to covert the hashmap into a format you can send as a file.
If you only need to grab one value from the map, you can just use
simple to lookup the path key from the body

<transform>
   <simple>${body["Path"]}</simple>
</transform>

On Thu, Jun 26, 2014 at 12:50 PM, eswar <ea...@gmail.com> wrote:
> hi Claus - But I do not want to send the message body as is.
>
> For ex., I have a message body of type HashMap as {"Path",
> "C:/Temp/Test.txt"}. Now I need to send the file mentioned in the path using
> the sftp component. So I was thinking this HashMap should be converted into
> File so that sftp component understands to trasnfer Test.txt into remote
> server and not the message itself.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815p5752846.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: convertBody - To SFTP component

Posted by eswar <ea...@gmail.com>.
hi Claus - But I do not want to send the message body as is. 

For ex., I have a message body of type HashMap as {"Path",
"C:/Temp/Test.txt"}. Now I need to send the file mentioned in the path using
the sftp component. So I was thinking this HashMap should be converted into
File so that sftp component understands to trasnfer Test.txt into remote
server and not the message itself.



--
View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815p5752846.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: convertBody - To SFTP component

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

Camel allows to send the message body as-is over FTP (either if its
text based or binary), the latter assum it can be read as input
stream.

Camel uses type converters for this.
http://camel.apache.org/type-converter.html

So if you want Camel to send a file to a ftp server you can just keep
the data as a String, and it will upload the data as text. You can use
the Exchange.FILE_NAME header if you want to give the file a fixed
name.

See more details at
http://camel.apache.org/file2
http://camel.apache.org/ftp2
http://camel.apache.org/ftp-example.html

On Wed, Jun 25, 2014 at 10:42 PM, eswar <ea...@gmail.com> wrote:
> hi -
>
> I have a message with body content with string value of file name and
> directory in it. That I need to send to a different server using sftp
> component. I am sure we need to convert the message body to a File class to
> be able to send it using the sftp, do we need to scan through the file to
> convert this or is there an alternative to this ?please suggest.
>
>
> thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: convertBody - To SFTP component

Posted by eswar <ea...@gmail.com>.
Thanks Rajesh - but as mentioned above I do not want to transfer the message
body but rather need to read  the body and determine the file to be
transfered



--
View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815p5752847.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: convertBody - To SFTP component

Posted by Rajesh <ra...@gmail.com>.
Hi ,

I don't thing you need to convert the string to file inorder  to put it in a remote sever. You just need to set the header for valid file name otherwise camel will create the file with the name as messageid

Sent from my iPhone

> On 26 Jun, 2014, at 4:42 am, eswar <ea...@gmail.com> wrote:
> 
> hi - 
> 
> I have a message with body content with string value of file name and
> directory in it. That I need to send to a different server using sftp
> component. I am sure we need to convert the message body to a File class to
> be able to send it using the sftp, do we need to scan through the file to
> convert this or is there an alternative to this ?please suggest.
> 
> 
> thanks
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/convertBody-To-SFTP-component-tp5752815.html
> Sent from the Camel - Users mailing list archive at Nabble.com.