Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mule 方法入口点解析器是否能够将参数强制转换为基类?_Mule - Fatal编程技术网

Mule 方法入口点解析器是否能够将参数强制转换为基类?

Mule 方法入口点解析器是否能够将参数强制转换为基类?,mule,Mule,我试图获得一个方法入口点解析器,以将有效负载转换为基类,如请求方法的参数所示。然而,骡子并没有这样做。我可能做错了什么 即,给定以下配置: <mule ...> <spring:bean id="FooBean" class="foo.Foo" /> <flow name="test"> <vm:inbound-endpoint name="test.Name" path="test.Path" exchange-pat

我试图获得一个方法入口点解析器,以将有效负载转换为基类,如请求方法的参数所示。然而,骡子并没有这样做。我可能做错了什么

即,给定以下配置:

<mule ...>
    <spring:bean id="FooBean" class="foo.Foo" />

    <flow name="test">
        <vm:inbound-endpoint name="test.Name" path="test.Path" exchange-pattern="request-response" />

        <component>
            <method-entry-point-resolver>
                <include-entry-point method="bar" />
            </method-entry-point-resolver>
            <spring-object bean="FooBean" />
        </component>        
    </flow>
</mule>
我希望下面的测试能够通过,但它没有通过。也就是说,我发送给流的负载是一个
整数
,我希望Mule将其作为参数传递给
Foo::bar

@Test
public void methodEntryPointResolverUpcasts() throws MuleException {
    final MuleClient client = muleContext.getClient();
    final MuleMessage reply = client.send("vm://test.Path", new Integer(1), null, RECEIVE_TIMEOUT);
    assertEquals("bar", reply.getPayload());
}
相反,日志显示一个错误。以下是一个相关的片段:


...
Message               : Failed to find entry point for component, the following resolvers tried but failed: [
ExplicitMethodEntryPointResolver: Could not find entry point on: "foo.Foo" with arguments: "{class java.lang.Integer}"
]
...
Exception stack is:
1. Failed to find entry point for component, the following resolvers tried but failed: [
ExplicitMethodEntryPointResolver: Could not find entry point on: "foo.Foo" with arguments: "{class java.lang.Integer}"


Mule的入口点解析器本身不执行强制转换:它们寻找可能接受特定负载的方法

这就是说,
方法入口点解析器
需要严格的类型匹配才能工作。在幕后,我们在支持它的类ExplicitMethodEntryPointResolver.java中找到以下行:

if (ClassUtils.compare(parameterTypes, classTypes, false, true))
false
表示:对象上不匹配。这就是为什么匹配不适合你的原因。不幸的是,这是不可配置的

当您删除入口点解析器的显式配置时,Mule使用默认的解析器链,其中包含
反射入口点解析器
。这是一个愉快地将整数传递到对象参数的函数,因为在ReflectionEntryPointResolver.java中:

methods = ClassUtils.getSatisfiableMethods(component.getClass(), 
            ClassUtils.getClassTypes(payload), true, true, ignoredMethods);
第二个真的意思是:对象匹配


因此,如果您想在配置中指定一个单入口点解析器,
反射入口点解析器
是您的朋友:)

我对此不太清楚,但它似乎正在寻找一个在
foo.foo
上采用
整数的方法,为什么不尝试将
bar
方法更改为采用
Integer
而不是
Object
?@Francis,如果您将
Foo::bar
上的参数类型更改为
Integer
,它将按预期工作。然而,我对演员的行为感兴趣。例如,如果从组件中删除入口点解析程序,Mule可以正确强制转换。因此,
反射入口点解析程序
是唯一不需要严格类型匹配的解析程序,正确吗?在源代码之后,
属性入口点解析器
似乎对对象匹配也很宽容,因此不应该要求严格的类型匹配。它确实感觉不一致。
methods = ClassUtils.getSatisfiableMethods(component.getClass(), 
            ClassUtils.getClassTypes(payload), true, true, ignoredMethods);