You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by imranrazakhan <im...@gmail.com> on 2016/11/08 20:07:13 UTC

How to convert property value to array

HI,

I want to convert value to array but couldn't get any idea from docs

// properties
cool.foo=a,b,c

 
// route
from("direct:start")
  .setHeader("myList",  simple(" ${properties:cool.foo} ") })
  .to("direct:end"}");

Currently myList valuse is string like a,b,c

How i can treat myList as array?




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to convert property value to array

Posted by Claus Ibsen <cl...@gmail.com>.
You need to put the groovy script as a String value. Its not compiled
together with the java code.

You can try with the simple language to use the split method on a string eg

.simple("${properties:cool.foo.split(',')}")

As java.lang.String has the split method out of the box, that Camel
simple language can invoke with the properties value.




On Wed, Nov 9, 2016 at 9:40 PM, imranrazakhan <im...@gmail.com> wrote:
> i tried but below is not working
>
>
> // route
>  from("direct:start")
>    .setHeader("myList").groovy(  simple(" ${properties:cool.foo} ")
> ).toString().split(",") )
>    .log("cid ==== "+simple("${header.myList.size}"))
>    .to("direct:end"}");
>
> i even tried below but groovy complain that
>
>  .setHeader("cid" ).groovy( new String("a,b,c").split(",") )
>
> Exception in thread "main" java.lang.Error: Unresolved compilation problem:
>         The method groovy(String) in the type
> ExpressionClause<ProcessorDefinition&lt;ExpressionNode>> is not applicable
> for the arguments (String[])
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924p5789965.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

Re: How to convert property value to array

Posted by imranrazakhan <im...@gmail.com>.
i tried but below is not working


// route
 from("direct:start")
   .setHeader("myList").groovy(  simple(" ${properties:cool.foo} ") 
).toString().split(",") )
   .log("cid ==== "+simple("${header.myList.size}"))
   .to("direct:end"}"); 

i even tried below but groovy complain that

 .setHeader("cid" ).groovy( new String("a,b,c").split(",") )

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The method groovy(String) in the type
ExpressionClause<ProcessorDefinition&lt;ExpressionNode>> is not applicable
for the arguments (String[])




--
View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924p5789965.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to convert property value to array

Posted by Claus Ibsen <cl...@gmail.com>.
Make a method call where you create that array or use dynamic
languages like groovy with some inlined script.



On Wed, Nov 9, 2016 at 5:42 AM, imranrazakhan <im...@gmail.com> wrote:
> I tried following but it is not working as u expected
>
> // route
> from("direct:start")
>   .setHeader("myList",  simple(" ${properties:cool.foo} ") })
>   .log("cid ==== "+simple("${header.myList.size}"))
>   .to("direct:end"}");
>
> Failed to invoke method: size on null due to:
> org.apache.camel.component.bean.MethodNotFoundException: Method with name:
> size not found on bean: a,b,c of type: java.lang.String. Exchange[]
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924p5789930.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

Re: How to convert property value to array

Posted by imranrazakhan <im...@gmail.com>.
I tried following but it is not working as u expected

// route
from("direct:start")
  .setHeader("myList",  simple(" ${properties:cool.foo} ") })
  .log("cid ==== "+simple("${header.myList.size}"))
  .to("direct:end"}"); 

Failed to invoke method: size on null due to:
org.apache.camel.component.bean.MethodNotFoundException: Method with name:
size not found on bean: a,b,c of type: java.lang.String. Exchange[]



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924p5789930.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to convert property value to array

Posted by Mark Nuttall <mk...@gmail.com>.
I did some googling and i cannot find an exact example. But based on what i
see in the Simple and Properties pages, i am guessing that it might work
like Spring.  So in your properties file try this:

cool.foos[0]=a
cool.foos[0]=b
cool.foos[0]=c

and in your DSL use:

 " ${properties:cool.foos} "


On Tue, Nov 8, 2016 at 3:40 PM, imranrazakhan <im...@gmail.com>
wrote:

> I am using Java DSL.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/How-to-convert-property-value-to-array-tp5789924p5789926.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: How to convert property value to array

Posted by imranrazakhan <im...@gmail.com>.
I am using Java DSL.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-convert-property-value-to-array-tp5789924p5789926.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to convert property value to array

Posted by Mark Nuttall <mk...@gmail.com>.
Are you using spring?  Creating arrays from properties is built in.

On Nov 8, 2016 3:07 PM, "imranrazakhan" <im...@gmail.com> wrote:

> HI,
>
> I want to convert value to array but couldn't get any idea from docs
>
> // properties
> cool.foo=a,b,c
>
>
> // route
> from("direct:start")
>   .setHeader("myList",  simple(" ${properties:cool.foo} ") })
>   .to("direct:end"}");
>
> Currently myList valuse is string like a,b,c
>
> How i can treat myList as array?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/How-to-convert-property-value-to-array-tp5789924.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>