The Echo example illustrates how to use Mule ESB to build a simple HTTP request-response application.
In this example, a user invokes the Mule application by submitting a request via her browser (i.e. entering a specific URL,
http://localhost:8084/echo). The Mule Echo example application receives the request and returns the same payload, or "echoes", the response to the end user. In other words, when a user types
http://localhost:8084/echo into the address bar of her browser, Mule returns a message in the browser that reads,
/echo (see image below, left); if she enters
http://localhost:8084/moon, Mule responds with
/moon (below, right).
There are two functions the Echo example application illustrates:
After reading this document, and creating and running the Echo example in Mule ESB, you should be able to leverage what you have learned to create a very simple HTTP request-response application. To understand more about Mule ESB’s ability to integrate services and systems, access the Mule examples and see other applications in action.
This document describes the details of the example within the context of Mule Studio, Mule ESB’s graphical user interface (GUI). Where appropriate, the XML configuration follows the Studio interface screenshot in an expandable section.
As with this Echo example, you can create template applications straight out of the box in Mule Studio or Mule Standalone (Mule ESB without Studio). You can tweak the configurations of these use case-based templates to create your own customized applications in Mule.
Follow the procedure below to create, then run the Echo application in Mule ESB.
Complete the procedure in Examples and Exercises to create, then run the Echo template in Mule Studio, or the Echo example in Mule Standalone (Mule ESB without Studio).
Open your Web browser, type
http://localhost:8084/echoin the address bar, then press enter.
Your browser presents a message that reads,
In your browser’s address bar, replace the word
echowith the word
moon, then press enter.
Your browser presents a message that reads,
The Echo example application consists of one, simple EchoFlow which receives end user HTTP requests, logs messages’ payloads, and returns the payloads to end users as HTTP responses.
The sections below elaborate further on the configurations of the Echo application and how it works to respond to end user requests.
For Mule Studio Users
In Mule Studio, double-click an icon representing a building block to open its Properties Panel and examine the configuration details. Alternatively, you can click the Configuration XML tab to access and examine the application’s XML config file.
View the XML
1 2 3 4 5 6 7 8 9 10 11 12 <?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="EE-3.3.0" 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 "> <flow name="EchoFlow" doc:name="EchoFlow"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8084" doc:name="HTTP" doc:description="Process HTTP requests or responses."/> <logger message="About to echo #[message:payload]" level="INFO" doc:name="Logger"/> <echo-component doc:name="Echo"/> </flow> </mule>
The EchoFlow makes use of three building blocks to receive, process and respond to an end user request. When an end user request encounters the Echo application, the first building block it meets is the request-response HTTP Inbound Endpoint. Because it has a two-way message exchange pattern, this HTTP endpoint is responsible for both receiving requests from, and send sending responses to, the end user.
Two-Way vs. One-Way
Notice that the HTTP endpoint has a two-way message exchange pattern (as indicated by the small double-arrow icon — below, left). Because it must respond to the requester, the HTTP endpoint in this example has a request-response message exchange pattern.
If an HTTP endpoint has only to input information into an application, it requires a one-way message exchange pattern (below, right).
Next, the flow uses a Logger Component to log the message payload in the application’s log files. The logger component uses an Expression to determine what information in, or about, the message that it should log. In this case, because it needs to log the message payload, the instructions to log read
About to echo #[message:payload].
Finally, Mule moves the message to an Echo Component which simply returns the message payload as the response to an end user. In other words, the response echoes the request.