Output File Name After Exec

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Output File Name After Exec

neilac333
I have a Camel route that starts off with an executable for which I use exec and which produces an output file. The name of the file is specified in the outFile parameter to Exec. What I want to do next is to pass that file name--not the contents--in the message body to the next component in the route.

Seems simple enough, but I don't see any clues in the documentation as to how to get that outFile name into a message body. Your insight is appreciated.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Output File Name After Exec

valdar
Can you provide the non working route?


On Tue, Jan 8, 2013 at 9:44 PM, neilac333
<[hidden email]>wrote:

> I have a Camel route that starts off with an executable for which I use
> exec
> and which produces an output file. The name of the file is specified in the
> outFile parameter to Exec. What I want to do next is to pass that file
> /name/--not the contents--in the message body to the next component in the
> route.
>
> Seems simple enough, but I don't see any clues in the documentation as to
> how to get that outFile name into a message body. Your insight is
> appreciated.
>
> Thanks.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Output-File-Name-After-Exec-tp5725152.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
"In a world without walls and fences who needs Windows and Gates?"
Reply | Threaded
Open this post in threaded view
|

Re: Output File Name After Exec

Claus Ibsen-2
In reply to this post by neilac333
On Tue, Jan 8, 2013 at 9:44 PM, neilac333
<[hidden email]> wrote:

> I have a Camel route that starts off with an executable for which I use exec
> and which produces an output file. The name of the file is specified in the
> outFile parameter to Exec. What I want to do next is to pass that file
> /name/--not the contents--in the message body to the next component in the
> route.
>
> Seems simple enough, but I don't see any clues in the documentation as to
> how to get that outFile name into a message body. Your insight is
> appreciated.
>

See this EIP
http://camel.apache.org/message-translator.html

To set the message body with the content of a message header

<transform>
   <header>myHeader</header>
</transform>

Using the header language
http://camel.apache.org/header.html



> Thanks.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Output-File-Name-After-Exec-tp5725152.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: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: Output File Name After Exec

neilac333
Thanks for your responses.

To answer the first question, here is the route I have so far:

from("servlet:///my-endpoint")
            .to("exec:${shellScriptPath}?outFile=${outFilePath}")
            .convertBodyTo(String.class)
            .bean(new DataProvider())
            .marshal(jsonDataFormat)

What I would like to do is replace the convertBodyTo with something that would send ${outFilePath}--the outFile name--as the message body. As it stands now, the outFile contents are the message body.

As for Claus' solution, I am familiar with the transformer EIP, but I am not sure how to apply it. In other words, I am not sure how to transform org.apache.camel.components.exec.ExecResult into a string with the outFile value.

I would appreciate some clarification on what I'm missing.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Output File Name After Exec

valdar
Hi,

outFile is an option that you use to instruct the exec component on which
file is the output of the executed command;
in other words the component first execs the command then grab the outFile
specified and put it in the body;

that said, assuming ${outFilePath} is a property correctly resolved, I
would do something similar to:
from("servlet:///my-endpoint")
            .to("exec:${shellScriptPath}?outFile=${outFilePath}")
            .setBody(${outFilePath})
            .bean(new DataProvider())
            .marshal(jsonDataFormat)

Even if executing a command that produce an output in a file and discarding
that file seems odd to me.

Andrea.




On Thu, Jan 10, 2013 at 5:11 PM, neilac333 <[hidden email]
> wrote:

> Thanks for your responses.
>
> To answer the first question, here is the route I have so far:
>
> from("servlet:///my-endpoint")
>             .to("exec:${shellScriptPath}?outFile=${outFilePath}")
>             .convertBodyTo(String.class)
>             .bean(new DataProvider())
>             .marshal(jsonDataFormat)
>
> What I would like to do is replace the convertBodyTo with something that
> would send ${outFilePath}--the outFile /name/--as the message body. As it
> stands now, the outFile /contents/ are the message body.
>
> As for Claus' solution, I am familiar with the transformer EIP, but I am
> not
> sure how to apply it. In other words, I am not sure how to transform
> /org.apache.camel.components.exec.ExecResult/ into a string with the
> outFile
> value.
>
> I would appreciate some clarification on what I'm missing.
>
> Thanks.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Output-File-Name-After-Exec-tp5725152p5725303.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--
"In a world without walls and fences who needs Windows and Gates?"