With Mule scripting, I am able to access a Mule Message in Groovy, JavaScript and Jython via a message variable. With JRuby I cannot:
undefined local variable or method `message' for main:Object (NameError)
Neither the Mule docs or the Internets have anything to say on this. How can I access the message from Ruby?
Code
<scripting:transformer name="SetData" doc:name="Set Data">
<scripting:script engine="jruby">
<scripting:text><![CDATA[File.open('/tmp/foo', 'w') { |f| f.puts message.payload }]]></scripting:text>
</scripting:script>
</scripting:transformer>
Mule bound variables end up in the global scope, so you need to refer them with
$name.In your case:
Note that if you only need the message payload, you’d rather use
$payloadinstead of$message.payload.Also your transformer looks more like a component IMO: it acts on the data (writes to file) instead of transforming it. It doesn’t even have a clear return value (you sure don’t want to process the return of
File.openin Mule. So ascripting:componentwould be more in order here.Finally, if all you need to do is write to file, you can use a File outbound endpoint from Mule that does just that.