MuleSoft Java Module Tutorial : How to Invoke Java Methods

By | March 6, 2022

MuleSoft Java Module provides a set of operations which can be used to invoke methods from Java Classes in a very efficient and convenient manner.

In this MuleSoft Java Module Tutorial, we will cover all available operations of this Java Module and you will learn how to invoke Static or Non-Static methods from a custom Java Class and also how to instantiate a class using New operation. You will also learn how to validate type of a class instance using Validate Type operation from Java Module.

An Overview of Mule 4 Java Module

Before we jump to the demo of MuleSoft Java Module available for Mule 4, it is important to have a high level overview of the module to better understand the concepts and use-cases.

Java Module provides operations to integrate with existing Java Classes by enabling your message flows to invoke static or non-static Java Methods from java classes. This module makes it easier to utilize existing java code for your integration flows.

There can be a number of use-cases where Java Module of Mule 4 can be considered and can serve your requirements. E.g. if you have a large number of existing java classes in a legacy system or you have a team of Java Developers working in parallel to implement some use-cases; you can simply utilize the available code by hooking that code in your AnyPoint Studio based message flows by using Java Module.

Also, if you have some specific requirements which can’t be handled by any of the existing connectors or modules, you can think of implementing that in your custom java code and then get that integrated with your message flows using Java Module operations. E.g. if you have to use certain Java Libraries like awt for graphics, it is much convenient to implement your logic in standard Java and then utilize it in your Mule Flows using Java Module.

There can be many other usage scenarios depending on your project’s nature and requirements where use of Java Module can be vital.

MuleSoft Java Module Operations

Java Module provides following operations in its current version (1.2) :

  • Invoke Static

This operation of Java Module is used to invoke static methods from a Java Class.

  • New

This operation of Java Module is used to create instance of a class. It creates an instance which can be subsequently used to invoke non-static methods of the class.

  • Invoke

This operation of Java Module 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

This operation can be used to validate 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.

 

Mule 4 Java Module Demo

Now that you have a good understanding of the Java Module available in MuleSoft, watch below video on TutorialsPedia YouTube channel which covers and demonstrates all operations of Java Module.


Feel free to comment below if you have any questions. Refer to Mule 4 Tutorials for more where I have covered various topics about Mule 4 ESB.

Ajmal Abbasi

Ajmal Hussain Abbasi is Integration Consultant By Profession with 13+ years experience in Integration domain mainly with TIBCO products. He has extensive practical knowledge of TIBCO Business Works, TIBCO Cloud, TIBCO Flogo, TIBCO Mashery, TIBCO Spotfire, EMS and TIBCO ActiveSpaces. He has worked on a number of highly critical integration projects in various sectors by using his skills in TIBCO Flogo, TIBCO API Management (Mashery), TCI, Tibco Designer, TIBCO Business Studio, Adapters, TIBCO EMS, RV, Administrator, TIBCO BE, TIBCO ActiveSpaces etc. Ajmal Abbasi has experience with MuleSoft ESB as well. Ajmal Abbasi is also experienced in the area of API Management particularly with WSO2 API management platforms. Ajmal Abbasi is also experienced in developing solutions using Core Java and J2EE Technologies. You can contact Ajmal Abbasi for Consultancy, Technical Assistance and Technical Discussions.

More Posts - Website - Facebook - LinkedIn - YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *