Moshe Elisha created CAMEL-19098:
------------------------------------
Summary: Possible performance issue invoking a bean method with a
string parameter
Key: CAMEL-19098
URL: https://issues.apache.org/jira/browse/CAMEL-19098
Project: Camel
Issue Type: Bug
Components: camel-bean
Affects Versions: 3.20.2
Reporter: Moshe Elisha
Hi,
As discussed in the Camel users email thread -
[https://lists.apache.org/thread/3whp1726zttcckh20tdn0j9wj9vt6tgd]
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.
{{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);}}
{{ }}}
{{}}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)