SlideShare a Scribd company logo
1 of 16
MULE: JAVA TRANSFORMER
ENABLES THE DEVELOPER TO PACKAGE CUSTOM JAVA
CODE
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
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
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
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
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.
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
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
JAVA CLASS: MESSAGE (1/3)
package com.mulesoft.learning;
import java.util.Map;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractMessageTransformer;
public class MessageTransformer extends AbstractMessageTransformer {
@Override
public Object transformMessage(MuleMessage message, String
outputEncoding) throws TransformerException {
Map<String, String> params =
message.getInboundProperty("http.query.params");
message.setInvocationProperty("myProperty", "Hello, " +
params.get("name"));
return message;
}
}
JAVA CLASS: MESSAGE (2/3)
The class has access to Mule Message:
• Inbound Properties
• Outbound Properties
• Payload
• Attachments
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
JAVA CLASS: PAYLOAD (1/3)
package com.mulesoft.learning;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
public class PayloadTransformer extends AbstractTransformer {
@Override
protected Object doTransform(Object src, String enc) throws
TransformerException {
return "Hello, " + src;
}
}
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
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
SUMMARY
Mule allows developers to:
• Build their own component and/or transformer
• Simply write their favorite programming language
• Choose the transformation scope
RESOURCES:
• https://docs.mulesoft.com/mule-user-guide/v/3.8/java-
transformer-reference

More Related Content

What's hot

What's hot (20)

Mule java part-1
Mule java part-1Mule java part-1
Mule java part-1
 
Mule esb introduction
Mule esb introductionMule esb introduction
Mule esb introduction
 
Introduction to mule esb
Introduction to mule esbIntroduction to mule esb
Introduction to mule esb
 
Mule Custom Aggregator
Mule Custom AggregatorMule Custom Aggregator
Mule Custom Aggregator
 
Mule rabbit mq
Mule rabbit mqMule rabbit mq
Mule rabbit mq
 
Message structure
Message structureMessage structure
Message structure
 
Mule esb usecase
Mule esb usecaseMule esb usecase
Mule esb usecase
 
Mule UDP Transport
Mule UDP TransportMule UDP Transport
Mule UDP Transport
 
Mule expression language
Mule expression languageMule expression language
Mule expression language
 
Mule system properties
Mule system propertiesMule system properties
Mule system properties
 
Mule esb
Mule esbMule esb
Mule esb
 
Mule dataweave
Mule dataweaveMule dataweave
Mule dataweave
 
Mule jms
Mule   jmsMule   jms
Mule jms
 
Connecting to external_application
Connecting to external_applicationConnecting to external_application
Connecting to external_application
 
Mule Expression Transformer
Mule Expression TransformerMule Expression Transformer
Mule Expression Transformer
 
Mule soa
Mule soaMule soa
Mule soa
 
Mule Amazon SNS Connector
Mule Amazon SNS ConnectorMule Amazon SNS Connector
Mule Amazon SNS Connector
 
Muleflowarchitecturepart2
Muleflowarchitecturepart2Muleflowarchitecturepart2
Muleflowarchitecturepart2
 
Rabbit Mq in Mule
Rabbit Mq in MuleRabbit Mq in Mule
Rabbit Mq in Mule
 
Mule esb
Mule esbMule esb
Mule esb
 

Similar to Mule: Java Transformer

Mule esb and_relevant_components
Mule esb and_relevant_componentsMule esb and_relevant_components
Mule esb and_relevant_components
Paaras Baru
 

Similar to Mule: Java Transformer (20)

Custom transformer and annotation
Custom transformer and annotationCustom transformer and annotation
Custom transformer and annotation
 
Ashok mule esb
Ashok mule esbAshok mule esb
Ashok mule esb
 
Java modulesystem
Java modulesystemJava modulesystem
Java modulesystem
 
Mule esb and_relevant_components
Mule esb and_relevant_componentsMule esb and_relevant_components
Mule esb and_relevant_components
 
Transformers in Mulesoft Anypoint
Transformers in Mulesoft AnypointTransformers in Mulesoft Anypoint
Transformers in Mulesoft Anypoint
 
Muletransformers
MuletransformersMuletransformers
Muletransformers
 
Mule transformers
Mule transformersMule transformers
Mule transformers
 
A short introduction on anypoint transformers
A short introduction on anypoint transformersA short introduction on anypoint transformers
A short introduction on anypoint transformers
 
Creating custom transformer
Creating custom transformerCreating custom transformer
Creating custom transformer
 
Java features
Java featuresJava features
Java features
 
Mule ESB
Mule ESBMule ESB
Mule ESB
 
ForEach scope
ForEach scopeForEach scope
ForEach scope
 
Srilekha mule esb
Srilekha mule esbSrilekha mule esb
Srilekha mule esb
 
Mule
MuleMule
Mule
 
Sai mule esb batch
Sai mule esb batchSai mule esb batch
Sai mule esb batch
 
Ashok mule esb
Ashok mule esbAshok mule esb
Ashok mule esb
 
Mule slides
Mule slides Mule slides
Mule slides
 
Mule esb kranthi
Mule esb kranthiMule esb kranthi
Mule esb kranthi
 
Mule esb kranthi
Mule esb kranthiMule esb kranthi
Mule esb kranthi
 
Mule esb
Mule esb Mule esb
Mule esb
 

Recently uploaded

Recently uploaded (20)

The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4jGraphSummit Milan - Visione e roadmap del prodotto Neo4j
GraphSummit Milan - Visione e roadmap del prodotto Neo4j
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14Spring into AI presented by Dan Vega 5/14
Spring into AI presented by Dan Vega 5/14
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 

Mule: Java Transformer

  • 1. MULE: JAVA TRANSFORMER ENABLES THE DEVELOPER TO PACKAGE CUSTOM JAVA CODE
  • 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
  • 9. JAVA CLASS: MESSAGE (1/3) package com.mulesoft.learning; import java.util.Map; import org.mule.api.MuleMessage; import org.mule.api.transformer.TransformerException; import org.mule.transformer.AbstractMessageTransformer; public class MessageTransformer extends AbstractMessageTransformer { @Override public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException { Map<String, String> params = message.getInboundProperty("http.query.params"); message.setInvocationProperty("myProperty", "Hello, " + params.get("name")); return message; } }
  • 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
  • 12. JAVA CLASS: PAYLOAD (1/3) package com.mulesoft.learning; import org.mule.api.transformer.TransformerException; import org.mule.transformer.AbstractTransformer; public class PayloadTransformer extends AbstractTransformer { @Override protected Object doTransform(Object src, String enc) throws TransformerException { return "Hello, " + src; } }
  • 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