2. Java Custom Component
• Java components are used write our custom code and custom
transformation. java transformers will be used when we cannot
transform a message using available Mule transformers. In this
example, following components are explained.
• Java Component
• Java component with singleton
• Invoke Component
• Java Transformer
3. • Reflection Entry Point Resolver
• Annotated Entry Point Resolver
• Invoking a service using java component
Below is the main flow which exposes a HTTP service and
refers to multiple sub flows one after another to cover all above
concepts.
4. Java Component:
Java component is used to refer a class which has complex code.
Example:
Below is sub flow named 'simple-java-component' which has Set
Payload and java component.
'Set Payload' component sets payload as "Custom Payload".
5. • Java component is reffered to custom made class
(UsingCallable) which implements Callable interface. This class is used
to print current payload, size of inbound properties and size of
invocation properties.
6. Above class implements Callable interface. it has
onCall(MuleEventContext eventContext) overriden method. This method
provides MuleEventContext . We can get all the data using MuleContext
instace as shown in above code snippet.Data-Mapper.
7. Java Component with Singleton:
The singleton object factory does not create a new instance for each
request; instead, the instance is shared.
Example:
Drag java component and double click on the java component to
bring up properties.
Click "+" symbol next to the 'Object' field
Select “core:singleton-object” and click "next".
8. Click on "..." button and select class
"com.techm.javacustomcomponents.UsingSingletonObject"
9. • Click on "Advanced" tab and create following three properties using "+"
as shown below and click on Finish.
• name
• dept
• location
Same properties with same names need to be created along with
setters and getters in "UsingSingletonObject" class. So that, specified
properties values in java component are assigned into java class
properties. Below is the code to create map object with these three
properties.
10.
11.
12.
13. • A bean needs to be created in global elements to use Invoke
component. Create a bean which refers to a custom made java class
in global elements. In "Global Elements" tab click on "Create" button.
• Click on "..." symbol next to "Class" field to select a java custom made
class. Provide some meaningful names in "ID" and "Name" fields. Click
on OK button.
14. • Drag a invoke component and double click on the component to bring
up the properties. Fill the required fields as shown below.
15.
16. • Name Any meaningful name
• Object Ref "ID" value of bean which is created earlier
• Method Method name which needs to be invoked
• Method Arguments Values of method arguments
• In the same way two more invoke components are created for
two methods (substract and multiply)