2012-05-03 58 views
0

我發現originalPayload與groovy表達式中的message.originalPayload不同。也就是說,以下變壓器不這樣做同樣的事情:originalPayload不同於groovy腳本中的message.originalPayload

originalPayload

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

message.originalPayload

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

下騾子的配置和測試案例可以用來重現問題:

<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> 

測試情況c一個是:

@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) 

什麼可能我是做錯了什麼?

謝謝。

回答

1

的問題是,expression-transformerscripting:transformer使用一組不同的綁定不是由scripting:component所使用的一個,這是因爲他們調用org.mule.module.scripting.component.Scriptable的不同方法。

而且,當originalPayload獲取綁定,它是用錯誤的值:

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

因此:MULE-6215

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()); 
    } 
} 
+0

我很難張貼的文件。我在一個受限制的環境中工作。這個項目可以很容易地創建,但是,我發佈了關於原始問題的信息。 – beluchin