krishnaiah avvaru
krishnaiah avvaru

Reputation: 1

How to call instance java method in dataweave mule 4

I have an instance method in java class (MyUtils.getDesc(String)) and I have to call this method from a dataweave script .

I wrote the code below, but it is not working:

var obj = MyUtils::new()

test:obj.getDesc('testme').

Can someone help me? What is wrong here?

Upvotes: 0

Views: 791

Answers (1)

afelisatti
afelisatti

Reputation: 2835

You should instantiate your object through the Java Module and its new operation. Then you'll be able to invoke your method through DataWeave using the Java Module invoke function (supposing your instance was stored in a Mule variable named 'myUtils'):

Java::invoke('your.package.MyUtils', 'getDesc(String)', vars.myUtils, {arg0: 'testme'})

If you were dealing with a static method instead you could invoke it directly with DataWeave like this:

java!your::package::MyUtils::getDesc('testme')

Upvotes: 2

Related Questions