Contact Us 1-800-596-4880

Integrating American Flights Processes

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.

Start by creating a basic integration for the American Flights example. This integration is a Mule application that provides some of the logic for processing requests from the American Flights API.

Before You Begin

Complete these procedures:

  • Designing the American Flights API Spec (all tasks from creating the API specification to publishing the specification to Exchange)

  • Installing a REST client such as Postman or Advanced REST Client.

Create a Mule Application

Start an integration application for the American Flights example.

  1. In the activity bar of the IDE, click the (Anypoint Code Builder) icon.

    MuleSoft icon in the VS Code Activity Bar
  2. From Quick Actions, click Develop an Integration:

    Develop an Integration link highlighted in the Getting started section
  3. Provide integration project properties to the Develop an Integration form:

    Create integration project from scratch.
    1. Under Project Name, type american-ws-anypoint-code-builder.

    2. Under Project Location, select Browse, and then select your home directory.

    3. Under Create, select Empty Project.

    4. Select Mule runtime and Java versions.

      You can select any of the supported Mule runtime and Java versions. The IDE saves your version settings to the project’s mule-artifact.json file. For information about version support and automated Mule patch updates, see Mule and Java version support. To set default Mule runtime and Java versions for the projects you create, see Version Settings for Mule, Java, and Connectors.

  4. Click Create Project.

    The IDE provides a notification if it is necessary to download the selected Mule runtime or Java version for the project. Mule runtime downloads to ${user.home}/AnypointCodeBuilder/runtimes, and the selected Java version downloads to ${user.home}/AnypointCodeBuilder/java.

  5. Proceed to Configure an HTTP Listener Operation and Set a Payload.

Configure an HTTP Listener Operation and Set a Payload

The listener is for triggering the flow, and Set Payload provides some test data for the integration:

  1. If the canvas and configuration XML for the project are not open, navigate to american-ws-anypoint-code-builder.xml from the Explorer.

    american-ws-anypoint-code-builder.xml file shown in visual representation of its 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 to getFlights, 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 getFlights.

    Automatically Generated Flow Element Renamed Flow Element
    <flow name="name1" >
    
    </flow>
    <flow name="getFlights" >
    
    </flow>
  4. Add the HTTP Listener component to your configuration XML:

    1. In the canvas, after your Flow component, click the (Add component) icon:

      Plus icon highlighted in the flow
    2. Search for and select Listener from the HTTP results:

      Listener component highlighted in the Add Component section

      The configuration XML file adds the XML for the HTTP Listener into the <flow/> element, for example:

      <flow name="getFlights" >
        <http:listener path="" config-ref="" doc:name="Listener" doc:id="ojzfry" />
      
      </flow>
  5. In the configuration XML, place your cursor before the opening <flow> tag, and type http.

  6. Select the built-in <http:listener-config/> snippet:

    http:listener-config highlighted in the configuration XML menu
    Snippet XML example:
    <http:listener-config name="HTTP_Listener_config" >
      <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>

    In the menu, the snippet is a partially configured Mule component that is represented by a two-dimensional box icon. Three-dimensional box icons are reserved for basic component XML that is not preconfigured. For information about code snippets, see Working with Code Snippets.

  7. In the configuration XML, configure the attributes for the HTTP Listener configuration <http:listener-config/>:

    <http:listener-config name="inbound-request" doc:name="Listener Config" doc:id="b5c62f-a84a3a">
      <http:listener-connection host="0.0.0.0" port="8081"/>
    </http:listener-config>

    In <http:listener-config/> and its child element <http:listener-connection/>, set the attributes to values provided in the example.

    Notice that the name attribute changes to inbound-request. The doc:id is randomly generated and does not require a change.

  8. Configure the attributes for the HTTP Listener configuration:

    • From the canvas

    • From the configuration XML

    Click the Listener operation to open its configuration panel, and set the HTTP Listener attributes to the following values:

    Configure the Listener operation through its configuration panel.
    1 Change the operation name to HTTP /flights.
    2 Select inbound-request from the configuration reference dropdown menu.
    3 Set the Path attribute to flights.

    In <http:listener/>, set the attributes to the values provided in the example.

    <flow name="getFlights">
        <http:listener path="flights" config-ref="inbound-request" doc:name="HTTP /flights" />
    </flow>
  9. From the canvas, add a Set Payload component after your HTTP Listener operation.

  10. Configure the Set Payload component attributes:

    • From the canvas

    • From the configuration XML

    Click the Set Payload component to open its configuration panel, and set the attributes to the following values:

    Configure the Set Payload component through its configuration panel.
    1 Change the component name to Set Response.
    2 Set the Value attribute to Flight info.

    In <set-payload/>, set the attributes to the values provided in the example.

    <http:listener-config name="inbound-request" doc:id="b5c62f-a84a3a">
        <http:listener-connection host="0.0.0.0" port="8081" />
    </http:listener-config>
    
    <flow name="getFlights" >
      <http:listener path="flights" config-ref="inbound-request" doc:name="HTTP /flights" doc:id="htprur" />
      (1)
      <set-payload value="Flight info" doc:name="Set Response" doc:id="e43e98-1a9a01"/>
    </flow>
    1 Set the value attribute to Flight info and the doc:name to Set Response.
  11. Before <http:listener-config/> in the configuration XML, click Test Connection to check the HTTP Listener connection.

    The UI provides status:

    • Verifying connection inbound-request indicates that the test is in progress.

    • Connection is valid indicates a successful connection.

    • Invalid Connection Got status code: 500 when trying to resolve a Mule Runtime operation indicates a connection error.

      A common code 500 error is port 8081: Address already in use. For port conflicts, configure a different port, such as 8082, and retest the connection.

  12. After receiving the Connection is valid message, proceed to Run Your Application in Debug Mode.

Run Your Application in Debug Mode

  1. Open the Run and Debug panel.

    Show me how
    • Click the (Run and Debug) icon in the activity bar.

    • Use the keyboard shortcuts:

      • Mac: Cmd+Shift+d

      • Windows: Ctrl+Shift+d

    • In the desktop IDE, select View > Run.

    • In the cloud IDE, click the (menu) icon, and select View > Run.

  2. Click the (Start Debugging (F5)) icon for Debug Mule Application:

    Run the debugger.

    Anypoint Code Builder uses Maven to build and deploy your application to its embedded Mule runtime engine.

    Note that using Run > Start without Debugging produces an error.

  3. From your IDE, open the Terminal window in the console:

    • In the desktop IDE, select View > Terminal.

    • In the cloud IDE, click the (menu) icon, and select Terminal > New Terminal.

    • For either IDE: Press Ctrl and then press the backtick key (`).

      *******************************************************************************
      * - -  + APPLICATION + - -   *   - - + DOMAIN + - -      * - - + STATUS + - - *
      *******************************************************************************
      * american-ws-anypoint-code-builder-1.0.0-SNAPS * default   * DEPLOYED        *
      *******************************************************************************
  4. Proceed to Test Your Application.

Test Your Application

Use the IDE’s terminal to trigger the flow.

  1. Submit a curl command from the terminal with the URL to the /flights endpoint to trigger the flow:

    curl http://0.0.0.0:8081/flights

    For guidance, see Trigger a Flow.

  2. In your REST client or browser, check for the response Flight info.

    If you do not receive this response or if you receive a connection error, review your XML configuration, make sure your application is deployed, and recheck your HTTP Listener connection.

  3. After receiving the Flight info response, proceed to Stop Your Application.

Stop Your Application

  1. In Anypoint Code Builder, select the stop icon from the toolbar:

    Stop icon highlighted in the toolbar
  2. Proceed to Connecting to a Database from the App to import a connector from Exchange, and connect to an existing database that returns data about flights for the American Flights API.