getting inbound properties of ESB Mule message using Groovy

倾然丶 夕夏残阳落幕 提交于 2019-12-08 07:37:53

问题


I have groovy transformer component which is to get the inbound properties and set it in the flow vars as like below.

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

But I am getting below specified error. It seems inboundProperties are not in the scope of groovy. Can you please tell me how to access inbound properties in groovy.

Note : I dont want to alter the payload. My aim is to create the flowVars based on queryparms.

Part of Error :

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

回答1:


I can't see a getInboundProperties() method on DefaultMuleMessage

I'm guessing you want:

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



回答2:


You have two options to set the variable from inbound properties:

  1. Replace the groovy component with MEL, replace <scripting:component doc:name="Groovy"> with <expression-component doc:name="Expression">
  2. Keep using groovy component, then modify the existing code

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



回答3:


Use message.getInboundProperty.

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


来源:https://stackoverflow.com/questions/38231587/getting-inbound-properties-of-esb-mule-message-using-groovy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!