Mule http inbound endpoint example


In this article we will use http transport to receive data. You can either receive or post data, in our example, we will look into http inbound endpoint. It internally uses the GET method to return data from a request-response inbound endpoint.

We will add <http:inbound-endpoint> as the message source in the flow to configure the http inbound endpoint. An inbound HTTP endpoint exposes a service over HTTP, essentially making it an HTTP server.

HTTP/S endpoints are synchronous by default, so you do not have to set exchange-pattern=”request-response” but we still have specified exchange-pattern for clarity sake. We will send a message to the endpoint and expect a response from the flow. We can either use host, port and path attributes to specify the individual components, host server to which the HTTP must connect, the http server port and the location in the host domain. Alternatively we can also use the address attribute which is what we have done here.

In this example, we will simply start an HTTP server accepting requests on http://localhost:8888/someRequest.

<http:inbound-endpoint address="http://localhost:${port1}/someRequest" exchange-pattern="request-response"/>

When entered http://localhost:8888/someRequest in browser, you will see:

The appender message processor appends the string ” received”.

<append-string-transformer message=" Received"/>


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns=""

    <flow name="httpFlow" processingStrategy="synchronous">
        <http:inbound-endpoint address="http://localhost:${port1}/someRequest" exchange-pattern="request-response"/>
        <append-string-transformer message=" Received"/>


In the below example, we now make a client invocation of an HTTP endpoint.

MuleMessage message = new DefaultMuleMessage("<html><body>Hello</body></html>", ctx);
MuleMessage response = muleClient.send("http://localhost:8888/someRequest", message);


package com.javarticles.mule;

import org.mule.DefaultMuleMessage;
import org.mule.api.MuleContext;
import org.mule.api.MuleMessage;
import org.mule.api.context.MuleContextBuilder;
import org.mule.api.context.MuleContextFactory;
import org.mule.config.DefaultMuleConfiguration;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextBuilder;
import org.mule.context.DefaultMuleContextFactory;
import org.mule.module.client.MuleClient;

public class MuleHttpInboundExample {
    public static void main(String[] args) throws Exception {
        System.setProperty("port1", "8888");
        DefaultMuleConfiguration dmc = new DefaultMuleConfiguration();
        SpringXmlConfigurationBuilder configBuilder = new SpringXmlConfigurationBuilder(
        MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder();
        MuleContextFactory contextFactory = new DefaultMuleContextFactory();
        MuleContext ctx = contextFactory.createMuleContext(configBuilder,
        try {
            MuleClient muleClient = new MuleClient(ctx);
            MuleMessage message = new DefaultMuleMessage("<html><body>Hello</body></html>", ctx);
            MuleMessage response = muleClient.send("http://localhost:8888/someRequest", message);            
            System.out.println("Response: " + response.getPayloadAsString());
        } finally {


Response: <html><body>Hello</body></html> Received

Download the source code

This was an example about http inbound endpoint.

You can download the source code here:

Comments are closed.