简体   繁体   English

您可以将null传递给Mule中的invoke组件吗?

[英]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. 上面的flowVars可以为null。 If they are, I don't seem to be able to pass them into the invoke component. 如果是这样,我似乎无法将它们传递给invoke组件。 Is there something wrong with what I'm doing above, or is it true that you can't pass null into an invoke component? 我在上面做的事情有什么问题吗,或者确实不能将null传递给调用组件?

With current Mule implementation, you will NOT be able to pass null values to invoke component. 使用当前的Mule实现,您将无法传递空值来调用组件。 When mule executes "invoke" component, internally it uses following method to transform the arguments. 当m子执行“调用”组件时,在内部使用以下方法转换参数。 Below method is present in InvokerMessageProcessor class. InvokerMessageProcessor类中提供以下方法。 Here, "arg" is the value you are passing and "type" is the class to which you want to assign value. 在这里,“ arg”是您要传递的值,“ type”是您要为其分配值的类。 When arg.getClass() statement is executed, you will see NullPointerException as arg value is null. 执行arg.getClass()语句时,您将看到NullPointerException,因为arg值为null。 This method must be patched to check for null and avoid NullPinterException. 必须修补此方法以检查是否为null并避免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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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