Start an App from a Browser Example - Mule 4

The following example illustrates how to configure the Anypoint Connector for HTTP (HTTP Connector) Listener source to initiate a flow. In this example, HTTP Listener listens on a specific port for every network interface on the server. Then, the Logger component logs the message Hello. To accomplish this example, you must create the Mule app, configure an HTTP global element, run, and test the app with curl commands.

The following screenshot shows the Anypoint Studio app flow for this example:

Start app from a browser flow
Figure 1. Start app from a browser flow

Create the Mule Application

To create the Mule flow:

  1. In the Mule Palette view, select the HTTP Listener source and drag it on to the canvas.
    The source initiates the flow by listening for incoming HTTP message attributes.

  2. On the Listener configuration screen, optionally change the value of the Display Name field.

  3. Set the Path field to /trigger to start the app from the web browser.

  4. Click the plus sign (+) next to the Connector configuration field to configure a global element that can be used by all instances of the HTTP Listener in the app.

  5. On the General tab, configure the following fields:

    • Host
      All Interfaces [] (default)

    • Port

  6. Click OK.

    HTTP Listener global configuration
    Figure 2. HTTP Listener global configuration
    HTTP Listener configuration
    Figure 3. HTTP Listener configuration
  7. Drag a Logger component to the right of HTTP Listener.

  8. In the Logger configuration screen, set the Message field to Hello.

    Logger configuration
    Figure 4. Logger configuration
  9. Save your Mule app.

  10. Click the project name in Package Explorer and then click Run > Run As > Mule Application.
    Ensure that the console messages state that the application started correctly by looking at the message Mule is up and kicking.

  11. Open a browser and type
    The HTTP Listener source listens to the request on port 8081, and the app starts.

  12. In the Studio Console, scroll through the logs to see the Hello message, for example:

INFO  2020-01-02 13:00:00,438 [[MuleRuntime].cpuLight.15: [http].httpFlow.CPU_LITE @169a1097]
  [event: id] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Hello

XML for Starting an App from a Browser

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule app:

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

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
	<http:listener-config name="HTTP_Listener_config" >
		<http:listener-connection host="" port="8081" />
	<flow name="flow" >
		<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="/trigger"/>
		<logger level="INFO" doc:name="Logger" message="Hello"/>

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub