You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ee7arh <an...@2e-systems.com> on 2009/03/04 21:13:25 UTC

Is it possible to overload a bean method?

Hi,

I have a bean defined which has 3 methods all with same name but with
different arguements. I would like to route messages from a queue to this
bean and depending on the object type I was hoping that the correct method
would get called by overloading.

Instead i get the error:

org.apache.camel.NoTypeConversionAvailableException: No type converter
available to convert from type:.....

I noticed that the first method defined in my bean caused this error so it
looks like Camel takes the 1st method and tries (and fails) to convert the
message.

here is my bean definition:

@Service(value = "serviceEventGenerator")
public class ServiceEventGenerator {
    
    public ArrayList<ServiceEvent> generateServiceEvents(Object1 event) {}

    public ArrayList<ServiceEvent> generateServiceEvents(Object2 event) {}

    public ArrayList<ServiceEvent> generateServiceEvents(Object3 event) {}

}

(Incidentally in my example, Object 1,2 and 3 all extend from a parent class
"Objectn".)

And my route:

from("jms:queue:unmarshalledEventsQueue")
            .to("log:unmarshalledEventLogger?level=INFO")
           
.to("bean:serviceEventGenerator?methodName=generateServiceEvents")

Thanks in advance for any help

Andrew
-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-overload-a-bean-method--tp22338316p22338316.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Is it possible to overload a bean method?

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

I created a ticket for it
https://issues.apache.org/activemq/browse/CAMEL-1424


On Thu, Mar 5, 2009 at 9:49 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Thu, Mar 5, 2009 at 9:40 AM, ee7arh <an...@2e-systems.com> wrote:
>>
>> Thanks for the feedback,
>>
>> It looks like we are talking about the same use case. In my example, all my
>> methods had the same name, but each method had a different parameter
>> (Object1, 2 and 3). Each of these parameter types inheritted from "Objectn".
>> So each method did have a different concrete sub-type although all are
>> instances of Objectn. In your example, your 3rd method has a different
>> name... was that a typo?
> Yeah probably.
>>
>> I could certainly use different method names, it would just mean I have to
>> have some more logic in my RouteBuilder. At the moment, I just send objects
>> off the queue to the same bean method and ask it to take care of selecting
>> the correct one by overloading.
> You can send it to an indirect method that will check the type and
> invoke the correct method of the 3.
> Then you route can stay simple.
>
>
>
>>
>> Thanks and Regards
>> Andrew
>>
>>
>> ee7arh wrote:
>>>
>>> Hi,
>>>
>>> I have a bean defined which has 3 methods all with same name but with
>>> different arguements. I would like to route messages from a queue to this
>>> bean and depending on the object type I was hoping that the correct method
>>> would get called by overloading.
>>>
>>> Instead i get the error:
>>>
>>> org.apache.camel.NoTypeConversionAvailableException: No type converter
>>> available to convert from type:.....
>>>
>>> I noticed that the first method defined in my bean caused this error so it
>>> looks like Camel takes the 1st method and tries (and fails) to convert the
>>> message.
>>>
>>> here is my bean definition:
>>>
>>> @Service(value = "serviceEventGenerator")
>>> public class ServiceEventGenerator {
>>>
>>>     public ArrayList<ServiceEvent> generateServiceEvents(Object1 event) {}
>>>
>>>     public ArrayList<ServiceEvent> generateServiceEvents(Object2 event) {}
>>>
>>>     public ArrayList<ServiceEvent> generateServiceEvents(Object3 event) {}
>>>
>>> }
>>>
>>> (Incidentally in my example, Object 1,2 and 3 all extend from a parent
>>> class "Objectn".)
>>>
>>> And my route:
>>>
>>> from("jms:queue:unmarshalledEventsQueue")
>>>             .to("log:unmarshalledEventLogger?level=INFO")
>>>
>>> .to("bean:serviceEventGenerator?methodName=generateServiceEvents")
>>>
>>> Thanks in advance for any help
>>>
>>> Andrew
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/Is-it-possible-to-overload-a-bean-method--tp22338316p22347357.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: Is it possible to overload a bean method?

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Mar 5, 2009 at 9:40 AM, ee7arh <an...@2e-systems.com> wrote:
>
> Thanks for the feedback,
>
> It looks like we are talking about the same use case. In my example, all my
> methods had the same name, but each method had a different parameter
> (Object1, 2 and 3). Each of these parameter types inheritted from "Objectn".
> So each method did have a different concrete sub-type although all are
> instances of Objectn. In your example, your 3rd method has a different
> name... was that a typo?
Yeah probably.
>
> I could certainly use different method names, it would just mean I have to
> have some more logic in my RouteBuilder. At the moment, I just send objects
> off the queue to the same bean method and ask it to take care of selecting
> the correct one by overloading.
You can send it to an indirect method that will check the type and
invoke the correct method of the 3.
Then you route can stay simple.



>
> Thanks and Regards
> Andrew
>
>
> ee7arh wrote:
>>
>> Hi,
>>
>> I have a bean defined which has 3 methods all with same name but with
>> different arguements. I would like to route messages from a queue to this
>> bean and depending on the object type I was hoping that the correct method
>> would get called by overloading.
>>
>> Instead i get the error:
>>
>> org.apache.camel.NoTypeConversionAvailableException: No type converter
>> available to convert from type:.....
>>
>> I noticed that the first method defined in my bean caused this error so it
>> looks like Camel takes the 1st method and tries (and fails) to convert the
>> message.
>>
>> here is my bean definition:
>>
>> @Service(value = "serviceEventGenerator")
>> public class ServiceEventGenerator {
>>
>>     public ArrayList<ServiceEvent> generateServiceEvents(Object1 event) {}
>>
>>     public ArrayList<ServiceEvent> generateServiceEvents(Object2 event) {}
>>
>>     public ArrayList<ServiceEvent> generateServiceEvents(Object3 event) {}
>>
>> }
>>
>> (Incidentally in my example, Object 1,2 and 3 all extend from a parent
>> class "Objectn".)
>>
>> And my route:
>>
>> from("jms:queue:unmarshalledEventsQueue")
>>             .to("log:unmarshalledEventLogger?level=INFO")
>>
>> .to("bean:serviceEventGenerator?methodName=generateServiceEvents")
>>
>> Thanks in advance for any help
>>
>> Andrew
>>
>
> --
> View this message in context: http://www.nabble.com/Is-it-possible-to-overload-a-bean-method--tp22338316p22347357.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/

Re: Is it possible to overload a bean method?

Posted by ee7arh <an...@2e-systems.com>.
Thanks for the feedback,

It looks like we are talking about the same use case. In my example, all my
methods had the same name, but each method had a different parameter
(Object1, 2 and 3). Each of these parameter types inheritted from "Objectn".
So each method did have a different concrete sub-type although all are
instances of Objectn. In your example, your 3rd method has a different
name... was that a typo?

I could certainly use different method names, it would just mean I have to
have some more logic in my RouteBuilder. At the moment, I just send objects
off the queue to the same bean method and ask it to take care of selecting
the correct one by overloading.

Thanks and Regards
Andrew


ee7arh wrote:
> 
> Hi,
> 
> I have a bean defined which has 3 methods all with same name but with
> different arguements. I would like to route messages from a queue to this
> bean and depending on the object type I was hoping that the correct method
> would get called by overloading.
> 
> Instead i get the error:
> 
> org.apache.camel.NoTypeConversionAvailableException: No type converter
> available to convert from type:.....
> 
> I noticed that the first method defined in my bean caused this error so it
> looks like Camel takes the 1st method and tries (and fails) to convert the
> message.
> 
> here is my bean definition:
> 
> @Service(value = "serviceEventGenerator")
> public class ServiceEventGenerator {
>     
>     public ArrayList<ServiceEvent> generateServiceEvents(Object1 event) {}
> 
>     public ArrayList<ServiceEvent> generateServiceEvents(Object2 event) {}
> 
>     public ArrayList<ServiceEvent> generateServiceEvents(Object3 event) {}
> 
> }
> 
> (Incidentally in my example, Object 1,2 and 3 all extend from a parent
> class "Objectn".)
> 
> And my route:
> 
> from("jms:queue:unmarshalledEventsQueue")
>             .to("log:unmarshalledEventLogger?level=INFO")
>            
> .to("bean:serviceEventGenerator?methodName=generateServiceEvents")
> 
> Thanks in advance for any help
> 
> Andrew
> 

-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-overload-a-bean-method--tp22338316p22347357.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Is it possible to overload a bean method?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 4, 2009 at 9:13 PM, ee7arh <an...@2e-systems.com> wrote:
>
> Hi,
>
> I have a bean defined which has 3 methods all with same name but with
> different arguements. I would like to route messages from a queue to this
> bean and depending on the object type I was hoping that the correct method
> would get called by overloading.
>
> Instead i get the error:
>
> org.apache.camel.NoTypeConversionAvailableException: No type converter
> available to convert from type:.....
>
> I noticed that the first method defined in my bean caused this error so it
> looks like Camel takes the 1st method and tries (and fails) to convert the
> message.
>
> here is my bean definition:
>
> @Service(value = "serviceEventGenerator")
> public class ServiceEventGenerator {
>
>    public ArrayList<ServiceEvent> generateServiceEvents(Object1 event) {}
>
>    public ArrayList<ServiceEvent> generateServiceEvents(Object2 event) {}
>
>    public ArrayList<ServiceEvent> generateServiceEvents(Object3 event) {}
>
> }
>
> (Incidentally in my example, Object 1,2 and 3 all extend from a parent class
> "Objectn".)
You have a bit of complex use case as you have the same method
overloaded 3 times with 3 objects inheriting from the same parent
class.
This for sure would lead to ambiguity. What it should do is to pick
the method of the 3 that has excactly the same type as the payload.

For example

methodA(Foo foo)
methodA(Bar bar)
methodB(Baz baz)

And they all inhertid from eg MyCoolObject

And you pass in a message contaning a Bar payload then Camel should
select the 2nd method.

This could work however I cant remember if it caters for this
currently, I might only check for instanceof and thus will get 3 hits.
I need to double check the code.

But why not name then methods differently
methodAwithFoo
methodAwithBar
..

We have improving the Bean method selector algorithm on the roadmap
for 2.0 so I will take you use case into consideration.


>
> And my route:
>
> from("jms:queue:unmarshalledEventsQueue")
>            .to("log:unmarshalledEventLogger?level=INFO")
>
> .to("bean:serviceEventGenerator?methodName=generateServiceEvents")
>
> Thanks in advance for any help


>
> Andrew
> --
> View this message in context: http://www.nabble.com/Is-it-possible-to-overload-a-bean-method--tp22338316p22338316.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/