Thanks, Claus. I have created a Jira ticket[1]. We can continue the discussion there.
[1] https://issues.apache.org/jira/browse/CAMEL-19098 ________________________________ From: Claus Ibsen <claus.ib...@gmail.com> Sent: Monday, February 27, 2023 7:41 PM To: users@camel.apache.org <users@camel.apache.org> Subject: Re: Possible performance issue invoking a bean method with a string parameter CAUTION: This is an external email. Please be very careful when clicking links or opening attachments. See http://nok.it/ext for additional information. Hi Thanks for reporting. Can you create a JIRA ticket. Also you are welcome to send a PR with a unit test, we can use to assist fixing this performance problem. And if you have time and want to try to make a fix, then a PR is also welcome. You are welcome to do that on camel-3.x branch (as main is v4 and its more unstable due to heavy work). After a fix in 3.x we then cherry-pick this over to v4 later. On Mon, Feb 27, 2023 at 5:26 PM Moshe Elisha (Nokia) <moshe.eli...@nokia.com> wrote: > Hello, > > I have noticed that when invoking a bean method with a string parameter, > it works but a very special handling is needed to avoid a performance hit. > Example code below. > > When the parameter is not single quoted or double quoted - Camel tries to > resolve the value and in the process tries to load a class by that name > which is a very expensive process. This behavior is expected IMO. > When the parameter is single quoted or double quoted - Camel still tries > to resolve the value as a class name. IMO this is not behaving properly. > > This issue happens because > "StringQuoteHelper.splitSafeQuote(methodParameters, ',', true);" invoked in > "MethodInfo.ParameterExpression#evaluate" removes the single/double quotes. > Inside "MethodInfo.evaluateParameterValue" the > "BeanHelper.isValidParameterValue(exp)" is invoked and returns false and > therefor "BeanHelper.isAssignableToExpectedType" > ... > > "DefaultClassResolver.loadClass(String name, ClassLoader loader)" is > invoked every time the bean method is invoked. > > The current workaround I found is to add both types of quotes. With this > workaround, "MethodInfo.ParameterExpression#evaluate" removes the outer set > of quotes but keeps the inner one and > "BeanHelper.isValidParameterValue(exp)" returns true. > > Am I missing anything? Should I open a bug? > > Thanks. > > > public class MyRouteBuilder extends RouteBuilder { > @Override > public void configure() throws Exception { > from("timer:foo?period=2000") > .to("bean:myBean?method=myMethod(slow)") > .to("bean:myBean?method=myMethod('alsoSlow1')") > .to("bean:myBean?method=myMethod(\"alsoSlow2\")") > .to("bean:myBean?method=myMethod(\"'fast'\")"); > } > } > > > > public class MyBean { > public void myMethod(String str) { > System.out.println("str = " + str); > } > } > > I am using Apache Camel 3.20.2 > -- Claus Ibsen ----------------- @davsclaus Camel in Action 2: https://www.manning.com/ibsen2