Invoke in Mule 4 | Handling Java in Mule 4

Invoke in Mule 4

Java Module in Mule 4 is to handle java code in mule.

1. New component is used to create instance of class.
2. Invoke component is used to invoke a java method of a class. So before Invoke we have to use New component to create instance of the class.
4. Invoke static is used to invoke a static method of a class.
5. It is used to validate that given instance is instance of class.


New component configuration:

Advanced setting:

Invoke component settings:

Validate Type settings:

Java class located in src/main/java:

Flow of invoke static:

Static invoke component configuration:

Method: GET


Static invoke URL: http://localhost:8085/static
Method: GET


XML project code:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="" xmlns:java=""
       xmlns:doc="" xmlns:xsi="" xsi:schemaLocation="">
       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="b9b13759-df20-4d08-89d1-3b26e3b35294" >
              <http:listener-connection host="" port="8085" />
       <flow name="test_javaFlow" doc:id="231601ea-098e-4a3e-bc79-ede33f33af53" >
              <http:listener doc:name="Listener" doc:id="a822823b-d8cb-40bf-af45-672d140ed582" config-ref="HTTP_Listener_config" path="/invoke"/>
              <java:new constructor="Test()" doc:name="New" doc:id="4cb81f7c-3d50-4343-9a5d-3383f448d33d" class="test_java.Test" target="test"/>
              <java:invoke doc:name="Invoke" doc:id="bdcd5fcd-cd43-4948-bdf2-2b3f816ca893" class="test_java.Test" method="a()" instance="#[vars.test]"/>
              <java:validate-type doc:name="Validate type" doc:id="b162a9e6-e549-48a3-b9b9-8a2f938a8c29" class="test_java.Test" instance="#[vars.test]"/>
              <set-payload value="#[payload]" doc:name="Set Payload" doc:id="81bd6430-f64a-4b7d-b45c-095a9ab43e24" />
       <flow name="test_javaFlow1" doc:id="48fd0e80-8507-4490-a7e2-dae441188936" >
              <http:listener doc:name="Listener" doc:id="43eb7c2a-9656-438d-9db2-8147f17454b9" config-ref="HTTP_Listener_config" path="/static"/>
              <java:invoke-static doc:name="Invoke static" doc:id="6686f6dc-487d-44a0-9f83-6b6ac3645117" class="test_java.Test" method="b()"/>

© 2020

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave