Contact Us 1-800-596-4880

Adding a Component to Your Project

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Open Beta Release: The cloud IDE is in open beta. Any use of Anypoint Code Builder in its beta state is subject to the applicable beta services terms and conditions, available from the IDE.

The following example illustrates basic configurations for adding components to your project from the canvas, and the configuration XML. The example assumes you are beginning with an empty integration project.

  1. {open-config-xml}, such as my-project-name.xml.

    Canvas showing visual representation of Mule flow and the Mule configuration file
    1 The canvas provides space for a visual representation of your Mule flows or subflows.
    2 The configuration XML editor displays the configuration file for your Mule application.
  2. Select Build a Flow from the canvas to create an empty flow within a Mule integration application.

  3. Change the default name of the flow from the canvas or from the configuration XML.

    • From the canvas

    • From the configuration XML

    Click Flow name1 to open the configuration panel for the Flow component, change the flow name, and click the check mark to set the new name.

    Change name of flow through canvas.

    Replace the default name of the flow (name1) with your flow name, such as getFlights, for example:

    <flow name="my-flow" >
    
    </flow>
  4. Add a component to your project from the canvas.

    For example, add the HTTP Listener component:

    1. In the canvas, click the (Add component) icon.

    2. In the Add Component panel, search for and select Listener from the HTTP results:

      Listener component highlighted in the Add Component section

      The configuration XML file now includes the XML for the HTTP Listener within the <flow/> element, for example:

      <flow name="getFlights" >
        <http:listener path="mypath" config-ref="config-ref" doc:name="Listener" doc:id="rrjiqa" />
      
      </flow>
  5. Add another component, this time using the XML configuration menu.

    For example, add the <http:listener-config/> component from a snippet.

    For more information about snippets, see Working with Code Snippets.

    1. In the configuration XML, place your cursor before the opening <flow> tag, and type http.

      Ensure that the cursor is not inside the <flow/> element.

    2. Type http, and select the http:listener-config snippet:

      http:listener-config snippet highlighted in the configuration XML menu

      The snippet adds the following code:

      <http:listener-config name="HTTP_Listener_config" >
        <http:listener-connection host="0.0.0.0" port="8081" />
      </http:listener-config>
    3. Notice that the Listener component in the canvas now displays an error:

      Listener error in the canvas
    4. To determine where the error is, select the processor in the canvas.

      Anypoint Code Builder highlights its location within the configuration XML, and you can mouse over the issue for more information, for example:

      Selecting configuration reference from configuration panel
    5. To fix the error, change the value of the name attribute in http:listener-config to match the name of the config-ref value in your http:listener configuration:

      <http:listener-config name="config-ref" >
        <http:listener-connection host="0.0.0.0" port="8081" />
      </http:listener-config>

      The HTTP listener within your flow now references the HTTP listener configuration, a global connection configuration that resides outside of the flow. For more information about debugging, see Debugging Mule Applications.

  6. Add another component to your flow.

    For example, add a Set Payload component to your HTTP Listener operation:

    1. In the canvas, click the (Add component) icon.

    2. In the Add Component panel, search for and select Set payload from the Transformer results.

    3. In the canvas, click Set payload to open its configuration panel, and add a string value, DataWeave expression, Mule variable, or configuration property.

      • To add a string, type a value such as my value. For example:

        Adding string to Set Payload
      • To add a DataWeave expression or a Mule variable as a value, such as payload, click fx (located before the field), and provide the value, for example:

        Adding expression to Set Payload

        For more information about configuring DataWeave expressions, see Configuring DataWeave Expressions.

      • To add a configuration property as a value, type a value such as ${secure::mysensitiveprop}. For example:

        Adding configuration property to Set Payload

        For more information about configuration properties, see Defining and Securing Properties for a Mule Application.

Your configuration XML file now looks similar to the following:

<http:listener-config name="config-ref" >
  <http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>

<flow name="getFlights" >
  <http:listener path="path" config-ref="config-ref" doc:name="Listener" doc:id="rrjiqa" />
  <set-payload value="my value" doc:name="Set payload" doc:id="gecykt" />

</flow>