0

我发现这originalPayloadmessage.originalPayloadgroovy 表达式不同。也就是说,以下转换器不会做同样的事情:

originalPayload

<expression-transformer evaluator="groovy" expression="originalPayload" />

message.originalPayload

<expression-transformer evaluator="groovy" expression="message.originalPayload" />

以下 mule 配置和测试用例可用于重现该问题:

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

        <expression-transformer evaluator="string" expression="bar" />

        <expression-transformer evaluator="groovy" expression="originalPayload" />
        <!-- or alternatively -->
        <!-- <expression-transformer evaluator="groovy" expression="message.originalPayload" /> -->
    </flow>
</mule>

测试用例可以是:

@Test
public void transformers() throws MuleException {
    final MuleClient client = muleContext.getClient();
    final MuleMessage reply = client.send("vm://test.Path", 1, null, RECEIVE_TIMEOUT);
    assertEquals(1, reply.getPayload());
}

替代方案message.originalPayload按预期工作。一个originalPayload没有,日志中显示了以下异常:

Exception stack is:
1. Expression Evaluator "groovy" with expression "originalPayload" returned null 
but a value was required. (org.mule.api.expression.RequiredValue Exception)

我可能做错了什么?

谢谢。

4

2 回答 2

1

问题在于它使用了一组expression-transformerscripting:transformera 使用的绑定不同的绑定scripting:component,这是因为它们在org.mule.module.scripting.component.Scriptable.

此外,当originalPayload被绑定时,它的值是错误的:

bindings.put("originalPayload", event.getMessage().getPayload());

因此:MULE-6215

于 2012-05-04T18:51:12.510 回答
0

Scripting Module Reference之后,它们应该是相同的。

此外,如果您查看脚本模块中的 org.mule.module.scripting.component.Scriptable,您会发现“originalPayload”是 message.getPayload。

您可以发布一个重现错误的小项目吗?

public void populateBindings(Bindings bindings, MuleMessage message)
{
    populateDefaultBindings(bindings);
    if (message == null)
    {
        message = new DefaultMuleMessage(NullPayload.getInstance(), muleContext);
    }
    bindings.put("message", message);
    //This will get overwritten if populateBindings(Bindings bindings, MuleEvent event) is called
    //and not this method directly.
    bindings.put("payload", message.getPayload());
    //For backward compatability
    bindings.put("src", message.getPayload());
}

public void populateBindings(Bindings bindings, MuleEvent event)
{
    populateBindings(bindings, event.getMessage());
    bindings.put("originalPayload", event.getMessage().getPayload());
    bindings.put("payload", event.getMessage().getPayload());
    bindings.put("eventContext", new DefaultMuleEventContext(event));
    bindings.put("id", event.getId());
    bindings.put("flowConstruct", event.getFlowConstruct());
    if (event.getFlowConstruct() instanceof Service)
    {
        bindings.put("service", event.getFlowConstruct());
    }
}
于 2012-05-04T00:14:57.910 回答