Contact Us 1-800-596-4880

Debugging the American Flights App

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.

Debug your American Flights interface and implementation.

Add Components

To facilitate debugging, add Set Variable and Logger components to your American Flights implementation:

  1. Open the implementation file (implementation.xml).

  2. After the Database Select operation (<db:select/>) named Query Flights, add a Set Variable component.

  3. In the configuration XML, provide this <set-variable/> configuration:

    <set-variable value="#[payload]"
         doc:name="Set variable Payload"
         variableName="databasePayload" />
  4. After the Set Variable component, add a Logger component with this configuration:

    <logger doc:name="Log Payload" message="#[
        %dw 2.0
        output application/json
        ---
        payload]" />
    Click for the complete implementation XML example.
    <flow name="getFlights">
        <logger doc:name="Logger" doc:id="ahcnzm" />
        <db:select doc:name="Query Flights" doc:id="pvuqsc" config-ref="Database_Config" >
            <db:sql>
                <![CDATA[Select * FROM american]]>
            </db:sql>
        </db:select>
    
        <set-variable value="#[payload]" doc:name="Set variable Payload"
             variableName="databasePayload" doc:id="vtptsr" />  (1)
    
        <ee:transform doc:name="Transform Message" doc:id="uniqueId" >
            <ee:message >
                <ee:set-payload >
                    <![CDATA[
                    %dw 2.0
                    output application/json
                    ---
                    payload map ( payload01 , indexOfPayload01 ) -> {
                      ID: payload01.ID,
                      code: (payload01.code1 default "") ++ (payload01.code2 default ""),
                      price: payload01.price default 0,
                      departureDate: payload01.takeOffDate as String default "",
                      origin: payload01.fromAirport default "",
                      destination: payload01.toAirport default "",
                      emptySeats: payload01.seatsAvailable default 0,
                      plane: {
                        "type": payload01.planeType default "",
                        totalSeats: payload01.totalSeats default 0
                      }
                    }
                    ]]>
                </ee:set-payload>
            </ee:message>
        </ee:transform>
    
    <logger doc:name="Log Payload" message="#[
        %dw 2.0
        output application/json
        ---
        payload]" /> (1)
    
    </flow>
    1 Set Variable component
    2 Logger component
  5. Proceed to Add Breakpoints.

    Learn to set up breakpoints to pause execution of your app.

Add Breakpoints

Add breakpoints to your American Flights project:

  1. Open the interface (interface.xml) for your American Flights project.

  2. Select the Run and Debug icon in the activity bar:

    run and debug
  3. In implementation (interface.xml), add a breakpoint to the line that contains the <flow-ref/> component:

    add breakpoint

    Alternatively, use F9 to add a breakpoint to the line.

  4. Open the implementation file (implementation.xml) for your American Flights project, and add breakpoints to the <db:select/> and <set-variable/> components.

  5. Notice that all the breakpoints are now listed in the Breakpoints panel:

    breakpoints panel
  6. Proceed to Start a Debugging Session.

    Run a debugging session, and inspect the message and variables at different points during your app’s execution.

Start a Debugging Session

  1. From the Run and Debug menu, click Debug Mule Application:

    start debugging

    The IDE packages the app and opens a new terminal that deploys the app to the embedded Mule runtime engine:

    packaged and running terminals
  2. Proceed to Test Your American Flights App.

Test Your American Flights App

After starting your debugging session:

  1. 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 (`).

  2. In the terminal, use a curl command to make a GET request to the listener in the interface (interface.xml) instead of the implementation:

    > curl http://localhost:8081/api/flights

    Notice the /api/flight in the URI for the listener in the interface. For more information about this step, see Trigger a flow.

  3. In your American Flights project, notice that the execution of the app stops at your first breakpoint:

    Stopping the flow at a breakpoint

    The breakpoint is located in you interface file (interface.xml).

  4. In your debug toolbar, click the Step Over button to continue execution to the next breakpoint, at the <db:select/> element in implementation.xml.

  5. In the Run and Debug sidebar, notice that the Variables panel provides information about the Mule event at the breakpoint:

    Breakpoint in the configuration XML file where execution stops
  6. Click the Step Over button on your debug toolbar to continue execution to your next breakpoint, at the <set-variable/> element.

  7. In the Variables panel, navigate to Mule Message > Payload, and notice that the database response is an array of flight data:

    Array of flight data in the payload
  8. Proceed to Add a Watch Expression.

Add a Watch Expression

  1. From the Run and Debug sidebar, open the Watch panel.

  2. Click the + icon in the panel, and add the expression payload.^mediaType:

    debug add expression
  3. Click the Step Over button until your execution moves to the Transform Message component (<ee:transform/>).

  4. Notice that the payload is application/java:

    tut debug mediatype java

  5. Continue clicking the Step Over button until you reach the Logger component (<logger>).

  6. Notice that your payload transforms to application/json:

    tut debug mediatype json
  7. Click the Continue button in the debug toolbar, and notice that the app returns the response from the database to your REST client or browser.

    Click for the complete implementation XML example.
    [
        {
            "ID": 1,
            "code": "rree0001",
            "price": 541,
            "departureDate": "2016-01-20T00:00:00",
            "origin": "MUA",
            "destination": "LAX",
            "emptySeats": 0,
            "plane": {
                "type": "Boeing 787",
                "totalSeats": 200
            }
        },
        {
            "ID": 2,
            "code": "eefd0123",
            "price": 300,
            "departureDate": "2016-01-25T00:00:00",
            "origin": "MUA",
            "destination": "CLE",
            "emptySeats": 7,
            "plane": {
                "type": "Boeing 747",
                "totalSeats": 345
            }
        },
        {
            "ID": 3,
            "code": "ffee0192",
            "price": 300,
            "departureDate": "2016-01-20T00:00:00",
            "origin": "MUA",
            "destination": "LAX",
            "emptySeats": 0,
            "plane": {
                "type": "Boeing 777",
                "totalSeats": 300
            }
        },
        {
            "ID": 4,
            "code": "rree1000",
            "price": 200,
            "departureDate": "2016-01-20T00:00:00",
            "origin": "MUA",
            "destination": "CLE",
            "emptySeats": 5,
            "plane": {
                "type": "Boeing 737",
                "totalSeats": 150
            }
        },
        {
            "ID": 5,
            "code": "rree1093",
            "price": 142,
            "departureDate": "2016-02-11T00:00:00",
            "origin": "MUA",
            "destination": "SFO",
            "emptySeats": 1,
            "plane": {
                "type": "Boeing 737",
                "totalSeats": 150
            }
        },
        {
            "ID": 6,
            "code": "ffee1112",
            "price": 954,
            "departureDate": "2016-01-20T00:00:00",
            "origin": "MUA",
            "destination": "CLE",
            "emptySeats": 100,
            "plane": {
                "type": "Boeing 787",
                "totalSeats": 200
            }
        },
        {
            "ID": 7,
            "code": "eefd1994",
            "price": 676,
            "departureDate": "2016-01-01T00:00:00",
            "origin": "MUA",
            "destination": "SFO",
            "emptySeats": 0,
            "plane": {
                "type": "Boeing 777",
                "totalSeats": 300
            }
        },
        {
            "ID": 8,
            "code": "ffee2000",
            "price": 300,
            "departureDate": "2016-02-20T00:00:00",
            "origin": "MUA",
            "destination": "SFO",
            "emptySeats": 30,
            "plane": {
                "type": "Boeing 737",
                "totalSeats": 150
            }
        },
        {
            "ID": 9,
            "code": "eefd3000",
            "price": 900,
            "departureDate": "2016-02-01T00:00:00",
            "origin": "MUA",
            "destination": "SFO",
            "emptySeats": 0,
            "plane": {
                "type": "Boeing 737",
                "totalSeats": 150
            }
        },
        {
            "ID": 10,
            "code": "eefd4511",
            "price": 900,
            "departureDate": "2016-01-15T00:00:00",
            "origin": "MUA",
            "destination": "LAX",
            "emptySeats": 100,
            "plane": {
                "type": "Boeing 777",
                "totalSeats": 300
            }
        },
        {
            "ID": 11,
            "code": "rree4567",
            "price": 456,
            "departureDate": "2016-01-20T00:00:00",
            "origin": "MUA",
            "destination": "SFO",
            "emptySeats": 100,
            "plane": {
                "type": "Boeing 737",
                "totalSeats": 150
            }
        }
    ]
  8. Proceed to Stop the Debugging Session.

Stop the Debugging Session

To stop your debugging session:

  1. Click the Stop button on your debug toolbar:

    Stopping a debugging session from the debug toolbar
  2. Proceed to Deploying the American Flights App.