Since Mule is built on Java and Spring, it has native integration capabilities to invoke Java and Spring components. In this tutorial, we shall learn how to pass request received from HTTP endpoint on to Java component and receive response.
Please complete Hello World lesson from last week before proceeding further.
First step, create a new project as described in the Hello World tutorial. Name the flow “java”.
Drag and drop the “HTTP” endpoint and “Echo” component as described in Hello World lesson. Double click on HTTP (Inbound Endpoint) and specify “java” for path field
Create a new Java class by clicking on File -> New -> Class.
Drag and drop a “Java” component between HTTP (Inbound Endpoint) and Echo component. Double click on “Java” component to bring up properties dialog. Click the + symbol next to “Object” field and select “core:singleton-object” and com.mulesoft.java.JavaMule for object type and class respectively. Click OK to save and close.
Open “Configuration XML” tab to see generated XML content.
Hit Save All and run “java.mflow” as Mule Application (right click on the file). Access http://localhost:8081/java from browser to see “Hello /java” output. If you carefully observe, we didn’t explicitly specify which method to invoke from JavaMule class. Through reflection, Mule automatically tries to identify relevant Java method. Sometimes, we may need to explicitly map request to specific methods. We are going to explore how to do this in subsequent lessons.