You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Alex Dettinger <al...@gmail.com> on 2019/06/02 16:19:25 UTC

Re: Null Argument treated as no parameter during method selection

Hi Ankit,

  I think you have spotted a very specific case. You could help by checking
whether this issue is present in the last camel version.
If it is not fixed there, then building a minimal camel test reproducing
the issue would be the way to go :)

Cheers,
Alex

On Thu, May 30, 2019 at 9:55 AM Ankit Bakshi <an...@ericsson.com>
wrote:

> Hi,
>
> I am trying to call Apaches' StringUtils class from my spring XML route
> file.
> I got to with the following code.
>
> <bean id="ExtnFieldServ"
> class="com.ericsson.tcrm.bil.customizations.util.ExtendedFieldManagerRouteBean"
> /> <!-just for reference-->
>
> <choice>
>                 <when>
>                     <simple>
>
> ${bean:org.apache.commons.lang.StringUtils?method=isNotEmpty(${bean:ExtnFieldServ?method=getFieldValueFromExchange(*,in.header.PA_CONTEXT,PaymentMethod)})}
>                     </simple>
> <!-stuff happens here-->
> </when>
> </ choice>
>
> This worked fine when bean:ExtnFieldServ?method=getFieldValueFromExchange
> returned a non-null value. But failed with null.
> Got the following exception
>
> org.apache.camel.component.bean.MethodNotFoundException: Method with name:
> isNotEmpty() (with no parameters) not found on bean:
> org.apache.commons.lang.StringUtils@3030debe of type:
> org.apache.commons.lang.StringUtils. Exchange[Message:
> com.ericsson.etelcrm.bil.common.exec.SessionContext@1bec93f]
>
> So basically camel was looking for a no parameter method when the actual
> argument evaluated to null. This is very strange. I don't know if this is
> normal behavior or a bug.
>
> So I had to think of another way to get the code to work. A couple of
> workarounds would work. One of which is posted below.
>
> <setProperty propertyName="CC_TMP_PAYMM">
>                 <simple>
>
> ${bean:ExtnFieldServ?method=getFieldValueFromExchange(*,in.header.PA_CONTEXT,PaymentMethod)}
>                 </simple>
>             </setProperty>
>             <choice>
>                 <when>
>                     <simple>
>
> ${bean:org.apache.commons.lang.StringUtils?method=isNotEmpty(property.CC_TMP_PAYMM)}
>                     </simple>
> <!-stuff happens here-->
> </when>
> </ choice>
>
> I went with property, the same approach can be taken with headers. Or I
> can create wrapper class around StringUtils which will have methods like
> below, and I would need to declare this wrapper as spring bean or use
> directly if I can using statics.
>
> public boolean isNotBlank()
>     {
>         return isNotBlank(null);
>     }
>
>     public boolean isEmpty(String value)
>     {
>         return org.apache.commons.lang.StringUtils.isEmpty(value);
>     }
>
> What I really wanna know if why Camel is looking for  a no parameter
> method when the parameter expression evaluates to null?
>
> Regards,
> Ankit Bakshi
>