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/06/01 08:08:41 UTC

Re: bean with method parameters in camel

You cannot do this.

On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar <ag...@gmail.com> wrote:
> If i try .bean(className, methodName('a', 'b')) : it calls method
> methodName of class className with method parameters 'a' and 'b'. However,
> if i want value of method variables to come from class variables, how can i
> do that?
>
> what i mean is :
> class abc extends RouteBuilder {
>   private string str1 = 'a';
>   private string str2 = 'b';
> .....
> .....
> to().bean(className, methodName(str1, str2)).end();
>
> i get str1 and str2 classes not found exception. How can i pass str1 and
> str2 values as method parameters without actually hardcoding them?



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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 with method parameters in camel

Posted by Diether <di...@optis.be>.
Put short: you can pass method parameters if they are part of the Exchange (either body or as headers).

But it's still unclear for me where these params should come from, or what you are trying to do.
You say "user input", but user input should be done before sending the Exchange and entering the Camel route.
So then they are part of the Exchange and you can use the methods mentioned previously.





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

Re: bean with method parameters in camel

Posted by Tarun Kumar <ag...@gmail.com>.
Hi Claus,

I have gone through all these links. Is there anything specific i am
missing here?


On Mon, Jun 3, 2013 at 2:02 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> Yeah read the docs
> http://camel.apache.org/bean-integration.html
> http://camel.apache.org/bean-binding.html
> http://camel.apache.org/parameter-binding-annotations.html
>
> On Mon, Jun 3, 2013 at 10:14 AM, Tarun Kumar <ag...@gmail.com>
> wrote:
> > my use case is:
> >
> > from().bean().end()
> >
> > Based on user input, i want to make bean call. So, basically method
> > parameters for bean call will come from exchange as well as user input. I
> > was wondering if there is any way to make bean call with method
> parameters
> > as exchange as well some user input parameters.
> >
> >
> > On Sun, Jun 2, 2013 at 1:46 PM, Claus Ibsen <cl...@gmail.com>
> wrote:
> >
> >> Hi
> >>
> >> You can call a method without parameters that call the method you want
> >> (as its just java code and you can call it yourself), or use a inlined
> >> Camel processor to call the method from java code etc.
> >>
> >> The bean component is intended for calling methods with parameter
> >> values with data from the Camel Exchange / Message - and not hardcoded
> >> values.
> >>
> >> So what is your use case for calling this method with hard-coded values
> ?
> >>
> >>
> >> On Sat, Jun 1, 2013 at 9:31 AM, Jan Matèrne (jhm) <ap...@materne.de>
> >> wrote:
> >> > The exchange could be passed to the bean method, therefore you could
> >> store
> >> > these values in the header or as exchange-properties.
> >> >
> >> > Something like
> >> > class abc extends RouteBuilder {
> >> >     private string str1 = 'a';
> >> >     private string str2 = 'b';
> >> >     .....
> >> >     .....
> >> >     .setHeader("str1", str1)
> >> >     .setHeader("str2", str2)
> >> >     .to().bean(myBean, methodName).end();
> >> > }
> >> >
> >> > // @see http://camel.apache.org/bean.html
> >> > // @see http://camel.apache.org/bean-binding.html
> >> > class MyBean {
> >> >     public String method(@Header("str1") str1, @Header("str2) str2) {
> >> >         ....
> >> >     }
> >> > }
> >> >
> >> >
> >> > Jan
> >> >
> >> >> -----Ursprüngliche Nachricht-----
> >> >> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> >> >> Gesendet: Samstag, 1. Juni 2013 08:09
> >> >> An: users@camel.apache.org
> >> >> Betreff: Re: bean with method parameters in camel
> >> >>
> >> >> You cannot do this.
> >> >>
> >> >> On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar
> >> >> <ag...@gmail.com> wrote:
> >> >> > If i try .bean(className, methodName('a', 'b')) : it calls method
> >> >> > methodName of class className with method parameters 'a' and 'b'.
> >> >> > However, if i want value of method variables to come from class
> >> >> > variables, how can i do that?
> >> >> >
> >> >> > what i mean is :
> >> >> > class abc extends RouteBuilder {
> >> >> >   private string str1 = 'a';
> >> >> >   private string str2 = 'b';
> >> >> > .....
> >> >> > .....
> >> >> > to().bean(className, methodName(str1, str2)).end();
> >> >> >
> >> >> > i get str1 and str2 classes not found exception. How can i pass
> str1
> >> >> > and
> >> >> > str2 values as method parameters without actually hardcoding them?
> >> >>
> >> >>
> >> >>
> >> >> --
> >> >> Claus Ibsen
> >> >> -----------------
> >> >> www.camelone.org: The open source integration conference.
> >> >>
> >> >> 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
> >> >
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> www.camelone.org: The open source integration conference.
> >>
> >> 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
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> 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 with method parameters in camel

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

Yeah read the docs
http://camel.apache.org/bean-integration.html
http://camel.apache.org/bean-binding.html
http://camel.apache.org/parameter-binding-annotations.html

On Mon, Jun 3, 2013 at 10:14 AM, Tarun Kumar <ag...@gmail.com> wrote:
> my use case is:
>
> from().bean().end()
>
> Based on user input, i want to make bean call. So, basically method
> parameters for bean call will come from exchange as well as user input. I
> was wondering if there is any way to make bean call with method parameters
> as exchange as well some user input parameters.
>
>
> On Sun, Jun 2, 2013 at 1:46 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> Hi
>>
>> You can call a method without parameters that call the method you want
>> (as its just java code and you can call it yourself), or use a inlined
>> Camel processor to call the method from java code etc.
>>
>> The bean component is intended for calling methods with parameter
>> values with data from the Camel Exchange / Message - and not hardcoded
>> values.
>>
>> So what is your use case for calling this method with hard-coded values ?
>>
>>
>> On Sat, Jun 1, 2013 at 9:31 AM, Jan Matèrne (jhm) <ap...@materne.de>
>> wrote:
>> > The exchange could be passed to the bean method, therefore you could
>> store
>> > these values in the header or as exchange-properties.
>> >
>> > Something like
>> > class abc extends RouteBuilder {
>> >     private string str1 = 'a';
>> >     private string str2 = 'b';
>> >     .....
>> >     .....
>> >     .setHeader("str1", str1)
>> >     .setHeader("str2", str2)
>> >     .to().bean(myBean, methodName).end();
>> > }
>> >
>> > // @see http://camel.apache.org/bean.html
>> > // @see http://camel.apache.org/bean-binding.html
>> > class MyBean {
>> >     public String method(@Header("str1") str1, @Header("str2) str2) {
>> >         ....
>> >     }
>> > }
>> >
>> >
>> > Jan
>> >
>> >> -----Ursprüngliche Nachricht-----
>> >> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> >> Gesendet: Samstag, 1. Juni 2013 08:09
>> >> An: users@camel.apache.org
>> >> Betreff: Re: bean with method parameters in camel
>> >>
>> >> You cannot do this.
>> >>
>> >> On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar
>> >> <ag...@gmail.com> wrote:
>> >> > If i try .bean(className, methodName('a', 'b')) : it calls method
>> >> > methodName of class className with method parameters 'a' and 'b'.
>> >> > However, if i want value of method variables to come from class
>> >> > variables, how can i do that?
>> >> >
>> >> > what i mean is :
>> >> > class abc extends RouteBuilder {
>> >> >   private string str1 = 'a';
>> >> >   private string str2 = 'b';
>> >> > .....
>> >> > .....
>> >> > to().bean(className, methodName(str1, str2)).end();
>> >> >
>> >> > i get str1 and str2 classes not found exception. How can i pass str1
>> >> > and
>> >> > str2 values as method parameters without actually hardcoding them?
>> >>
>> >>
>> >>
>> >> --
>> >> Claus Ibsen
>> >> -----------------
>> >> www.camelone.org: The open source integration conference.
>> >>
>> >> 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
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> www.camelone.org: The open source integration conference.
>>
>> 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
>>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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 with method parameters in camel

Posted by Tarun Kumar <ag...@gmail.com>.
my use case is:

from().bean().end()

Based on user input, i want to make bean call. So, basically method
parameters for bean call will come from exchange as well as user input. I
was wondering if there is any way to make bean call with method parameters
as exchange as well some user input parameters.


On Sun, Jun 2, 2013 at 1:46 PM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> You can call a method without parameters that call the method you want
> (as its just java code and you can call it yourself), or use a inlined
> Camel processor to call the method from java code etc.
>
> The bean component is intended for calling methods with parameter
> values with data from the Camel Exchange / Message - and not hardcoded
> values.
>
> So what is your use case for calling this method with hard-coded values ?
>
>
> On Sat, Jun 1, 2013 at 9:31 AM, Jan Matèrne (jhm) <ap...@materne.de>
> wrote:
> > The exchange could be passed to the bean method, therefore you could
> store
> > these values in the header or as exchange-properties.
> >
> > Something like
> > class abc extends RouteBuilder {
> >     private string str1 = 'a';
> >     private string str2 = 'b';
> >     .....
> >     .....
> >     .setHeader("str1", str1)
> >     .setHeader("str2", str2)
> >     .to().bean(myBean, methodName).end();
> > }
> >
> > // @see http://camel.apache.org/bean.html
> > // @see http://camel.apache.org/bean-binding.html
> > class MyBean {
> >     public String method(@Header("str1") str1, @Header("str2) str2) {
> >         ....
> >     }
> > }
> >
> >
> > Jan
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> >> Gesendet: Samstag, 1. Juni 2013 08:09
> >> An: users@camel.apache.org
> >> Betreff: Re: bean with method parameters in camel
> >>
> >> You cannot do this.
> >>
> >> On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar
> >> <ag...@gmail.com> wrote:
> >> > If i try .bean(className, methodName('a', 'b')) : it calls method
> >> > methodName of class className with method parameters 'a' and 'b'.
> >> > However, if i want value of method variables to come from class
> >> > variables, how can i do that?
> >> >
> >> > what i mean is :
> >> > class abc extends RouteBuilder {
> >> >   private string str1 = 'a';
> >> >   private string str2 = 'b';
> >> > .....
> >> > .....
> >> > to().bean(className, methodName(str1, str2)).end();
> >> >
> >> > i get str1 and str2 classes not found exception. How can i pass str1
> >> > and
> >> > str2 values as method parameters without actually hardcoding them?
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> www.camelone.org: The open source integration conference.
> >>
> >> 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
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
>
> 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 with method parameters in camel

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

You can call a method without parameters that call the method you want
(as its just java code and you can call it yourself), or use a inlined
Camel processor to call the method from java code etc.

The bean component is intended for calling methods with parameter
values with data from the Camel Exchange / Message - and not hardcoded
values.

So what is your use case for calling this method with hard-coded values ?


On Sat, Jun 1, 2013 at 9:31 AM, Jan Matèrne (jhm) <ap...@materne.de> wrote:
> The exchange could be passed to the bean method, therefore you could store
> these values in the header or as exchange-properties.
>
> Something like
> class abc extends RouteBuilder {
>     private string str1 = 'a';
>     private string str2 = 'b';
>     .....
>     .....
>     .setHeader("str1", str1)
>     .setHeader("str2", str2)
>     .to().bean(myBean, methodName).end();
> }
>
> // @see http://camel.apache.org/bean.html
> // @see http://camel.apache.org/bean-binding.html
> class MyBean {
>     public String method(@Header("str1") str1, @Header("str2) str2) {
>         ....
>     }
> }
>
>
> Jan
>
>> -----Ursprüngliche Nachricht-----
>> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
>> Gesendet: Samstag, 1. Juni 2013 08:09
>> An: users@camel.apache.org
>> Betreff: Re: bean with method parameters in camel
>>
>> You cannot do this.
>>
>> On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar
>> <ag...@gmail.com> wrote:
>> > If i try .bean(className, methodName('a', 'b')) : it calls method
>> > methodName of class className with method parameters 'a' and 'b'.
>> > However, if i want value of method variables to come from class
>> > variables, how can i do that?
>> >
>> > what i mean is :
>> > class abc extends RouteBuilder {
>> >   private string str1 = 'a';
>> >   private string str2 = 'b';
>> > .....
>> > .....
>> > to().bean(className, methodName(str1, str2)).end();
>> >
>> > i get str1 and str2 classes not found exception. How can i pass str1
>> > and
>> > str2 values as method parameters without actually hardcoding them?
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> www.camelone.org: The open source integration conference.
>>
>> 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
>



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

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

AW: bean with method parameters in camel

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
The exchange could be passed to the bean method, therefore you could store
these values in the header or as exchange-properties.

Something like
class abc extends RouteBuilder {
    private string str1 = 'a';
    private string str2 = 'b';
    .....
    .....
    .setHeader("str1", str1)
    .setHeader("str2", str2)
    .to().bean(myBean, methodName).end();
}

// @see http://camel.apache.org/bean.html
// @see http://camel.apache.org/bean-binding.html
class MyBean {
    public String method(@Header("str1") str1, @Header("str2) str2) {
        ....
    }
}


Jan

> -----Ursprüngliche Nachricht-----
> Von: Claus Ibsen [mailto:claus.ibsen@gmail.com]
> Gesendet: Samstag, 1. Juni 2013 08:09
> An: users@camel.apache.org
> Betreff: Re: bean with method parameters in camel
> 
> You cannot do this.
> 
> On Thu, May 30, 2013 at 11:48 AM, Tarun Kumar
> <ag...@gmail.com> wrote:
> > If i try .bean(className, methodName('a', 'b')) : it calls method
> > methodName of class className with method parameters 'a' and 'b'.
> > However, if i want value of method variables to come from class
> > variables, how can i do that?
> >
> > what i mean is :
> > class abc extends RouteBuilder {
> >   private string str1 = 'a';
> >   private string str2 = 'b';
> > .....
> > .....
> > to().bean(className, methodName(str1, str2)).end();
> >
> > i get str1 and str2 classes not found exception. How can i pass str1
> > and
> > str2 values as method parameters without actually hardcoding them?
> 
> 
> 
> --
> Claus Ibsen
> -----------------
> www.camelone.org: The open source integration conference.
> 
> 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