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

Related

  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • Designing a Java Connector for Software Integrations
  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Trending

  • Add Observability to Your React Native Application in 5 Minutes
  • Real-World Problems Being Solved by Java
  • Why DDoS Protection Is an Architectural Decision for Developers
  • The Dark Side of Big Data: Pseudo-Science & Fooled By Randomness

Mule 4 HTTP Connector — Listener Configuration Explained

We will set up an HTTP connector and will work with the listener configurations to build a simple HTTP service to return a static message as the response.

By 
Karthik Selvaraj user avatar
Karthik Selvaraj
·
Nov. 02, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
17.8K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will set up an HTTP connector and will work with the listener configurations to build a simple HTTP service to return a static message as the response. The Anypoint studio version used will be version 7.6 and the mule run time version will be 4.3 for this demonstration and better to use the same version of Anypoint studio and mule run time if in case you are planning to try out to build the project.

Setting up a simple HTTP service:

  1. launch the Anypoint studio application and create a new mule project by traversing the below path

File -> New -> Mule project

anypoint mule

  1. Enter the project name as "HTTP-listener-project" and select the run time version of the mule as 4.3 (Please note, in my current setup I have only the run time version 4.3 installed. If in case multiple run time versions are installed please make sure to select version 4.3). Please click the finish button to continue.

project settings

  1. The new project is created and from the Mule palette on the right side, use the "add module" option to add the HTTP connector to the palette by dragging the HTTP connector.

get started

get started

get started

  1. When the HTTP connector in the Mule palette is clicked, the four components of the HTTP connector is displayed

  • Basic Security Filter
  • Listener
  • Load Static resource
  • Request
  1. In this demonstration, the configuration setup of the Listener component will be explained so drag the listener component to the canvas

http listener

  1. First, let us change the display name of the listener component from the default name of "Listener" to "First Listener" and also set up the "Connector Configuration" under the General -> Basic Settings by clicking the "+" symbol

message flow

http listener

  1. Now let's change the name of the connector configuration from the default name of "HTTP_Listener_config" to "First_HTTP_Listener_config" and also change the configuration for "Host" as "Localhost" from the default value "All Interfaces [0.0.0.0] (default)". Let us use the default port of "8081".

Note: We will discuss in detail the difference between using the host as "Localhost" and "All Interfaces [0.0.0.0] (default)" in another post. Also, any available port can be used and not necessarily requires port "8081" to be used.

listener config

  1. Before clicking the "Ok" button use the "Test Connection" button to check if the configuration works fine. If the port is available for connection and all the other configurations are working fine we will receive a success response as below.

test connection

If in case the port is being used by any other application then we will receive an error message as below and the same can be rectified by using a different port number or by stopping the application which is using the port "8081". For simplicity, we will go for a new port in this example as port "8082"

connection failed

test successful

Note: To illustrate the error message another application was build to use port "8081" and changed to "8082". We will continue to use 8081 for our demonstration

  1. Next, let us define the "path" parameter as "/test"

first listener

Note: If we need to allow specific HTTP methods, you can navigate to the "Advanced" option and provide the HTTP methods which should be allowed. If no value is provided, then all HTTP methods are allowed for use. In our example let us leave as blank to accept any HTTP method

listener

  1. Next, we will use the "Set Payload" transformer to default the response message as "First HTTP listener testing". First, select and drag the "Set Payload" component from Mule Palette "Core" option

package explorer

  1. Now let's set the Value in the "Set payload" transformer to "First HTTP listener testing". To do it first switch the value field to the literal mode by clicking the "fx" symbol and enter the phrase as mentioned below.

message flow

  1. Save the project and right-click on the canvas and use the "Run Project" option to execute the project.

listener studio

  1. After the project is successfully deployed, the status will appear as "DEPLOYED"deployed

  2. Now let's test the HTTP service which is built and to test we will use an open-source testing tool "Postman". Even though there are multiple tools available in markets such as SOAP UI and ARC, Postman is more user friendly and has a good interface. Add a new request and provide the URL as  "http://localhost:8081/test" as the HTTP service is hosted on port "8081" and the URL is "/test". As any HTTP method is allowed, let us check the working of the service by using the "GET" HTTP method my workspace We can see that we have received the response message as "First HTTP listener testing"

  3. To check if other HTTP methods are allowed, let us try using the "POST" method

postmanThe "POST" method also provides the same output and with this, we conclude the article on how to use the "HTTP Connector Listener Configuration"

Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Related

  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • Designing a Java Connector for Software Integrations
  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook