Simple Java component in Mule
-
Upload
christian-hipolito -
Category
Technology
-
view
97 -
download
0
Transcript of Simple Java component in Mule
![Page 1: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/1.jpg)
Simple Java Component in Mule
![Page 2: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/2.jpg)
How to use Java in Mule
• Ever wonder how to use your own java class or utility in mule? Here is a simple sample on how to use a java component or class in mule.
• This project used mule 3.8 and 6.0 anypointstudio.
![Page 3: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/3.jpg)
Building your Java Component
• Assuming that you already created a new project. In this sample, I created a project named “simplejavacomponent”.
![Page 4: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/4.jpg)
• Also created a package for the java class i will create.
![Page 5: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/5.jpg)
![Page 6: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/6.jpg)
• Based from the previous slide, I created a class named “SimpleJavaComponent”.
• Also implement an interface named “Callable” from org.mule.api.lifecycle. You need this inherit classes by overriding the method “onCall” with a parameter name “MuleEventContext”.
• The override method simply returns any object or Object.
![Page 7: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/7.jpg)
![Page 8: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/8.jpg)
• In the previous slide, I simply get the current MuleMessage from the eventContext or MuleEventContext.
• Then I get the current payload and Cast it in a String. Then I simply return a String payload just to showcase how to call a java component. You can return any objects in onCall.
• You can used this functionality if you want to get values from current payload and manipulate those values to a new payload or simply regenerate the current payload to correct or format some values.
![Page 9: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/9.jpg)
![Page 10: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/10.jpg)
![Page 11: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/11.jpg)
![Page 12: Simple Java component in Mule](https://reader035.fdocuments.us/reader035/viewer/2022062822/5882212b1a28ab3f4c8b7c2b/html5/thumbnails/12.jpg)
END