2. BASIC CONSIDERATIONS
• Anypoint Studio provides a set of transformers to
handle the most common data transformation
scenarios
• Developer can chain transformers if a transformer did
not exist for specific needs
• The DataWeave Transform Message component can be
used in place of most other transformers
3. SPECIAL CASES
• Transforming complex data structures
• Applying complex business rules
• The available transformers cannot meet the
requirement
• Simply throw the old lines of code into a component
instead of having to reengineer the code’s behavior
through a series of different Mule components
4. POSSIBLE SOLUTIONS
• Building custom components and/or transformers
• Turning to the most favorite Programming Languages:
o Java
o .NET
o Scripting languages: Groovy, Javascript, Python or Ruby
5. JAVA
• Java is the native language in which Mule is coded
• The Java component enables the developer to package
custom Java code that executes when the component
receives a message
• The Java component can be used to enhance the
functionality and capability of your web-based
applications written in Java
6. JAVA TRANSFORMER (1/2)
• Transforms a message from its original
format to a new, modified format.
• If rather than just changing the
message/payload, trigger a more complex
set of processes coded in Java, use a Java
Component.
7. JAVA TRANSFORMER (2/2)
To configure the Java
Transformer, selecting a
class is the only required
entry:
• Browse for an existing Java
class
• Add a new Java class
8. BASIC JAVA CLASS
• A class must extends:
o org.mule.transformer.AbstractMessageTransformer
Modifies the message and returns it as the output
message of the transformer.
o org.mule.transformer.AbstractTransformer
Modifies the payload and returns it as the output
payload.
• A class must be referenced in a fully-qualified name
10. JAVA CLASS: MESSAGE (2/3)
The class has access to Mule Message:
• Inbound Properties
• Outbound Properties
• Payload
• Attachments
11. JAVA CLASS: MESSAGE (3/3)
Run/debug a simple flow
• http://localhost:8081/?name=Max
• It will produce a variable
myProperty, and its value is: Hello,
Max
• It will keep the payload as is
13. JAVA CLASS: PAYLOAD (2/3)
The class has only access to Payload, therefore:
• Add new Byte Array to String Transformer
• Update the custom-transformer class to refer to the new
class
14. JAVA CLASS: PAYLOAD (3/3)
Run/debug the new flow
• Post a raw message: Max
• Send it to http://localhost:8081
• It will produce a new payload: Hello, Max
15. SUMMARY
Mule allows developers to:
• Build their own component and/or transformer
• Simply write their favorite programming language
• Choose the transformation scope