Introduction
This
application demonstrates a simple HTTP request-response activity. Mule responds
to end user calls submitted via Web browser with a message that reads,
"Hello World". This example was designed to
demonstrate the ability of a Mule application to interact with an end user via
an HTTP request. Its goal is to introduce users to Mule by illustrating very
simple functionality.
Overview
The Hello
World example consists of one simple Mule
flow.
This flow accepts an HTTP request, sets a static payload on the message,
then returns a response to the end user.
The
request-response inbound HTTP
endpoint receives
requests the end user submits to the Web service. Because it has a
request-response message exchange pattern, this HTTP endpoint is responsible
for both receiving and returning messages. The descriptive notes included in
the configuration of the endpoint helps other developers understand the actions
the element performs in the context of the application.
Implementation
We need to
complete the following procedure to create, then run this example in your own
instance of Anypoint Studio. We can create template applications
straight out of the box in Anypoint Studio and tweak the configurations of the
use case-based templates to create your own customized applications in Mule.
Open Anypoint
Studio, Right click and sect new à Mule Project.
Enter the
project name as ‘EAI_HelloWorldMuleProject’ select the Runtime as ‘Mule Server
3.5.0 CE’ then click on next.
Change the
project name as ‘EAI_HelloWorldMuleProjec’ as it shows small letters in this
step then click on finish.
Open EAI_HelloWorldMuleProjec.xml
file and it will show the empty flow. We need to implement our logic to display
Hello World.
Drag and
drop HTTP connector from connector pallet to Mule flow. Configure as shown
below.
Select the
HTTP connector à HTTP Properties à under General Tab enter the below configuration
details as shown.
Field
|
Value
|
General Tab
|
|
Display Name
|
HTTP
|
Host
|
localhost
|
Port
|
8081
|
Notes Tab
|
|
Description
|
This endpoint
receives an HTTP message.
|
Drag
and drop Set Payload transformer from
Transformations to sets a value in the
message payload. In this example, the value utilizes a Mule expression to set a static string on the payload. Like the
HTTP endpoint, the descriptive notes included in the configuration helps other
developers understand the actions the element performs in the context of the
application.
Select the
Set Payload à Set Payload Properties àunder General Tab enter the below configuration
details as shown.
Field
|
Value
|
General Tab
|
|
Display Name
|
Set Payload
|
Value
|
Hello Ameer
|
Notes Tab
|
|
Description
|
This processor sets the payload of the message to the string 'Hello Ameer'.
|