Java Component in Mule | Execute Java Class in Mule

Java Component in Mule | Execute Java Class in Mule

Java component delegates to a java class. It is invoked by Mule when a message is received.

flow of java component :

java class is present in src/main/java named as

package testjava;

import org.mule.api.MuleEventContext;
import org.mule.api.lifecycle.Callable;

public class Demo implements Callable {

public Object onCall(MuleEventContext eventContext) throws Exception {

String str = eventContext.getMessageAsString();

return str;


URL : http://localhost:8085/api/java
Method : POST

Input :

Output :

XML project code :

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

<mule xmlns:http="" xmlns="" xmlns:doc=""
    <http:listener-config name="HTTP_Listener_Configuration" host="" port="8085" doc:name="HTTP Listener Configuration" basePath="/api"/>
    <flow name="testjavaFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/java" doc:name="HTTP"/>
        <component  doc:name="Java" class="testjava.Demo">
        <set-payload value="#[payload]" doc:name="Set Payload"/>