You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2013/05/01 07:41:21 UTC

Re: bean, collections in parameters - groovy

Hi

You cannot do this
> .to("bean://myclass?method=myFonction(${mymap})")*

This is just a string.
Also mind that ${ } is also groovy gstrings, so it may conflict and
groovy want to do string interpolation as its a gstring.

If you want to call a method named myFonction, and pass in that mymap
as parameter. Then you need to store the mymap in the Camel registry.
And then refer to it by its id using the ref function from simple
language:
http://camel.apache.org/simple

> .to("bean://myclass?method=myFonction(${ref:idOfTheMap})")*

And read about registry here
http://camel.apache.org/registry.html



On Tue, Apr 30, 2013 at 10:12 AM, Bovas <bo...@gmail.com> wrote:
> Hi
>
> I use the Groovy DSL, Apache Camel 2.11.0.
> I have a problem when I put a Map or a List in parameters in a bean.
>
> I declared à map :
> *def mymap= [:]
> mymap["Mode"]="Zip"
> mymap["test"]="test"*
>
> my route :
> *from("file://path")
> .to("bean://myclass?method=myFonction(${mymap})")*
>
> how looks my fonction in my class /myclass/
> I just display the values of my map :
> *public void myFonction(def mymap){
>                 println mymap
>         }*
>
> When i display my map before the method myFonction, it displays :
> [Mode:Zip, test:test]
>
> but when i displays in the call of my method, it displays :
> [Mode:Zip
>
> I don't understand, maybe the comma makes the error.
>
> I already try differents ways :
> .bean(new Myclass(),"myFonction(${mymap})")
> myFonction("+mymap+")
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778.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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: bean, collections in parameters - groovy

Posted by Bovas <bo...@gmail.com>.
Thanks a lot Claus, it works

I defined my map in my bean and modified it inside.



--
View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778p5731958.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: bean, collections in parameters - groovy

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

Is it the same map instance you want to use? If you register it in the
Camel registry, then Camel will use the same instance, as it just
lookup the instance by the name you assigned to it, when it was added
to the registry.

You can also use the same bean instance and have the bean with a
shared map. After all this is just java/groovy code. So you can do
whatever you can do in regular java/groovy language as well with
Camel.

If you want to use the same bean, then you may want to register it as
well in the registry, and then refer to the bean

.bean("ref:myBeanName?method=method1");




On Thu, May 2, 2013 at 4:36 PM, Bovas <bo...@gmail.com> wrote:
> Thanks Claus for your answer.
>
> I do another way, I create a fonction which return my map (like Christian
> said, thanks to you Christian).
>
> But now I just search how I could use my map in another file.
>
> i.e =>
> 1) from(file1)
> bean(function1) function which returns a map
>
> 2) from(file2)
> bean(function2) which uses the map from 1)
>
> I think I should use Aggregator, unify file 1 and 2, then use my functions?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778p5731919.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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: bean, collections in parameters - groovy

Posted by Bovas <bo...@gmail.com>.
Thanks Claus for your answer.

I do another way, I create a fonction which return my map (like Christian
said, thanks to you Christian).

But now I just search how I could use my map in another file.

i.e =>
1) from(file1)
bean(function1) function which returns a map 

2) from(file2)
bean(function2) which uses the map from 1)

I think I should use Aggregator, unify file 1 and 2, then use my functions? 




--
View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778p5731919.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: bean, collections in parameters - groovy

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

I think ${ } from the simple language syntax in Camel conflicts with
groovy gstrings.

So you can use $simple{ } instead to avoid this clash.
Or redefine the simple language to use other tokens than ${ }

So something like:
.to("bean://verbes?method=myFonction($simple{ref:myMap})")



On Thu, May 2, 2013 at 12:11 PM, Bovas <bo...@gmail.com> wrote:
> Thanks for your anwsers. But I don't success.
>
> I use the default Camel registry (jndiContext)
>
> *def jndiContext = new JndiContext()
> def mymap= [:]
> mymap["Mode"]="Zip"
> mymap["test"]="test"
> jndiContext.bind("myMap",mymap)*
>
>
> from("file://path")
> .to("bean://myclass?method=myFonction(${ref:myMap})")
>
> => console
> Caught: groovy.lang.MissingFieldException: No such field: myMap for class:
> Main.CamelProcess
> groovy.lang.MissingFieldException: No such field: myMap for class:
> Main.CamelProcess
>         at Main.CamelProcess.this$dist$get$3(CamelProcess.groovy)
>         at Main.CamelProcess$1.propertyMissing(CamelProcess.groovy)
>         at Main.CamelProcess$1.getProperty(CamelProcess.groovy)
>         at Main.CamelProcess$_1_configure_closure1.doCall(CamelProcess.groovy:44)
>         at Main.CamelProcess$_1_configure_closure1.doCall(CamelProcess.groovy)
>         at Main.CamelProcess$1.configure(CamelProcess.groovy:44)
>         at
> org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
>         at
> org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)
>         at
> org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)
>         at
> org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:649)
>         at org.apache.camel.CamelContext$addRoutes.call(Unknown Source)
>         at Main.CamelProcess.run(CamelProcess.groovy:39)
>
> other test :
> 1)
> .to("bean://myclass?method=myFonction(${ref:jndiContext})")
>
> => console
> org.apache.camel.util.jndi.JndiContext@55e29b99
>
> i try to display jndiContext.lookup('myMap') but nothing
>
> 2)
> .to("bean://verbes?method=myFonction(${ref:jndiContext.lookup('myMap')})")
>
> => console
> [Mode:Zip
>
>
> I forget something with the *ref function from simple *?
>
> i don't find the solution... so I'm going to do another way
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778p5731904.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: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: bean, collections in parameters - groovy

Posted by Bovas <bo...@gmail.com>.
Thanks for your anwsers. But I don't success.

I use the default Camel registry (jndiContext)

*def jndiContext = new JndiContext()
def mymap= [:]
mymap["Mode"]="Zip"
mymap["test"]="test"
jndiContext.bind("myMap",mymap)*


from("file://path")
.to("bean://myclass?method=myFonction(${ref:myMap})")

=> console
Caught: groovy.lang.MissingFieldException: No such field: myMap for class:
Main.CamelProcess
groovy.lang.MissingFieldException: No such field: myMap for class:
Main.CamelProcess
	at Main.CamelProcess.this$dist$get$3(CamelProcess.groovy)
	at Main.CamelProcess$1.propertyMissing(CamelProcess.groovy)
	at Main.CamelProcess$1.getProperty(CamelProcess.groovy)
	at Main.CamelProcess$_1_configure_closure1.doCall(CamelProcess.groovy:44)
	at Main.CamelProcess$_1_configure_closure1.doCall(CamelProcess.groovy)
	at Main.CamelProcess$1.configure(CamelProcess.groovy:44)
	at
org.apache.camel.builder.RouteBuilder.checkInitialized(RouteBuilder.java:322)
	at
org.apache.camel.builder.RouteBuilder.configureRoutes(RouteBuilder.java:276)
	at
org.apache.camel.builder.RouteBuilder.addRoutesToCamelContext(RouteBuilder.java:262)
	at
org.apache.camel.impl.DefaultCamelContext.addRoutes(DefaultCamelContext.java:649)
	at org.apache.camel.CamelContext$addRoutes.call(Unknown Source)
	at Main.CamelProcess.run(CamelProcess.groovy:39)

other test :
1) 
.to("bean://myclass?method=myFonction(${ref:jndiContext})")

=> console
org.apache.camel.util.jndi.JndiContext@55e29b99

i try to display jndiContext.lookup('myMap') but nothing

2) 
.to("bean://verbes?method=myFonction(${ref:jndiContext.lookup('myMap')})")

=> console 
[Mode:Zip


I forget something with the *ref function from simple *? 

i don't find the solution... so I'm going to do another way



--
View this message in context: http://camel.465427.n5.nabble.com/bean-collections-in-parameters-groovy-tp5731778p5731904.html
Sent from the Camel - Users mailing list archive at Nabble.com.