简体   繁体   中英

Can you pass null into an invoke component in Mule?

I'm attempting something like the following:

 <invoke object-ref="importsManager" method="logImportError" methodArguments="#[flowVars['jobConfig']],#[flowVars.['importRecord']], #[exception], 'ERROR'" doc:name="Log Import Error"/>

The flowVars above may be null. If they are, I don't seem to be able to pass them into the invoke component. Is there something wrong with what I'm doing above, or is it true that you can't pass null into an invoke component?

With current Mule implementation, you will NOT be able to pass null values to invoke component. When mule executes "invoke" component, internally it uses following method to transform the arguments. Below method is present in InvokerMessageProcessor class. Here, "arg" is the value you are passing and "type" is the class to which you want to assign value. When arg.getClass() statement is executed, you will see NullPointerException as arg value is null. This method must be patched to check for null and avoid NullPinterException.

private Object transformArgument(Object arg, Class<?> type) throws TransformerException
{
    if (!(type.isAssignableFrom(arg.getClass())))
    {
        DataType<?> source = DataTypeFactory.create(arg.getClass());
        DataType<?> target = DataTypeFactory.create(type);
        // Throws TransformerException if no suitable transformer is found
        Transformer t = muleContext.getRegistry().lookupTransformer(source, target);
        arg = t.transform(arg);
    }
    return arg;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM