You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Olivier.Roger" <ol...@bsb.com> on 2010/10/21 10:24:02 UTC

[Camel-exec] dynamic parameters in Spring DSL

Hello,

I am using Camel version 2.4 for the new Camel-exec component.

I would like to ask your opinion on this potential improvement for the usage
of this component with Spring DSL. To use dynamic parameters the
CamelExecCommandArgs header has to be set with a Java List object.

This of course requires Java code to create (simple of course, but still).
Would it not more user friendly if it a String could be given instead/also ?
In that case a separator would be necessary but I guess a blank space could
be the default value.

This way instead of doing 

            <setHeader headerName="execArgs">
                <constant>arg1,arg2,arg3</constant>
            </setHeader>

            <setHeader headerName="CamelExecCommandArgs">
                <method bean="helper" method="parseArgs"/>
            </setHeader>

    <bean id="helper" class="CamelExecHelper">
         <property name="argsHeader" value="execArgs" />
         <property name="argsSeparator" value="," /> <!-- optional -->
    </bean>

This could be writtent 

            <!-- optional -->
            <setHeader headerName="CamelExecCommandArgs">
                <constant>,</constant>
            </setHeader>

            <setHeader headerName="CamelExecCommandArgs">
                <simple>arg1,arg2,arg3</simple> <!-- of course simple offers
many more advance possibilities -->
            </setHeader>

The bean code is very simple indeed but is required 

    public List<String> parseArgs(@Header(field) String argsHeader){
        List<String> args = new ArrayList<String>();
        
        args.addAll(Arrays.asList(argsHeader.split(argsSeparator)));

        return args;        
    }

But maybe I am not seeing an easier way already applicable with the current
version. In that case, please tell me.
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-exec-dynamic-parameters-in-Spring-DSL-tp3230040p3230040.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [Camel-exec] dynamic parameters in Spring DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
Mitko,

Using the args option onj the endpoint would solve the problem for fix
values but in my case the arguments are dynamic.

That's why I need to set the header in the route.


-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-exec-dynamic-parameters-in-Spring-DSL-tp3230040p3230341.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [Camel-exec] dynamic parameters in Spring DSL

Posted by mi...@icw.de.
Hello Oliver,

some functionality that could help you already exist in the Camel exec 
component. 

To use the component conveniently,  you can use the "args" endpoint 
argument with whitespace separator, as described in the documentation  
http://camel.apache.org/exec.html. 

You can not however achieve everything with the current implementation of 
the argument parsing,  for example the parsing has no support for nested " 
symbols. The implementation of the commons-exec library, that is the 
default implementation used by the component,, does not provide a perfect 
argument parsing algorithm that can be reused as well.

I personally prefer and use the list argument, because my code is less 
error-prone when someone else, who has not read the component 
documentation, decides to change and/or add an argument. 


Regards, 
Mitko






From:
"Olivier.Roger" <ol...@bsb.com>
To:
users@camel.apache.org
Date:
21.10.2010 10:24
Subject:
[Camel-exec] dynamic parameters in Spring DSL




Hello,

I am using Camel version 2.4 for the new Camel-exec component.

I would like to ask your opinion on this potential improvement for the 
usage
of this component with Spring DSL. To use dynamic parameters the
CamelExecCommandArgs header has to be set with a Java List object.

This of course requires Java code to create (simple of course, but still).
Would it not more user friendly if it a String could be given instead/also 
?
In that case a separator would be necessary but I guess a blank space 
could
be the default value.

This way instead of doing 

            <setHeader headerName="execArgs">
                <constant>arg1,arg2,arg3</constant>
            </setHeader>

            <setHeader headerName="CamelExecCommandArgs">
                <method bean="helper" method="parseArgs"/>
            </setHeader>

    <bean id="helper" class="CamelExecHelper">
         <property name="argsHeader" value="execArgs" />
         <property name="argsSeparator" value="," /> <!-- optional -->
    </bean>

This could be writtent 

            <!-- optional -->
            <setHeader headerName="CamelExecCommandArgs">
                <constant>,</constant>
            </setHeader>

            <setHeader headerName="CamelExecCommandArgs">
                <simple>arg1,arg2,arg3</simple> <!-- of course simple 
offers
many more advance possibilities -->
            </setHeader>

The bean code is very simple indeed but is required 

    public List<String> parseArgs(@Header(field) String argsHeader){
        List<String> args = new ArrayList<String>();
 
        args.addAll(Arrays.asList(argsHeader.split(argsSeparator)));

        return args; 
    }

But maybe I am not seeing an easier way already applicable with the 
current
version. In that case, please tell me.
-- 
View this message in context: 
http://camel.465427.n5.nabble.com/Camel-exec-dynamic-parameters-in-Spring-DSL-tp3230040p3230040.html

Sent from the Camel - Users mailing list archive at Nabble.com.




�� 
InterComponentWare AG:  
Vorstand: Peter Kirschbauer (Vors.), J�rg Stadler  
Aufsichtsratsvors.: Prof. Dr. Christof Hettich  
Firmensitz: 69190 Walldorf, Altrottstra�e 31  
AG Mannheim HRB 351761 / USt.-IdNr.: DE 198388516  

Re: [Camel-exec] dynamic parameters in Spring DSL

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Thanks Olivier,

I'm gonna work on it as I'm making some change on the camel-exec component.

Regards
JB

On 10/21/2010 10:36 AM, Olivier.Roger wrote:
>
> Sure, I just created  https://issues.apache.org/activemq/browse/CAMEL-3263
> CAMEL-3263

Re: [Camel-exec] dynamic parameters in Spring DSL

Posted by "Olivier.Roger" <ol...@bsb.com>.
Sure, I just created  https://issues.apache.org/activemq/browse/CAMEL-3263
CAMEL-3263 
-- 
View this message in context: http://camel.465427.n5.nabble.com/Camel-exec-dynamic-parameters-in-Spring-DSL-tp3230040p3230061.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [Camel-exec] dynamic parameters in Spring DSL

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
Hi Olivier,

It can be interesting, yes.

Could you raise an improvement Jira ?

Regards
JB

On 10/21/2010 10:24 AM, Olivier.Roger wrote:
>
> Hello,
>
> I am using Camel version 2.4 for the new Camel-exec component.
>
> I would like to ask your opinion on this potential improvement for the usage
> of this component with Spring DSL. To use dynamic parameters the
> CamelExecCommandArgs header has to be set with a Java List object.
>
> This of course requires Java code to create (simple of course, but still).
> Would it not more user friendly if it a String could be given instead/also ?
> In that case a separator would be necessary but I guess a blank space could
> be the default value.
>
> This way instead of doing
>
>              <setHeader headerName="execArgs">
>                  <constant>arg1,arg2,arg3</constant>
>              </setHeader>
>
>              <setHeader headerName="CamelExecCommandArgs">
>                  <method bean="helper" method="parseArgs"/>
>              </setHeader>
>
>      <bean id="helper" class="CamelExecHelper">
>           <property name="argsHeader" value="execArgs" />
>           <property name="argsSeparator" value="," />  <!-- optional -->
>      </bean>
>
> This could be writtent
>
>              <!-- optional -->
>              <setHeader headerName="CamelExecCommandArgs">
>                  <constant>,</constant>
>              </setHeader>
>
>              <setHeader headerName="CamelExecCommandArgs">
>                  <simple>arg1,arg2,arg3</simple>  <!-- of course simple offers
> many more advance possibilities -->
>              </setHeader>
>
> The bean code is very simple indeed but is required
>
>      public List<String>  parseArgs(@Header(field) String argsHeader){
>          List<String>  args = new ArrayList<String>();
>
>          args.addAll(Arrays.asList(argsHeader.split(argsSeparator)));
>
>          return args;
>      }
>
> But maybe I am not seeing an easier way already applicable with the current
> version. In that case, please tell me.