2016-07-06 65 views
1

我有groovy變量組件,它將獲取入站屬性並將其設置在流程變量中,如下所示。使用Groovy獲取ESB Mule消息的入站屬性

if(message.inboundProperties.'http.query.params'.Brand != null){ 
    flowVars ['Brand'] = message.inboundProperties.'http.query.params'.Brand 
} 
return payload; 

但我得到低於指定的錯誤。看來inboundProperties不在groovy的範圍之內。您能否告訴我如何訪問groovy中的入站屬性。

注:我不想改變有效載荷。我的目標是創建基於queryparms的flowVars。錯誤的

部分:

No such property: inboundProperties for class: org.mule.DefaultMuleMessage (groovy.lang.MissingPropertyException) 
    org.codehaus.groovy.runtime.ScriptBytecodeAdapter:51 (null) 

回答

3

我看不到getInboundProperties()方法on DefaultMuleMessage

我猜你想:

if(message.getInboundProperty('http.query.params')?.Brand){ 
    flowVars ['Brand'] = message.getInboundProperty('http.query.params').Brand 
} 
+0

The?檢查null是我的新語法。感謝分享它。 – Simbu

1

有兩個選項來設置變量從入站屬性:

  1. 與MEL更換常規組件,使用Groovy組件與<expression-component doc:name="Expression">
  2. 不斷更換<scripting:component doc:name="Groovy">,然後修改現有代碼

    if(message.getInboundProperty('http.query.params').get('Brand') != null) { 
    flowVars ['Brand'] = message.getInboundProperty('http.query.params').get('Brand'); 
    } 
    return payload; 
    
1

使用message.getInboundProperty。

def brand = message.getInboundProperty('http.query.params').Brand 
if (brand != null){ 
    flowVars ['Brand'] = brand 
} 
return payload; 
+0

如果getInboundProperty返回null,那會給你一個NPE –

+0

有用的信息。謝謝。 – tbriscoe