How To Invoke Java Function Within Data Weave Transform and Mule Flow

12
How To Invoke Java Function Within Data Weave Transform and Mule Flow

Transcript of How To Invoke Java Function Within Data Weave Transform and Mule Flow

How To Invoke Java

Function Within Data

Weave Transform and

Mule Flow

Data Weave

DataWeave makes transformations very easy. DataWeave is a language used to query and

transform complex data. It contains a lot of operators, including filters and functions. It

supports various formats including XML, JSON, CSV, Java, and EDI out of the box. DataWeave

code looks like JSON syntax and is format-neutral. It is very much possible to invoke

Java/Groovy function within DataWeave.

Invoke MEL Function Within

DataWeave Transform

You will receive two numbers as input message (Json format) and return addition of 2 numbers.

Below you can see what will be the input and output.

Invoke MEL Function Within

DataWeave Transform

Declare Spring MEL Function

You need declare a Spring MEL function in global configuration xml as shown below :

Invoke MEL Function Within

DataWeave Transform

DataWeave Transform

You need to invoke function addition expecting 2 arguments and it invoke with dataweave

transform as shown below:

Invoke Java Function Within

DataWeave Transform

Now, you will see how to invoke java function with your dataweave transformation. For example,

if you have class with name TestClass.java which have function addTwoNumbers accept two

argument and return the sum of two arguments.

Invoke Java Function Within

DataWeave Transform

Mule Global Configuration

Now, you need to make the entry of Java function in Mule Global Configuration as shown below:

Invoke Java Function Within

DataWeave Transform

DataWeave Transform

You need to invoke function addition expecting 2 arguments and it invoke with dataweave

transform as shown below:

Invoke Java Function Within Mule Flow

Now you will see how to invoke the java function with Mule flow.

Define Spring Beans

You need to define spring beans in your Mule xml flow as shown below :

Invoke Java Function Within Mule Flow

Invoke Component

Add invoke component in your flow and this will invoke your java class in the flow.

Invoke Java Function Within Mule Flow

Display Name is unique name for your component in the application.

Name is the name of message processor used for logging purpose.

Object Ref is a bean-name and it is reference to object contains method to be invoked.

Method is a function that need to be invoked.

Method Arguments is the parameters that needs to be pass to function. Multiple arguments can be specify using comma separated.

Method Arguments Types is data type for argument. Multiple argument type can specify using comma separated. Use this property whenever you have multiple method with same name in same class.

Now, you are aware how to invoke Java function within your dataweave transformation and Mule flow!

Thank You.