Creating Global functions
- By Rahul Kumar
Creating Global functions
Global function can be used in any Mule Expression within the project.
You can then invoke it anywhere in your DataWeave code, without need for any
special syntax.
Creating Global functions
To create a global function, you must edit your Mule project’s XML file and
enclose any functions that you wish to define in the following set of tags,
which must be placed in the global elements section, before any of the
flows are defined.
Creating Global functions
Use any existing java functions or create one :
Create a java function
package org.rahul.util;
import org.apache.commons.lang3.text.WordUtils;
public class StringUtil {
public static String fullyCapitalize(String string)
{
String orignal_string = string;
System.out.println(orignal_string);
String fullyCapitalizedString = WordUtils.capitalizeFully(orignal_string);
System.out.println(fullyCapitalizedString);
return fullyCapitalizedString;
}
}
Creating Global functions
Edit your Mule project’s XML file and enclose any functions that you wish to define in the
following set of tags, which must be placed in the global elements section, before any of the
flows are defined.
Note : The function should be in the classpath
<expression-language>
<global-functions>
def fullyCapitalize(str) {
org.rahul.util.StringUtil.fullyCapitalize(str)
}
</global-functions>
</expression-language>
Configuration
Use the created function anywhere in your project in Mule Expressions, in
Dataweave component
%dw 1.0
%output application/json
---
{
"output” : fullyCapitalize(“HELLo how ArE yOU”),
}
Thank You

Creating global functions

  • 1.
  • 2.
    Creating Global functions Globalfunction can be used in any Mule Expression within the project. You can then invoke it anywhere in your DataWeave code, without need for any special syntax.
  • 3.
    Creating Global functions Tocreate a global function, you must edit your Mule project’s XML file and enclose any functions that you wish to define in the following set of tags, which must be placed in the global elements section, before any of the flows are defined.
  • 4.
    Creating Global functions Useany existing java functions or create one : Create a java function package org.rahul.util; import org.apache.commons.lang3.text.WordUtils; public class StringUtil { public static String fullyCapitalize(String string) { String orignal_string = string; System.out.println(orignal_string); String fullyCapitalizedString = WordUtils.capitalizeFully(orignal_string); System.out.println(fullyCapitalizedString); return fullyCapitalizedString; } }
  • 5.
    Creating Global functions Edityour Mule project’s XML file and enclose any functions that you wish to define in the following set of tags, which must be placed in the global elements section, before any of the flows are defined. Note : The function should be in the classpath <expression-language> <global-functions> def fullyCapitalize(str) { org.rahul.util.StringUtil.fullyCapitalize(str) } </global-functions> </expression-language>
  • 6.
    Configuration Use the createdfunction anywhere in your project in Mule Expressions, in Dataweave component %dw 1.0 %output application/json --- { "output” : fullyCapitalize(“HELLo how ArE yOU”), }
  • 7.