DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Trending

  • Navigating Change Management: A Guide for Engineers
  • Building a Real-Time Audio Transcription System With OpenAI’s Realtime API
  • Analyzing Techniques to Provision Access via IDAM Models During Emergency and Disaster Response
  • Enhancing Business Decision-Making Through Advanced Data Visualization Techniques
  1. DZone
  2. Coding
  3. Java
  4. Mule Expressions Using Java

Mule Expressions Using Java

Read this short and simple tutorial in order to learn how to use Java code to perform validation for variables in the Mule flow.

By 
Varun Goyal user avatar
Varun Goyal
·
May. 12, 18 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
18.9K Views

Join the DZone community and get the full member experience.

Join For Free

When we use variables in a Mule flow, we often come across the scenario for the validation. Mule provides us an expression component where we can use Java code to perform the validation that not only increases the time but also increases efficiency in the complex flows.

The component invokes the expression written, and based on the conditions, evaluates the result that could be either user-defined or a referenced one. The format involves display name, Expression, File.

Here in the flow, there are two variables defined namely: ID and Name as shown in the flow. An Expression component consists of Java Code and a logger to log the result from the request URI.

Image title

Here is the code that gives the customized information about the use of Expression component using Java Code.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:validation="http://www.mulesoft.org/schema/mule/validation" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/validation http://www.mulesoft.org/schema/mule/validation/current/mule-validation.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <flow name="expressioninjavaFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/Test" doc:name="HTTP" allowedMethods="GET"/>
        <set-variable variableName="Name" value="#[message.inboundProperties.'http.query.params'.name]" doc:name="Name"/>
        <set-variable variableName="Id" value="#[message.inboundProperties.'http.query.params'.id]" doc:name="Id"/>
        <expression-component doc:name="Expression"><![CDATA[flowVars.checkflag='false';      

if(flowVars.id != "" &&  flowVars.name  != "" )
{
flowVars.checkflag='true';      
}
]]></expression-component>
        <logger message="#[flowVars]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>


The conditions are checked to see whether name and ID are empty, and a flag named check flag is initially set to True. If both the conditions satisfy, we set the check flag value to true or else it will return false.

The configuration of HTTP Listener can be set as per the port availability and being set in the code.

Request URI: http://localhost:8081/Test?id=1&name=Varun 

Response:    

Image title

So, it is an easier way to use Java code within the Mule Expression Component, increasing the efficiency of results.

Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 3: Understanding Janus
  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • How to Introduce a New API Quickly Using Micronaut
  • Introducing Graph Concepts in Java With Eclipse JNoSQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!