Return-Path: X-Original-To: apmail-camel-issues-archive@minotaur.apache.org Delivered-To: apmail-camel-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E796319F81 for ; Tue, 22 Mar 2016 12:02:25 +0000 (UTC) Received: (qmail 28804 invoked by uid 500); 22 Mar 2016 12:02:25 -0000 Delivered-To: apmail-camel-issues-archive@camel.apache.org Received: (qmail 28691 invoked by uid 500); 22 Mar 2016 12:02:25 -0000 Mailing-List: contact issues-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list issues@camel.apache.org Received: (qmail 28676 invoked by uid 99); 22 Mar 2016 12:02:25 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Mar 2016 12:02:25 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 78A182C1F5D for ; Tue, 22 Mar 2016 12:02:25 +0000 (UTC) Date: Tue, 22 Mar 2016 12:02:25 +0000 (UTC) From: "Claus Ibsen (JIRA)" To: issues@camel.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (CAMEL-9690) bean parameter binding should check parameter types when using simple expressions MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CAMEL-9690?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:all-tabpanel ] Claus Ibsen resolved CAMEL-9690. -------------------------------- Resolution: Fixed > bean parameter binding should check parameter types when using simple exp= ressions > -------------------------------------------------------------------------= -------- > > Key: CAMEL-9690 > URL: https://issues.apache.org/jira/browse/CAMEL-9690 > Project: Camel > Issue Type: Improvement > Components: camel-core > Affects Versions: 2.16.2 > Environment: mac > Reporter: Minh Tran > Assignee: Claus Ibsen > Priority: Minor > Fix For: 2.18.0 > > > Hello > I=E2=80=99m using camel 2.16.2 and I=E2=80=99m finding the bean parameter= binding doesn=E2=80=99t seem to work very well on overloaded methods. See = below for an example > {noformat} > public class ClassA { > =09public int foo() { > =09=09return 0; > =09} > =09public int foo(String param1) { > =09=09return 1; > =09} > =09public int foo(String param1, String param2) { > =09=09return 2; > =09} > =09public int foo(String param1, ClassB param2) { > =09=09return 3; > =09} > =09public int foo(boolean param1, String param2) { > =09=09return 4; > =09} > } > public class ClassB { > } > {noformat} > Here are the routes > {noformat} > from("direct:noParam").bean(ClassA.class, "foo()").to("mock:end"); > from("direct:1Param").bean(ClassA.class, "foo(${body})").to("mock:end"); > from("direct:2Param").bean(ClassA.class, "foo(${body}, ${header.key})").t= o("mock:end=E2=80=9D); > {noformat} > And here are the tests > {noformat} > =09@EndpointInject(uri =3D "mock:end") > =09private MockEndpoint end; > =09@Produce > =09private ProducerTemplate producerTemplate; > =09@Test > =09// passes > =09public void testNoParam() throws InterruptedException { > =09=09end.expectedBodiesReceived(0); > =09=09producerTemplate.sendBodyAndHeader("direct:noParam", "body", "key",= "value"); > =09=09end.assertIsSatisfied(); > =09} > =09@Test > =09// passes > =09public void test1Param() throws InterruptedException { > =09=09end.expectedBodiesReceived(1); > =09=09producerTemplate.sendBodyAndHeader("direct:1Param", "body", "key", = "value"); > =09=09end.assertIsSatisfied(); > =09} > =09@Test > =09// throws ambiguous method call exception > =09public void test2Param_string() throws InterruptedException { > =09=09end.expectedBodiesReceived(2); > =09=09producerTemplate.sendBodyAndHeader("direct:2Param", "body", "key", = "value"); > =09=09end.assertIsSatisfied(); > =09} > =09@Test > =09// throws ambiguous method call exception > =09public void test2Param_classB() throws InterruptedException { > =09=09end.expectedBodiesReceived(3); > =09=09producerTemplate.sendBodyAndHeader("direct:2Param", "body", "key", = new ClassB()); > =09=09end.assertIsSatisfied(); > =09} > =09@Test > =09// passes > =09public void test2Param_boolBody() throws InterruptedException { > =09=09end.expectedBodiesReceived(4); > =09=09producerTemplate.sendBodyAndHeader("direct:2Param", true, "key", "v= alue"); > =09=09end.assertIsSatisfied(); > =09} > {noformat} > I don=E2=80=99t understand why test2Param_string and test2Param_classB th= row ambiguous call exceptions. Here=E2=80=99s a sample stack trace. > {noformat} > org.apache.camel.component.bean.AmbiguousMethodCallException: Ambiguous m= ethod invocations possible: [public int au.com.winning.navmidware.routes.na= vws.ClassA.foo(java.lang.String,java.lang.String), public int au.com.winnin= g.navmidware.routes.navws.ClassA.foo(java.lang.String,au.com.winning.navmid= ware.routes.navws.ClassB)]. Exchange[ID-minhmac-local-53614-1457474273519-0= -2][Message: body] > =09at org.apache.camel.component.bean.BeanInfo.chooseBestPossibleMethodIn= fo(BeanInfo.java:835) ~[camel-core-2.16.2.jar:2.16.2] > =09at org.apache.camel.component.bean.BeanInfo.chooseMethodWithMatchingBo= dy(BeanInfo.java:764) ~[camel-core-2.16.2.jar:2.16.2] > =09at org.apache.camel.component.bean.BeanInfo.chooseMethod(BeanInfo.java= :621) ~[camel-core-2.16.2.jar:2.16.2] > =09at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.= java:254) ~[camel-core-2.16.2.jar:2.16.2] > =09at org.apache.camel.component.bean.BeanInfo.createInvocation(BeanInfo.= java:183) ~[camel-core-2.16.2.jar:2.16.2] > {noformat} > From looking at the code in BeanInfo, I *think* it just tries to match th= e type on the body and if it sees multiple possible methods then it throws = the exception. I believe it should go further and try to match the type on = the other parameters as well? > To get around this issue temporarily, I=E2=80=99ve had to write an adapte= r class that wraps around ClassA but it=E2=80=99s not an ideal solution. -- This message was sent by Atlassian JIRA (v6.3.4#6332)