Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Build a Hello World Application

It’s time to roll up your sleeves and build your first Anypoint Studio application!

As the objective of this quick tutorial is get something built and running fast, this document doesn’t spend much time explaining components. More detailed explanations and concepts exist in the Anypoint Fundamentals, but for now, let’s just see Mule work: you’re about to build a very simple application in Studio, deploy it to Studio’s embedded server, then interact with the application through a Web browser.

Assumptions

This tutorial assumes that you have downloaded, installed, and launched Anypoint Studio, and that you’ve read through the Anypoint Studio Essentials.

Creating a New Project

  1. In Anypoint Studio, click File then select New > Mule Project.

  2. Studio opens the New Mule Project wizard. In the Name field, enter the value My First Project, then click Finish.

    new

  3. Studio opens a new blank project, below is  a quick reference of the different views you use to build a Mule project:

    blank+canvas

  4. Begin designing your project by dragging and dropping an HTTP Connector from the palette onto the canvas. Notice that Studio automatically wraps the connector with a flow, thus saving you the step of manually creating one.

    add+http

  5. Add a Set Payload Component to your flow, by dragging it next to the HTTP connector on the canvas.

    set+payload

  6. Click the Configuration XML tab (at the base of the canvas) to see your application represented in XML. Studio’s two-way editing functionality ensures that anything you add or change in the graphical interface is reflected in the XML config. (Use the tabs below to see both the graphical and XML representations of the application.)

    basic+basic+flow 

    xml+code

  7. Click the Message Flow tab to return to the graphical editor, then click the Save icon to save your project. 

Configuring the Project

Now that you’ve modeled a basic application in Studio, you can take the steps to configure each individual element. 

  1. Click the HTTP Connector on the canvas to open its Properties Editor (see image below).

    The HTTP Connector allows your Mule application to connect to Web resources through the HTTP or HTTPS protocol.

    The HTTP Connector needs to be given basic information before it can work. These fields are mandatory for this connector: Path, and in Connector Configuration, the configuration Name, Host, and Port. All the rest are optional.

    http+pelado

    Path is already populated by the default value, slash /, and you can accept the default values in Connector Configuration or change Host to localhost.

    On Connector Configuration you need to provide a reference to another element which you must create.

  2. Click the green plus sign (+) next to Connector Configuration to create a new Global Element to be referenced by the connector. A Global Element is a separate element that encapsulates some reusable configuration properties, it can be referenced by as many connectors as you want.

    add+global+element

  3. A new window opens with several fields to configure. Leave all the fields to their default values and click OK to close the window and create a global element.

    global+element+default

    Notice how, back in the connector, the Connector Configuration field is now populated with a reference to the element you just created. Also notice how the red warning marks have disappeared both from the properties editor and the representation for the connector on the canvas.

  4. Click the Set Payload Component on the canvas to open its Properties Editor in the console (see image below).

  5. The Set Payload Component simply sets the message payload to a value you define. Set the Value field to Hello World! or whatever other text string you prefer.

    set+payload+hello+world

  6. Once again, click the Configuration XML to view your changes in the XML config (see code below). Click the Save icon to save your changes.

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    <?xml version="1.0" encoding="UTF-8"?>
    
    <mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
        xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.6.2"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="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
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
    http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
    http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd">
    
        <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    
       <flow name="my_first_projectFlow">
            <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
            <set-payload doc:name="Set Payload" value="Hello World!"/>
        </flow>
    </mule>

Deploying the Project

Anypoint Studio comes bundled with its own embedded server, ideal for testing deployments as you code. You can deploy your application on the embedded server to see it working and perform any debugging activities before deploying to a production environment, such as an on-premises server or CloudHub.

  1. In the Package Explorer, right-click the project name, then select Run As > Mule Application.

    run+as

  2. Studio launches the application on the embedded server, displaying its actions in the console. When complete, the console message reads: Started app 'my_first_project'

    console1

Interacting with the Project

  1. Open your favorite Web browser. 

  2. Navigate to the URL of your application (this address is the result of the default settings of the HTTP Connector):

  3. The application accepts the request via its HTTP endpoint, then the set payload component sets the payload to "Hello World!", and finally the HTTP connector returns this payload as the response you see in your browser.

    hello+world

  4. In Studio, stop the application from running using the Terminate icon in the console:

    console2

See Also