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
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

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

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

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

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Memory Management in Couchbase’s Query Service
  • How to Build Slack App for Audit Requests
  • Idempotency in Distributed Systems: When and Why It Matters
  • Perfecting CRUD Functionality in NextJS

Trending

  • Unlocking AI Coding Assistants: Generate Unit Tests
  • Start Coding With Google Cloud Workstations
  • Agentic AI for Automated Application Security and Vulnerability Management
  • MySQL to PostgreSQL Database Migration: A Practical Case Study

Mule-HTTP Request and Response Example

Here, I'm going to explain handling HTTP requests and responses in Mule, using AnypointStudio version 6.0 and Mule version 3.8.

By 
Rajesh Kumar user avatar
Rajesh Kumar
·
Jul. 05, 16 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
30.3K Views

Join the DZone community and get the full member experience.

Join For Free

Here, I'm going to explain handling HTTP requests and responses in Mule, using AnypointStudio version 6.0 and Mule version 3.8.

(Used: HTTP Endpoint and Logger in the flow.)

1. Drag and drop the HTTP endpoint in the Mule flow and configure the HTTP listener configuration.

<http:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="7000"/>


We are using port number 7000.

Map the listener configuration to the HTTP endpoint which we have created.

<http:listener config-ref="HTTP_Listener_Configuration" doc:name="Receive HTTP request" path="/*"/>


2. Read the request from the URL, will be using set payload to do that.

<set-payload doc:name="Set Payload" value="#[message.inboundProperties['http.request.path']]"/>


Using MEL (Mule Expression Language) to read the request from the URL -message.inboundProperties['http.request.path']

3. Print the message in the browser using logger.

<logger doc:name="Log the payload" level="INFO" message="http example #[message.payload]"/>


Execute the Mule application and check the console for the successful deployment.

Enter the below URL in the browser :

http://localhost:7000/testhttp

You will see the response printing in the browser: testhttp

In the above example, we are using two functions.

1. reading from HTTP request and returns to response

2. logs the request

Total Flow XML :

<?xml version="1.0" encoding="UTF-8"?>
<mule version="EE-3.8.0" xmlns="http://www.mulesoft.org/schema/mule/core" 
  xmlns:core="http://www.mulesoft.org/schema/mule/core" 
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
xmlns:http="http://www.mulesoft.org/schema/mule/http" 
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 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:listener-config doc:name="HTTP Listener Configuration" host="0.0.0.0" name="HTTP_Listener_Configuration" port="7000"/>  
  <flow doc:name="HTTP Example" name="EchoFlow">       
    <http:listener config-ref="HTTP_Listener_Configuration" doc:name="Receive HTTP request" path="/*"/>       
    <set-payload doc:name="Set Payload" value="#[message.inboundProperties['http.request.path']]"/>   
    <logger doc:name="Log the payload" level="INFO" message="http example #[message.payload]"/>    
  </flow>
</mule>

That's all!

Requests

Opinions expressed by DZone contributors are their own.

Related

  • Memory Management in Couchbase’s Query Service
  • How to Build Slack App for Audit Requests
  • Idempotency in Distributed Systems: When and Why It Matters
  • Perfecting CRUD Functionality in NextJS

Partner Resources

×

Comments

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: