Using HTTP Listener Connector in Mule ESB application

In the previous tutorial, I already introduced to you all how to configure the HTTP Listener Connector in Anypoint Studio for Mule ESB application. In this tutorial, I will guide you all how to use it by an example.

My example is: we need a Mule ESB application that can receive an HTTP POST request, then get the body data from the request to transform it to other data format. To simply the example, we can log this body data request into the console.

First of all, we need create new Mule ESB Maven project as below:

Using HTTP Listener Connector in Mule ESB application

To enable our Mule ESB application can receive the HTTP request from client, we need use HTTP Connector in the Message Source of Mule Flow.

You can find out the HTTP Connector in Mule Palette tool:

Using HTTP Listener Connector in Mule ESB application

Let drag and drop it into the Editor of Anypoint Studio.

Using HTTP Listener Connector in Mule ESB application

To configure for HTTP Connector, you can reference again previous tutorial.

Here, I configured it as below:

Using HTTP Listener Connector in Mule ESB application

With Global HTTP Listener Configuration:

Using HTTP Listener Connector in Mule ESB application

After receiving the request, we need to get the data from request body by using a Transformer component named Byte Array to String.

The Transformer component as calling name, it will get the byte data and convert them to string.

To add this component, in Mule Palette, let search “Byte Array to String”:

Using HTTP Listener Connector in Mule ESB application

then drag and drop into Editor of Anypoint Studio.

Using HTTP Listener Connector in Mule ESB application

With this transformer component, we don’t need to have any configuration for it. Everything from input and output for this component will be done automatically.

After converting the body request data to string, the payload of Mule ESB message will be this string.

The final step, we need to do that is: log the body request data into console using Logger component.

Let find out the Logger component in Mule Palette.

Using HTTP Listener Connector in Mule ESB application

Drag and drop it into Editor

Using HTTP Listener Connector in Mule ESB application

For this component, we only need configure to print out the payload from Mule message as below:

Using HTTP Listener Connector in Mule ESB application

OK, we just finished the requirement. Now, we can make a test.

Let run our Mule ESB application, then open Postman tool and send a POST request with body data “name=Khanh”:

Using HTTP Listener Connector in Mule ESB application

then check the result in the console.

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment