I have a Java method that will read some flow variables, do some aggregation and append the result to a list that already exists in another flow variable.
For this reason the method expects a MuleMessage. I thought it's obviously possible to pass a MuleMessage
to a java method, using the message
MEL variable like:
<invoke object-ref="Aggregator" method="aggregateSingle" methodArguments="#[message]" doc:name="Invoke"/>
But it turned out that this passes a MessageContext
object instead. But I need to set InvocationVariable
so this class is not useful. I know I've set variables in groovy, so perhaps this would work (I thought):
<invoke object-ref="Aggregator" method="aggregateSingle" methodArguments="#[groovy:message]" doc:name="Invoke"/>
But no, this somehow passes the payload
instead of the MuleMessage
.
So the only way I've found to do this is to actually call it in a Groovy component as below. Which means I have to create a new Aggregator object every time, instead of using the spring:bean
as I'd planned.
<scripting:transformer doc:name="aggregateSingle">
<scripting:script engine="Groovy"><![CDATA[
new com.example.Aggregator().aggregateSingle(message);
message
]]></scripting:script>
</scripting:transformer>
Is there no way to pass a MuleMessage
object to the Java method using invoke
?