MuleSoft provides Java Module, which contains various operations to invoke methods from Java Classes
I will explain all available operations..
- How to invoke Static or Non-Static methods from a custom Java Class
- How to instantiate a class using New operation.
- How to validate type of a class instance using Validate Type operation
Major Use Cases:
- For suppose, if you have large number of java classes in a legacy system or If you have a Java Developers team working in parallel to implement business logic, then you can leverage those logic into MuleSoft by using Java Module.
- If you have some specific business case which can’t be implemented by using existing MuleSoft connectors or modules, then you can implement it in java and then invoke it by using Java Module
Java Module Operations
- Invoke Static - It is used to invoke static methods from a Java Class.
- New - It is used to create instance of a class, which can be subsequently used to invoke non-static methods of the class.
- Invoke - It is used to invoke methods of a class based on class instance. 'New' operation must be used first to generate the instance and then 'Invoke' can be used.
- Validate Type - Which can be used to validate the type of an instance. It validates that provided instance and class in the configuration match or not.
If they don’t match it throws JAVA:WRONG_INSTANCE_CLASS error type.
Sample Java Code:
package com.java.mule;
public class HelloJava {
public static String Welcome() {
return "Welcome to Mule Java World ..:-) ";
}
public static String addTwoStrings(String fname, String lname) {
String fullName = fname +" "+ lname;
return fullName;
}
public static int addTwoNumbers(int numA, int numB) {
int sum = numA + numB;
return sum;
}
}
Mule flow
Source code location: Github
Thanks for reading..
No comments:
Post a Comment