DEX401 WI25v1 en Exercise Guide (2)
DEX401 WI25v1 en Exercise Guide (2)
nypoint Platform
A
Development: Fundamentals
DEX401 | November 26, 2024
EXERCISE GUIDE
Anypoint Platform: Development Fundamentals (DEX401)
Table of Contents
able of Contents
T
2
Introducing the course 4
Walkthrough: Set up your computer for class 5
Module 1: Accessing and modifying Mule events 12
Walkthrough 1-1: View event data 13
Walkthrough 1-2: Debug a Mule application 23
Walkthrough 1-3: Track event data as it moves in and out of a Mule application 32
Walkthrough 1-4: Set request and response data 41
Walkthrough 1-5: Get and set event data using DataWeave expressions 47
Walkthrough 1-6: Set and get variables 59
Module 2: Structuring Mule applications 65
Walkthrough 2-1: Create and reference subflows and private flows 66
Walkthrough 2-2: Trigger flows using the VM connector 74
Walkthrough 2-3: Encapsulate global elements in a separate configuration file 86
Walkthrough 2-4: Use property placeholders in connectors 98
Walkthrough 2-5: Create a well-organized Mule project 104
Walkthrough 2-6: Manage metadata for a project 118
Module 3: Consuming web services 128
alkthrough 3-1: Consume a RESTful web service that has an API (and connector) in
W
Exchange 129
Walkthrough 3-2: Consume a RESTful web service 147
Walkthrough 3-3: Consume a SOAP web service 159
Walkthrough 3-4: Transform data from multiple services to a canonical format 175
Module 4: Controlling event flow 187
Walkthrough 4-1: Multicast an event 188
Walkthrough 4-2: Route events based on conditions 196
Walkthrough 4-3: Validate events 211
Module 5: Handling errors 220
Walkthrough 5-1: Explore default error handling 221
Walkthrough 5-2: Handle errors at the application level 232
Walkthrough 5-3: Handle specific types of errors 243
Walkthrough 5-4: Handle errors at the flow level 250
Walkthrough 5-5: Handle errors at the processor level 262
In this walkthrough, you make sure your computer is set up correctly, so you can complete
the class exercises. You will:
● Install Advanced REST client (if you did not already).
● Make sure you have a Salesforce developer account and an API security token.
1. Locate your course enrollment email and follow the instructions to download the
student files ZIP.
2. On your computer, locate the student files ZIP and expand it.
3. Open the two course snippets.txt files, one for each part of the course.
NOTE: Keep these files open. You will copy and pastetext from them during class.
4. Again, follow your course enrollment email to access the student manuals and
slides.
5. In your computer's file browser, navigate to where you installed Anypoint Studio and
open it.
NOTE:If you do not have Anypoint Studio, you can download it from
https://www.mulesoft.com/lp/dl/studio.
Upon starting Anypoint Studio, users on Windows may get a popup asking to allow
Windows Defender Firewall access for OpenJDK; access should be allowed.
6. In the Workspace Launcher dialog box, look at the location of the default
workspace; change the workspace location if you want.
NOTE:If you cannot successfully start Anypoint Studio,make sure that you have enough
available memory (at least 8GB available) to run Anypoint Studio.
8. If you get a new features page, click theContinue to Studiobutton to close it.
9. If you get an Updates Available popup in the lower-right corner of the application,
click it and install the available updates.
NOTE:If you do not have Advanced REST Client (oranother REST API client) installed,
download it now from https://install.advancedrestclient.com/and install it.
11.Leave Advanced REST Client open; you will use it throughout class.
NOTE:If you do not have an account, sign up for afree, 30-day trial account now. Also, if
you get prompted here or in other parts of the course to enable multi-factor authentication,
select Not Now.
13.Click the menu button located in the upper left in the main menu bar.
15.In the left-side navigation, click the Runtime Manager link under Subscription.
16.Check your subscription level and if it is a trial account, make sure it is not expired.
NOTE:If your trial is expired or will expire duringclass, sign out and then sign up for a new
trial account now.
17.In the same or another web browser tab, navigate tohttp://salesforce.comand log
in to your Salesforce org.
NOTE:If you did not sign up for a free developeraccount yet, go to
http://developer.salesforce.com/and sign up for onenow. You will want to use a free
developer account and not your company account (if you already have one) for class. You
will use the API to add new fictitious accounts to it and will probably not want to add those
to your real data.
18.In Salesforce, click your avatar at the top of the screen and selectSettings.
20.If you did not already request a security token, click theReset Security Token
button.
NOTE:A security token will be sent to your email in a few minutes. You will need this token
to make API calls to Salesforce from your Mule applications.
In this walkthrough, you create a new project to use in the next two modules to learn about
Mule events and Mule applications. You will:
● Create a new Mule project with an HTTP Listener and set the event payload.
● Use a Logger to view event data in the Anypoint Studio console.
7. In the Global Element Properties dialog box, verify the host value is set to0.0.0.0
and the port value to8081.
8. ClickOK.
9. In the Listener properties view, set the path to/hello.
14.Drag aSet Payloadtransformer from the Favoritessection of the Mule Palette into
the process section of the flow.
15.In the Set Payload properties view, set the display name toHello.
16.Switch the value to literal mode and set its value toHello.
Add a Logger
17.Drag a Logger component from the Mule Palette and drop it at the end of the flow.
28.Return toAdvanced REST Clientand click the buttonto create a new tab.
NOTE:You are adding a new tab so that you can keepthe request to the American API you
created in the Getting Started with Anypoint Platform course saved in another tab for later
use.
29.In the new tab, make a GET request tohttp://localhost:8081/hello; you should see
Hellodisplayed.
33.Return to Advanced REST Client and add a query parameter with a key offnameand
a value ofmax.
35.ClickSend.
In this walkthrough, you debug and step through the code in a Mule application. You will:
● Add a breakpoint, debug an application, and step through the code.
● Pass query parameters to a request and locate them in the Mule Debugger.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. In the main menu bar, selectRun > Debug Configurations.
3. Selectapdev-examplesin the left menu bar under MuleApplications; you should
see that the apdev-examples project is selected to launch.
4. Select theMule Debugtab; you should see the debuggerport is set to 6666 for the
project.
NOTE:If you know you have another program using port6666 like McAfee on Windows,
change this to a different value. Otherwise, you can test the Debugger first and come back
and change the value here later if there is a conflict.
5. ClickClose.
Add a breakpoint
NOTE:You can also select Run > Debug or click theDebug button in the main menu bar.
8. If you get a Confirm Perspective Switch dialog box, selectRemember my decision
and clickYes.
9. Look at the console and wait until the application starts.
Use Resume to step to the next breakpoint and then the end of the
application
21.In the Mule Debugger, click theResumebutton; youshould step to the Logger.
22.Click theResumebutton again; you should step throughthe rest of the application.
24.Do not step through the application and wait (90 seconds by default) for the request
to timeout.
25.In the Advanced REST Client main menu, selectFilethenSettingsto navigate to the
application settings.
NOTE:Depending on your platform, accessing the applicationsettings may differ such as
AdvancedRestClient then Preferences.
26.In the application settings, locate theRequest timeoutsetting and click the arrow
next to it.
29.In the main screen, verify the tab with your last failed request is selected.
Switch perspectives
In this walkthrough, you call an external resource, which for simplicity is another HTTP
Listener in the same application, so that you can watch event data as it moves in and out of
a Mule application. You will:
● Make an HTTP request from the first flow to the new HTTP Listener.
NOTE:You are making an HTTP request from one flowto another in this exercise only so
you can watch the value of event data as it moves in and out of a Mule application. You will
learn how to pass events between flows within and between Mule applications in the next
module.
Starting file
If you did not complete walkthrough 1-1, you can get a starting file h
ere. This file is also
located in the solutions folder of the student files ZIP located in the Course Resources.
2. Drag an HTTP Listener from the Mule Palette and drop it in the canvas beneath the
first flow.
4. In the Listener view, ensure the connector configuration is set to the existing
HTTP_Listener_config.
8. In the Set Payload properties view, set the display name toGoodbyeand then use
literal mode to set the value toGoodbye.
9. From the Mule Palette, drag anHTTP Requestto thecanvas and drop it before the
Logger in helloFlow.
10.In the Request properties view, set the display name toGET /goodbye.
13.In the HTTP Request configuration dialog box, set the host tolocalhostand the port
to8081and clickOK.
16.In the properties view for the GET /goodbye HTTP Request, click theResponsetab.
NOTE:This is being set only for debugging purposesso that the HTTP Request does not
timeout when you are stepping through the application and examining data in the Mule
Debugger.
21.Look at the values of the payload and the attributes, including the queryParams.
22.Step intogoodbyeFlow.
24.Step through the flow until the event returns to the Logger in helloFlow.
27.Return to Advanced REST Client and view the return data and the http status code.
28.Select Headers from the options menu above the http status code.
29.Look at the response headers; you should see content-type, content-length, and date
headers.
In this walkthrough, you set response and request data for HTTP Listener and HTTP Request
operations. You will:
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
4. In the Response section, locate the expression that sets the response body by
default to the value of the payload.
5. In the Headers section for the response, click theAddbutton.
7. Locate the status code field and leave it blank so the default value200is returned.
12.In Advanced REST Client, locate the status code and your new reason phrase on the
Raw or Response tab.
13.On the Headers tab, review the response headers; you should now see the new
name header.
16.In the GET /goodbye properties view, locate the Request section on the General tab.
17.On the Body tab, locate the expression that sets the request body by default to the
value of the payload.
Debug and verify that the query parameter is sent with the request
In this walkthrough, you get and set event data using DataWeave expressions. You will:
● Use expressions to set a response header and a request query parameter.
● In expressions, reference values for the event payload and attributes.
● Use the DataWeave upper() function, the concatenation, as, and default operators.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. Navigate to the properties view for the Goodbye Set Payload transformer in
goodbyeFlow.
#['Goodbye']
5. In Advanced REST Client, send the same request; you should get the same result of
Goodbye as before.
6. In Anypoint Studio, return to the Goodbye Set Payload properties view.
7. Inside the brackets and before the string, type the wordupand pressCtrl+Spacebar.
#[upper('Goodbye')]
11.In Advanced REST Client, send the same request; the return string should now be in
upper case.
18.Return to the console in Anypoint Studio; you should see GOODBYE displayed for
the second Logger instead of the entire event object.
20.Switch the message field to literal mode then change the value to display the string
Message in front of the payload.
Message: #[payload]
23.Return to the console in Anypoint Studio; you should see the new string displayed.
25.Switch the message field to expression mode then change its value so the string is
part of the evaluated expression and use the concatenation operator.
29.Return to the console in Anypoint Studio; you should see the same string displayed
on a new line.
32.Switch the message field to expression mode then type the wordatand press
Ctrl+Spacebar; you should see auto-completion insertthe attributes keyword.
#[attributes.queryParams]
36.Return to the Anypoint Studio console; you should see an object displayed by the
first Logger.
37.Modify the message for the Logger in goodbyeFlow to display the value of the query
parameter.
#[attributes.queryParams.fullName]
40.Return to the console; you should now see the value of the parameter displayed.
41.Navigate to the properties view for the Goodbye Set Payload in goodbyeFlow.
42.Use the concatenation operator to also display the value of the query parameter
separated by a space.
44.Add the as operator to display the value of the query parameter as a string.
NOTE:This step coerces a null value to a String,to avoid UI errors. The recommended way
to handle null values is by using a default value, which is explained later in this walkthrough.
46.In Advanced REST Client, send the same request; you should now also see the name
displayed.
47.Return to the Anypoint Studio and navigate to the properties view for the GET
/goodbye HTTP Request in helloFlow.
51.In Advanced REST Client, send the same request; you should now see the name of
the fname query parameter displayed.
53.Return to the Anypoint Studio and navigate to the properties view for the Goodbye
Set Payload in goodbyeFlow.
54.Removeas String.
57.In Advanced REST Client, send the same request; you should now see the default
value Maxine displayed.
58.Return to the Anypoint Studio and navigate to the properties view for the GET /hello
HTTP Listener.
59.Select theResponsestab.
attributes.queryParams.fname
62.In Advanced REST Client, add anfnamequery parameterand set it equal to max or
some other value and send the request.
63.Look at the response headers; you should no longer see a name header.
Debug and verify that the query parameter is sent with the request
67.Return to the Mule Debugger and look at the attributes and query parameters; you
should see the fname query parameter.
68.Step into goodbyeFlow and look at the attributes and query parameters; you should
see the fullName query parameter.
69.Step back to helloFlow and look at the value of the attributes; you should not see
any query parameters.
In this walkthrough, you create variables associated with an event. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Add the Set Variable transformer to the Favorites section of the Mule
Palette
3. Locate the Set Variable transformer and right-click it and selectAdd to favorites.
Create a variable
4. Drag theSet Variabletransformer from the Favoritessection of the Mule Palette and
drop it after the GET /hello HTTP Listener in helloFlow.
5. In the Set Variable properties view, set the display name and name to firstName.
7. Return to the properties view for the GET /hello HTTP Listener in helloFlow.
9. Change the name header value fromattributes.queryParams.fnameto the value of
thefirstNamevariable.
vars.firstName
12.In the Mule Debugger, locate and expand the newVariablessection; you should see
your firstName variable.
14.Step back tohelloFlow; you should see the Variables section again with your
firstName variable.
16.Return to Advanced REST Client; you should see the header with the value of the
query parameter.
17.Change the value of the query parameter and send another request.
18.In the Mule Debugger, click theResumebutton untilyou step through the
application.
19.Return to Advanced REST Client; you should see the new query parameter value
returned in both the body and the header.
● Specify application properties in a separate properties file and use them in the
application.
● Describe the purpose of each file and folder in a Mule project.
In this walkthrough, you continue to work with apdev-examples.xml. You will:
● Explore event data persistence through subflows and private flows.
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Collapse a flow
Create a subflow
4. Drag aSub Flowscope from the Mule Palette and dropit between the existing flows
in the canvas.
Reference a subflow
7. Drag aFlow Referencecomponent from the Mule Paletteand drop it into helloFlow
between the GET /hello HTTP Listener and the GET /goodbye HTTP Request.
8. In the Flow Reference properties view, set the flow name to
apdev-examplesSub_Flowand the display name tosubflow.
10.In the subflow Flow Reference properties view, notice that value in the Flow name
field has been automatically changed to subflow.
13.In the Extract Flow dialog box, set the flow name toprivateFlow.
16.Look at the new Flow Reference properties view; set the display name to
privateFlow.
20.In the Mule Debugger, step through the application, watching as you step into and
out of the flows and subflows.
23.In the Mule Debugger, step through the application again, this time watching the
values of the attributes, payload, and variables in each of the flows.
In this walkthrough, you trigger flows to run both synchronously and asynchronously. You
will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. Select theVM connectorin the right side of the Mule Palette and drag and drop it
into the left side.
4. In the Package Explorer, locate theJARfile for theVM connector.
7. Select thePublish consumeoperation and drag and drop it before theLoggerin
helloFlow.
8. In the Publish consume properties view, change the display name toVM goodbye.
10.In the queues dropdown menu, selectEdit inlinethen click theAdd Queuebutton.
11.In the Queue dialog box, set the queue name togoodbyeand clickFinish.
13.In the VM goodbye Publish consume properties view, set the queue name to
goodbye.
NOTE:If you do not see the queue name in the dropdownmenu, click the refresh icon for it
to be populated and then set it.
Add a VM Listener
16.Locate theListeneroperation for the VM connector in the right side of the Mule
Palette and drag and drop it in the source section of goodbyeFlow.
17.In the VM Listener properties view, change the display name toVM goodbye.
21.In the Mule Debugger, step through the application to theVM Publish consume.
23.Step intogoodbyeFlow.
28.Switch perspectives.
30.Drag aVM Publish operationfrom the Mule Paletteand drop it before the Logger.
31.In the Publish properties view, set the display name toVM goodbye.
35.In the Mule Debugger, step through the application to the VM Publish operation.
40.Return to Advanced REST Client; you should see a response of Hello – not
GOODBYE.
In this walkthrough, you refactor your apdev-examples project. You will:
● Create a new configuration file with an endpoint that uses an existing global
element.
● Create a new global element in global.xml and configure a new connector to use it.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. In the Package Explorer, right-click the project and selectNew > Mule Configuration
File.
3. In the dialog box, set the name to accounts and clickFinish.
4. Drag an HTTP Listener to the canvas from the Mule Palette.
5. In the Listener properties view, set the display name toGET /sfdc.
9. In the Transform Message properties view, change the output type to
application/json and set the expression to payload.
11.Switch to the Global Elements view; you should not see any global elements.
14.Place some empty lines between the start and end mule tags.
Move the existing global elements to the new global configuration file
15.Return toapdev-examples.xml.
18.Select and cut the three configuration elements defined before the flows.
NOTE:If you delete the global elements from the GlobalElements view instead, the
config-ref values are also removed from the connector operations and you need to re-add
them.
20.Return toglobal.xml.
21.Paste the global elements you cut to the clipboard between the start and end mule
tags.
22.Switch to the Global Elements view; you should see the three configurations.
23.Return toapdev-examples.xml.
26.In the dialog box, ensure all the resources are selected and click Save 3 of 3.
27.In Advanced REST Client, send the same request; you should still get a response of
Hello.
28.Return to apdev-examples.xml.
30.Select theSalesforceconnector in the right sideof the Mule Palette and drag and
drop it into the left side.
32.Return to global.xml.
34.In the Choose Global Type dialog box, selectConnector Configuration >Salesforce
Configand clickOK.
35.In the Global Element Properties dialog box, locate the Connection section and
enter yourSalesforce username,password, andsecuritytoken.
38.In the Global Element Properties dialog box, clickOK; you should now see the new
configuration in global.xml.
41.Locate the Query operation in the right side of the Mule Palette and drag and drop it
before the Transform Message component in getSFDCaccounts.
42.In the Query properties view, set the display name toAccount.
45.Return to Anypoint Studio and paste the query in the Salesforce query section of the
Query properties view.
In this walkthrough, you introduce properties into your API implementation. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
6. In the Choose Global Type dialog box, selectGlobalConfigurations > Configuration
propertiesand clickOK.
7. In the Global Element Properties dialog box, set the file toconfig.yamland clickOK.
10.Return toglobal.xml.
13.ClickOK.
16.Return to config.yaml.
18.Add properties for password and token and set them to your values.
20.Return toglobal.xml.
NOTE:If your connection fails, click OK and thengo back and make sure you do not have
any syntax errors in config.yaml and that you saved the file.
24.ClickOK.
27.In Advanced REST Client, make the same request tohttp://localhost:8081/sfdc and
confirm you still get data.
In this walkthrough, you create a new project for the Mule United Airlines (MUA) flights
application that you will build during the course and then review and organize its files and
folders. You will:
● Create an application properties file and a global configuration file for the project.
● Add Java files and test resource files to the project.
● Create and examine the contents of a deployable archive for the project.
2. In Design Center, select theCreate +button and selectImport from File.
3. In the Import from file dialog box, set the project name toMUA Flights APIthen
select theChoose filebutton.
4. Browse to your student files and select theMUA Flights API.zipfile located in the
resources folder.
5. ClickOpen.
6. Back in the Import from file dialog box, ensureAPIspecificationis selected with
REST APIin its dropdown menu.
7. ClickImport.
8. Explore the API; be sure to look at what resources are defined, the name of the
query parameters, and the structure of the Flight data type.
11.In the New Mule Project dialog box, set the project name toapdev-flights-ws.
14.Sign into Anypoint Platform if prompted, then, in the Browse Design Center for APIs
dialog box, selectMUA Flights APIand clickOK.
20.Renamemua-flights-api.xmltointerface.xml.
31.In the Create New File dialog box, set the file name toconfig.yamland clickFinish.
36.Create a new Configuration properties element with the file set toconfig.yaml.
37.Create a new HTTP Listener config element with the host set to0.0.0.0and the port
set to thehttp.portproperty.
45.In the Package Explorer, right-click the src/main/java folder and selectNew >
Package.
46.In the New Java Package dialog box, set the name tocom.mulesoft.trainingand
clickFinish.
47.In your computer's file browser, locate theFlight.javafile in the resources folder of
the student files.
48.Drag the Flight.java file into the new com.mulesoft.training package in the
src/main/java folder in the apdev-flights-ws project.
49.In the File Operation dialog box, ensureCopy filesis selected and clickOK.
50.Open theFlight.javafile.
55.Select the three flights and one united-flights files (JSON and XML) and drag them
into the src/test/resources folder in the apdev-flights-ws project.
56.In the File Operation dialog box, ensureCopy filesis selected and clickOK.
57.In Anypoint Studio, save all files, and then right-click the project and selectExport.
58.In the Export dialog box, select Mule > Anypoint Studio Project to Mule Deployable
Archive and click Next.
59.In the Export Mule Project dialog box, set the JAR file to a location that you can find
and clickFinish.
In this walkthrough, you define metadata for the apdev-flights-ws project. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
6. In the Manage Metadata Types dialog box, select theamerican_flights_json type.
7. ClickOK.
15.In the Create new type dialog box, set the type id toflights_json.
16.ClickCreate type.
17.In the Manage Metadata Types dialog box, set the first type toJSON.
22.Locateapplication-types.xmlin src/main/resources.
26.In the Create new type dialog box, set the type id toflight_jsonand clickCreate
type.
27.In the Manage Metadata Types dialog box, set the first type toJSON.
30.In the Create new type dialog box, set the type id toflights_xmland clickCreate
type.
32.In the Manage Metadata Types dialog box, set the first type toXML.
35.In the Create new type dialog box, set the type id toFlight_pojoand clickCreate
type.
37.In the Manage Metadata Types dialog box, set the first type toObject.
40.In the dialog box that opens, typefliin the Selectentries field and then in the list of
classes that appears, selectFlight – com.mulesoft.training.
41.ClickOK.
44.Return toapplication-types.xml.
● Consume web services that have an API (and connector) in Exchange.
● Pass parameters to SOAP web services using the Transform Message component.
In this walkthrough, you consume a pre-built American flights RESTful web service that has
an API and a connector in Exchange. You will:
● Create a new flow to call the American RESTful web service.
● Configure and use a REST connector to make a call to a web service.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
NOTE: If you still have access to the American FlightsAPI you created in the Getting Started
with Anypoint Platform course, you are encouraged to review and use that API instead in
the steps that follow. If you do not have access to port 3306, using your API (or, if necessary,
a new API created using the Derby Database connector option detailed in Walkthrough 4-2
of the Getting Started course) is required. In order to use your API, you'll need its client
credentials and endpoint URL.
4. Click theDownloaddropdown menu button; you shouldsee that REST Connect has
created connectors for the API in Exchange.
5. Return to the coursesnippets.txtfile and copy thevalue for the Training: American
Flights API client_id.
6. Return to Advanced REST Client, select the first tab, and add a header called
client_id.
9. Return to the coursesnippets.txtfile and copy the value for the Training: America
Flights API web service URL.
10.Return to Advanced REST Client and send a GET request to the value you copied; you
should see JSON data for the American flights as a response.
NOTE:The client credentials in the snippets file may be different than what is shown here;
the values in the snippets file differ for instructor-led and self-study training classes.
12.Return toimplementation.xml.
15.In the Listener properties view, set the display name toGET /american.
20.In the Add Dependencies to Project dialog box, enteramericanin the search field.
22.ClickFinish.
25.Select theGet flightsoperation on the right sideof the Mule Palette and drag and
drop it in the process section of the flow.
26.Select theGet flightsoperation in the canvas andin its properties view, see that you
need to create a new configuration and enter aclient_idand client_secret.
27.Openglobal.xml.
29.In the Choose Global Type dialog box, selectConnectorConfiguration > American
Flights APIConfig and clickOK.
30.In the Global Element Properties dialog box, set each field to a corresponding
property placeholder (that you will define and set next):
31.ClickOK.
32.Return to the course snippets.txt file and copy the text for the American RESTful web
service properties.
34.Return to Advanced REST Client and copy the value for your client_id.
37.Return toimplementation.xml.
38.In the Get flights properties view, ensure the Connector configuration is set to
American_Flights_API_Config.
44.In the dialog box, ensure all the resources are selected and clickSave 3 of 3.
45.In Advanced REST Client, return to the tab with the localhost request.
47.Return tomua-flights-api.ramlinsrc/main/resources/api.
49.Locate the return type for the get method of the /flights resource.
51.Return toimplementation.xml.
52.Drag aSub Flowscope from the Mule Palette and dropit at the top of the canvas.
54.Drag aSet Variabletransformer from the Mule Palette and drop it in thesetCode
subflow.
55.In the Set Variable properties view, set the name and display name tocode.
56.Switch the value field to expression mode then set its value to a query parameter
calledcodeand give it a default value ofSFOifno query parameter is passed to the
flow.
57.Drag aFlow Referencecomponent from the Mule Paletteand drop it after theGET
/americanListenerin getAmericanFlights.
58.In the Flow Reference properties view, set the flow name and display name to
setCode.
59.In the Get flights properties view, switch the destination field to expression mode
then set its value to the variable containing the airport code.
vars.code
61.In Advanced REST Client, send the same request; this time you should only get
flights to SFO.
62.Add a query parameter calledcodeequal to LAX and make the request; you should
now only see flights to LAX.
NOTE:You will transform the data to the format specifiedby the mua-flights-api in a later
walkthrough.
In this walkthrough, you consume the United RESTful web service that does not have an API
in Exchange. You will:
● Create a new flow to call the United RESTful web service.
● Use the HTTP Request operation to call a RESTful web service.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. In Advanced REST Client, make a new tab and make a GET request to this URL.
5. Look at the destination values; you should see SFO, LAX, CLE, PDX, and PDF.
6. In the URL field, add the destination CLE as a URI parameter.
7. Send the request; you should now only see flights to CLE.
9. Drag out anHTTP Listenerfrom the Mule Palette and drop it at the bottom of the
canvas.
11.In the Listener properties view, set the display name toGET /united.
15.Drag out anHTTP Requestfrom the Mule Palette anddrop it into the process
section of getUnitedFlights.
16.In the Request properties view, set the display name toGet flights.
17.Return to thecourse snippets.txtfile and copy thetext for theTraining web service
properties.
NOTE: The Training web service properties you see may be different than what is shown
here; the values in the snippets file differ for instructor-led and self-study training classes.
21.ClickOK.
22.Return toimplementation.xml.
29.In Advanced REST Client, return to the tab with the localhost request.
31.Add a query parameter named code and set it to one of the destination airport code
values:http://localhost:8081/united?code=CLE; youshould still get flights to all
destinations.
33.Drag aFlow Referencecomponent from the Mule Paletteand drop it after the GET
/united Listener in getUnitedFlights.
34.In the Flow Reference properties view, set the flow name and display name to
setCode.
38.Click theAddbutton.
vars.code
42.In Advanced REST Client, make the same request; you should now only get flights to
CLE.
43.Remove the code parameter and make the request; you should now only get results
for SFO.
NOTE: You will transform the data to the format specified by the mua-flights-api in a later
walkthrough.
50.Click theEditbutton.
52.In the Create new type dialog box, set the type id tounited_flights_json.
53.ClickCreate type.
54.In the Select metadata type dialog box, set the first type toJSON.
57.Select united-flights-example.json and click Open; you should see the example data
for the metadata type.
58.ClickSelect.
In this walkthrough, you consume a Delta SOAP web service. You will:
● Create a new flow to call the Delta SOAP web service.
● Use a Web Service Consumer connector to consume a SOAP web service.
● Use the Transform Message component to pass arguments to a SOAP web service.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the coursesnippets.txtfile and copy theDelta SOAP web service WSDL.
2. In Advanced REST Client, return to the tab with themule-trainingrequest.
3. Paste the URL and send the GET request; you should see the web service WSDL
returned.
4. Browse the WSDL; you should find references to operations listAllFlights and
findFlight.
6. Drag out anotherHTTP Listenerfrom the Mule Paletteand drop it in the canvas after
the existing flows.
8. In the Listener properties view, set the display name toGET /delta.
12.Select the Web Service Consumer connector on the right side of the Mule Palette
and drag and drop it into the left side.
13.If you get a Select module version dialog box, select the latest version and clickAdd.
14.Return to the coursesnippets.txtfile and copy thetext for the Delta web service
properties.
15.Return toconfig.yamlin src/main/resources and paste the code at the end of the
file.
NOTE: The Delta web service properties you see maybe different than what is shown here;
the values in the snippets file differ for instructor-led and self-study training classes.
17.Return toglobal.xml.
18.ClickCreate.
19.In the Choose Global Type dialog box, selectConnector Configuration > Web
Service Consumer Config.
20.ClickOK.
21.In the Global Element Properties dialog box, change the name to
Delta_Web_Service_Consumer_Config.
23.ClickOK.
24.Return toimplementation.xml.
26.In the Consume properties view, change its display name toGet flights.
28.Click the operation dropdown menu; you should see the web service operations
listed.
29.Select thelistAllFlightsoperation.
32.In Advanced REST Client, return to the tab with the localhost request.
37.In the Transform Message properties view, change the output type to
application/jsonand set the expression topayload.
44.In the properties view for Get flights Consume operation, change the operation to
findFlight.
48.In Advanced REST Client, send the same request with the query parameter; you
should get a 500 Server Error with a message that the operation requires input
parameters.
51.In the Flow Reference properties view, set the flow name and display name to
setCode.
54.In the Pass code properties view, look at the input and output sections.
55.Drag the code variable in the input section to the destination element in the output
section.
57.In Advanced REST Client, make another request; you should now only see flights to
LAX.
In this walkthrough, you will transform the JSON returned from the American and United
web services and the SOAP returned from the Delta web service to the same format. You
will:
● Transform the results from RESTful and SOAP web service calls to a collection of
Flight objects.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Review Flight.java
Change the American flow to return Java Flight objects instead of
JSON
7. Change the name of the Transform Message component toJSON to [Flight].
8. In the Transform Message properties view, look at the input section; you should see
metadata already defined.
9. In the output section of the Transform Message properties view, click theDefine
metadatalink.
10.In the Select metadata type dialog box, select theuser-defined Flight_pojo.
12.ClickSelect; you should now see output metadata inthe output section of the
Transform Message properties view.
13.Map fields (except ID and totalSeats) by dragging them from the input section and
dropping them on the corresponding field in the output section.
15.In the generated DataWeave expression, change the airlineName value from null to
"American".
17.In Advanced REST Client, change the URL and make a request to
http://localhost:8081/american; you should see a representationof a collection of
Java objects.
23.In the Mule Debugger, step to theTransform Messagecomponent and examine the
payload.
Change the United airline flows to return Java Flight objects instead of
JSON
26.Return togetUnitedFlightsinimplementation.xml.
30.In the Transform Message properties view, look at the input section; you should see
metadata already defined.
31.In the output section of the Transform Message properties view, click theDefine
metadatalink.
32.In the Select metadata type dialog box, select theuser-defined Flight_pojo.
34.ClickSelect; you should now see output metadata in the output section of the
Transform Message properties view.
35.Map fields by dragging them from the input section and dropping them on the
corresponding field in the output section.
38.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/united.
40.Step to the Logger and look at the payload; it should be a collection of Flight objects.
42.Return togeDeltaFlightsinimplementation.xml.
45.Look at the input section in the SOAP to [Flight] Transform Message properties view;
you should see metadata already defined.
46.In the output section of the Transform Message properties view, click theDefine
metadatalink.
47.In the Select metadata type dialog box, select the user-definedFlight_pojo.
49.ClickSelect; you should now see output metadata inthe output section of the
Transform Message properties view.
50.Map the fields by dragging them from the input section and dropping them on the
corresponding field in the output section.
53.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/delta.
55.Step to the Logger and look at the payload; it should be a collection of Flight objects.
In this walkthrough, you create a flow that calls each of the three airline services and
combines the results. You will:
● Use a Scatter-Gather router to concurrently call all three flight services.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. From the Mule Palette, drag anHTTP Listenerand dropit at the top of the canvas.
4. In the Listener properties view, set the display name toGET /flights.
6. Set the path to /flights and the allowed methods toGET.
7. In the Core section of the Mule Palette, locate theFlow Controlelements.
8. Drag aScatter-Gatherflow control element from the Mule Palette and drop it in the
process section ofgetAllAirlineFlights.
10.In the first Flow Reference properties view, set the flow name and display name to
getAmericanFlights.
11.Set the flow name and display name of the second Flow Reference to
getUnitedFlights.
12.Set the flow name and display name of the third Flow Reference togetDeltaFlights.
14.In the Logger properties view, explore the input payload structure in the DataSense
Explorer.
18.In Advanced REST Client, change the URL to make a request to
http://localhost:8081/flights.
19.In the Mule Debugger, step through the application; you should step through each
of the airline flows.
20.Stop at the Logger after the Scatter-Gather and explore the payload.
23.Return to Advanced REST Client and review the response; you should get a 500
Server Error with a message that the object could not be serialized.
27.In the input section of the Transform Message properties view, review the payload
data structure.
28.In the expression section, use the DataWeave flatten function to flatten the
collection of objects into a single collection.
31.In the Mule Debugger, clickResumeuntil you are stoppedat the Logger at the end
of the Scatter-Gather; you should see the payload is now one ArrayList of Flights.
In this walkthrough, you create a flow to route events to either the American, United, Delta,
or get all airline flows based on the value of an airline query parameter. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. Locate the airline query parameter and its possible values.
5. Drag aFlowscope from the Mule Palette and drop itat the top of the canvas above
all the other flows.
8. Drag a Choice flow control element from the Mule Palette and drop it in the process
section ofgetFlights.
11.In the first Flow Reference properties view, set the flow name and display name to
getAmericanFlights.
12.Set the flow names and display names for the other two Flow References to
getUnitedFlightsandgetDeltaFlights.
13.For the Flow Reference in the default branch, set the flow name and display name to
getAllAirlineFlights.
15.In the Set Variable properties view, set the name and display name toairline.
16.Switch the value field toexpression modethen setits value to a query parameter
calledairline.
message.attributes.queryParams.airline
17.In the Choice router getAmericanFlights flow reference branch, click theWhen
scope.
18.In the When properties view, switch the value field toexpression mode, and then
add an expression to check if the airline variable is equal toamerican.
vars.airline == "american"
29.In the Transform Message properties view, change the output type to
application/json and set the expression to payload.
34.In the Mule Debugger, step through the application; you should see the Choice
router pass the event to the default branch.
35.Resume to the Transform Message component after the Choice router; the payload
should be an ArrayList of Flight objects
38.Return to Advanced REST Client; you should see American, United, and Delta flights
to SFO (the default airport code).
40.In the Mule Debugger, step through the application; you should see the event
passed to getAmericanFlights and then back to getFlights.
41.Return to Advanced REST Client; you should see onlyAmerican flights to SFO
returned.
42.Change the airline tounitedand add a second query parameter code set toLAX:
http://localhost:8081/flights?airline=united&code=LAX.
44.In the Mule Debugger, step through the application; the event should be routed to
the United branch.
45.Return to Advanced REST Client; you should see onlyUnited flights to LAXare
returned.
48.In the Mule Debugger, step through the application; the event should be routed to
the Delta branch.
49.Return to Advanced REST Client; you should see onlyDelta flights to PDXare
returned.
NOTE: This JSON structure does not match that specified in the API: mua-flights-api.raml in
src/main/resources/api. The datashould, of course,be transformed so the response from
the API matches this specification – but we are going to hold off doing that right now so
that the scenario stays simpler for the error handling module (there is one less error to
handle at the beginning).
52.In the Mule Debugger, step through the application; you should see multiple errors.
53.Return to Advanced REST Client; you should get a 500 Server Response and an
exception.
In this walkthrough, you use a validator to check if a query parameter called code with a
value of SFO, LAX, CLE, PDX, or PDF is sent with a request and to throw an error if it is not.
You will:
● Use an Is true validator to check if a query parameter called code with a value of
SFO, LAX, CLE, PDX, or PDF is sent with a request.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. Select theValidationmodule in the right side ofthe Mule Palette and drag and drop
it into the left side.
4. If you get a Select module version dialog box, select the latest version and clickAdd.
5. Locate theIs truevalidator in the right side ofthe Mule Palette.
6. Drag and drop theIs truevalidator after thesetCodeFlow Reference in the
getFlightsflow.
7. In theIs trueproperties view, set the display nametoIs validdestination.
9. Add aDataWeave expressionto check if the code variableis one of the five
destination codes.
NOTE: You can copy this expression from the coursesnippets.txt file.
10.Using expression mode, set the error message to Invalid destination followed by the
provided code.
NOTE: You can copy this expression from the course snippets.txt file.
12.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?code=CLE.
13.In the Mule Debugger, step past the validator; you should see the code is valid and
application execution steps to the Choice router.
15.In Advanced REST Client, you should see flights for CLE.
17.In the Mule Debugger, attempt to step past the validator; you should see an error.
18.Resume through the rest of the application; you should see your Invalid destination
message in the console.
19.Return to Advanced REST Client; you should get a 500 Server Error with your Invalid
destination message.
NOTE: You will catch this error and send a JSON responsewith a different status code in the
next module.
21.In the Mule Debugger, step past the validator; you should not get any errors.
23.Return to Advanced REST Client; you should get a 200 response with all airline flights
to SFO.
25.Locate thesetCodesubflow.
26.In the Set Variable properties view, review the default value.
30.In the Mule Debugger, attempt to step past the validator; you should now get an
error.
32.Return to Advanced REST Client; you should get a 500 Server Error with your Invalid
destination message.
NOTE: You will catch this error and send a JSON responsewith a different status code in the
next module.
● Handle messaging errors at the application, flow, and processor level.
● Use different error scopes to either handle an error and continue execution of the
parent flow or propagate an error to the parent flow.
● Set the success and error response settings for an HTTP Listener.
In this walkthrough, you get familiar with the three errors you will learn to handle in this
module. You will:
● Explore information about different types of errors in the Mule Debugger and the
console.
● Review and modify the error response settings for an HTTP Listener.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
7. In Advanced REST Client, add a code and make a request to
http://localhost:8081/flights?code=FOO.
8. In the Mule Debugger, step to where the error is thrown and examine the error
object; you should see an error description, errorType, and other properties.
9. Step through the rest of the application and review the error information logged in
the console.
10.In Advanced REST Client, locate the response status code, status reason, and body;
you should see a 500 status code, a status reason of Server Error, and a response
body equal to the error description.
12.In the Mule Debugger, step to where the error is thrown and review the error object.
13.Step again and review the error information logged in the console.
15.Return to Advanced REST Client; you should see a 500 Server Error with the error
description.
17.In the Mule Debugger, step to where the error is thrown and review the error object.
20.Return to Advanced REST Client; you should see a 500 Server Error with the error
description.
24.Select theResponsestab.
25.Locate theError Responsesection and review the default settings for the body,
status code, and reason phrase.
Remove the default error response settings for the HTTP Listener
26.Select and cut the body expression (so it has no value, but you can paste it back
later).
27.Save the file, run the project, and proceed through any errors in the workspace.
Modify the default error response settings for the HTTP Listener
30.Return to the Responses tab in the properties view for the GET /flights Listener.
31.In the error response body, paste back the original value.
output
text/plain --- error.description
32.Change the output type of the error response toapplication/jsonand display the
error.errorType.
output
application/json --- error.errorType
Return the default error response settings for the HTTP Listener
43.Change the error response output type back totext/plainand display the
error.description.
output
text/plain --- error.description
46.In Advanced REST Client, change the airline and code to make a request to
http://localhost:8081/flights?airline=american&code=PDX;you should get the 500
Server Error again with the plain text error description.
In this walkthrough, you create a default error handler for the application. You will:
● Explore the differences between the On Error Continue and On Error Propagate
scopes.
● Modify the default error response settings for an HTTP Listener.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. In the Core section of the Mule Palette, locate the Error Handling elements.
3. Drag out an Error Handler element and drop it in the canvas ofglobal.xml.
5. In the On Error Continue properties view, click thesearchbutton for type.
9. In the Transform Message properties view, change the output type to
application/json.
10.Add a message property to the output JSON and give it a value of the
error.description.
12.ClickCreate.
13.In the Choose Global Type dialog box, selectGlobalConfigurations > Configuration
and clickOK.
14.In the Global Element Properties dialog box, set the default error handler to
globalError_Handlerand clickOK.
16.Return toimplementation.xml.
18.Select theResponsestab.
19.Locate the Response section (not the Error Response section) and review the default
settings for the body, status code, and reason phrase.
20.Locate the Error Response section and review the default settings for the body,
status code, and reason phrase.
21.Save all files, debug the project, and proceed through any errors in the workspace.
23.In the Mule Debugger, step through the application until the event is passed to
globalError_Handler.
25.Step again; the event should be passed back to getFlights, which continues to
execute after the error occurs.
28.Return to Advanced REST Client; you should see a 200 OK response with the
response body equal to the payload value set in the error handler.
30.Return toglobal.xml.
31.Drag anOn Error Propagatescope from the Mule Palette and drop it to the right or
left of theOn Error Continueto add it toglobalError_Handler.
38.Look at the error object in the Mule Debugger; it should be the same as before.
40.Look at the payload and the error object in the Mule Debugger.
41.Step twice more; the error is handled by the application’s default error handler again.
42.Look at the payload and the error object in the Mule Debugger.
44.Return to Advanced REST Client; you should get a 500 Server Error response with the
response body equal to the plain text error description – not the payload.
Modify the default error response settings for the HTTP Listener
47.Return toimplementation.xml.
49.Change the error response body to return the payload instead of error.description.
payload
50.Save the file, run the project, and proceed through any errors in the workspace.
NOTE: You will handle this error differently in alater walkthrough, so it does not return a
server error. It is a valid request; there are just no American flights to PDX.
In this walkthrough, you continue to work with the application’s default error handler. You
will:
Starting file
I f you did not complete the previous walkthrough, you can get a starting file h ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. Navigate to the properties view for the Get flights Consume operation in
getDeltaFlights.
4. Click theAdd new mappingbutton and review (but don’tselect!) theWSCerror
types.
7. Click theAdd new mappingbutton, and review (butdon’t select!) the
AMERICAN-FLIGHTS-APIerror types.
11.Return toglobal.xml.
13.If necessary, drag and drop it so it is the first scope inside the error handler.
14.Return to the coursesnippets.txtfile and copy theexpression for the error type.
16.In the properties view for the newOn Error Propagate, set the error type by pasting
the expression you copied.
WSC:CONNECTIVITY, WSC:INVALID_WSDL
18.In the Transform Message properties view, change the output type to
application/json.
19.Add a message property to the output JSON and give it a value ofData unavailable.
Try later.
NOTE: This should also not be a server error, buteither a 4XX bad request or a 200 OK with
an appropriate message. You will handle this error differently in the next walkthrough.
In this walkthrough, you add multiple error handlers to a flow. You will:
● Test the behavior of errors thrown in a flow and by a child flow.
● Set an HTTP status code in an error handler and modify an HTTP Listener to return it.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
4. Set the error type toANYso it will initially catchboth the validation and American
flights errors.
5. Add aTransform Messagecomponent to the scope and set the display name toNo
flights.
6. In the Transform Message properties view, set the payload to aJSON message
propertyequal to the stringNo flights toand concatenatethe code variable.
9. In the Set Variable properties view, set the display name and name tohttpStatus.
Set the HTTP Listener error response status code to use a variable
12.Use expression mode to change the error response status code (not the response
status code!) to an expression that sets it equal to the value of an httpStatus variable
with a default value of500.
vars.httpStatus
default
500
13.Save the file, debug the project, and proceed through any errors in the workspace.
14.In Advanced REST Client, change the airline to make a request to
http://localhost:8081/flights?airline=american&code=FOO.
15.In the Mule Debugger, step until the event is passed to the flow’s error handler.
17.Return to Advanced REST Client; you should get the 200 status code and the JSON
message.
18.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?airline=american&code=PDX.
20.Step until the error is passed to the parent flow’s error handler.
22.Return to Advanced REST Client; you should get the 200 status code and the JSON
error message.
28.In the Mule Debugger, step through the application; the error should still be handled
by globalError_Handler and then the getFlights flow error handler.
29.In Advanced REST Client, change the code to make a request to
http://localhost:8081/flights?airline=american&code=FOO.
30.In the Mule Debugger, step through the application; you should get a 500 Server
Error and no message because the error is not handled by the getFlights flow error
handler or by globalError_handler.
34.Review theerror response body(not the response body!)and ensure you know why
you got the last response for
http://localhost:8081/flights?airline=american&code=FOO.
36.In the On Error Continue properties view, set the type to
VALIDATION:INVALID_BOOLEAN.
37.Add aTransform Messagecomponent to the scope andset the display name to
error.description.
38.In the Transform Message properties view, set the payload to aJSON message
property equal to the error.description.
40.Set the display name and name to httpStatus and set the value to 400.
41.Save the file, run the project, and proceed through any errors in the workspace.
45.Use expression mode to set theresponse status code(not the error response status
code!) to an expression that sets it equal to the value of an httpStatus variable with a
default value of 200.
vars.httpStatus
default
200
48.In Advanced REST Client, change the code and make a request to
http://localhost:8081/flights?airline=american&code=PDX;you should get a 200
response and no flights to PDX.
In this walkthrough, you work with the Scatter-Gather in getAllAirlineFlights so that it
correctly returns results when one but not all airlines have flights. You will:
● Wrap the Flow Reference in each branch of a Scatter-Gather in a Try scope.
● Use an On Error Continue scope in each Try scope error handler to provide a valid
response so flow execution can continue.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. Debug the project and proceed through any errors in the workspace.
4. Return to the Mule Debugger and step through the application until you see a
routing exception.
6. Return to Advanced REST client, you should get the 500 Server Error that there were
exceptions in routes 0 and 2.
7. Return to Anypoint Studio and switch to the Mule Design perspective.
9. Drag aTryscope from the Mule Palette and drop itin theScatter-Gatherbefore the
getAmericanFlightsFlow Reference.
12.Move the getUnitedFlights Flow Reference into one of the Try scopes and the
getDeltaFlights Flow Reference into the other.
Add an error handler to each branch that passes through the error
message
14.Add anOn Error Continuescope and set the types oferrors it handles to ANY.
15.Repeat these steps to add the same error handler to the two other Try scopes.
18.In the Mule Debugger, resume to the Logger after the Scatter-Gather in
getAllAirlineFlights.
19.ExpandPayload; you should see three flights (fromUnited) and two error messages.
21.Return to Advanced REST Client; you should see United flights and error messages.
25.In the Transform Message properties view, set the payload to an empty array.
26.Repeat the steps to add the same Transform Message component to the two other
error handlers.
29.In the Mule Debugger, resume to the Logger after the Scatter-Gather in
getAllAirlineFlights.
30.ExpandPayload; you should now see the three flightsand no error messages.
32.Return to Advanced REST Client; you should now only see the three flights.
In this walkthrough, you map the Validation error to a custom error type for the application.
You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
6. Leave the namespace of the custom error to map to set toAPP.
Change the existing validation error handler to catch the new custom
type
9. Navigate to the properties view for the getFlights validation On Error Continue error
handler.
11.Save the file, run the project, and proceed through any errors in the workspace.
12.In Advanced REST Client, change the code and make a request to
http://localhost:8081/flights?code=FOO; you shouldstill get a 400 response with
the invalid destination error.
13.Collapse thegetAllAirlineFlightsandsetCodeflows.
NOTE: The following steps have instructions to makechanges in the XML. If you prefer, you
can copy and paste the error handler to move it between files and then delete the original.
18.Return toglobal.xml.
20.Place the cursor on a new line inside and at the start of theglobalError_Handler
error-handler.
22.Switch back to the Message Flow view; you should see the
APP:INVALID_DESTINATION handler.
23.Return to implementation.xml and switch to the Message Flow view; you should no
longer see an error handler in getFlights.
In this walkthrough, you connect the application’s implementation to the interface and
ensure all the error handling works. You will:
● Review settings for the APIkit Router and HTTP Listener in the APIkit generated
interface.
● Connect the implementation to the interface and test the error handling behavior.
● Modify implementation error scopes so they work with the APIkit generated
interface.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
4. Review the types of errors handled by each error handler scope.
5. Navigate to the Transform Message properties view for the first error handling scope.
7. Use the output dropdown menu to change the output toVariable – httpStatus.
8. Review the expression that sets an httpStatus variable; you should see that for a bad
request the httpStatus variable is set to 400.
9. Navigate to the properties view for the APIkit Router in mua-flights-api-main.
11.In the Global Element Properties dialog box, locate the HTTP status var name
setting; you should seehttpStatus.
12.ClickOK.
20.In the Flow Reference properties view, set the flow name and display name to
getFlights.
21.Return toimplementation.xml.
30.Return tomua-flights-api.ramland review the code;you should see the code query
parameter is not required but it has allowed values enumerated.
31.Return tointerface.xml.
33.Debug the project and proceed through any errors in the workspace.
35.In the Mule Debugger, watch the payload and variables and step through the
application.
39.In Advanced REST Client, change the code to make a request to
http://localhost:8081/api/flights?airline=american&code=FOO.
40.In the Mule Debugger, step through the application; the APIkit router should
immediately throw an error.
41.Step again; you should see that the error is handled by theAPIKIT:BAD_REQUEST
handler.
43.In Advanced REST Client, remove the airline and code to make a request to
http://localhost:8081/api/flights.
44.In the Mule Debugger, step through the application; the validator should throw an
error and execution should not return to the APIkit router.
45.Return to Advanced REST Client; you should get a 400 response with the custom
message.
NOTE: If you had specified the code query parameter to be required in the RAML file from
which the interface was generated, the APIkit router would catch this immediately and
respond with a 400 Bad Request response. The event would never get to the validator in
your implementation.
47.Return toimplementation.xml.
52.Switch back to the Message Flow view; you should now see an On Error Continue.
53.Return toglobal.xml.
58.Switch back to the Message Flow view; you should now see both are On Error
Continue scopes.
Set the HTTP status code for the On Error Continue scopes so you do
not get 200
60.In the Set Variable properties view, set the display name and name tohttpStatus.
64.In Advanced REST Client, add the airline and code to make a request to
http://localhost:8081/api/flights?airline=american&code=PDX.
65.In the Mule Debugger, step through the application; the application now does not
return to the APIkit router.
66.Return to Advanced REST Client; you should now get a 200 response with the No
flights to PDX message.
67.In Advanced REST Client, change the airline to make a request to
http://localhost:8081/api/flights?airline=delta&code=PDX.
69.Return to Advanced REST Client; you should now get the 500 response with the data
unavailable message.
● Set a reconnection strategy for the Web Service Consumer connector.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
4. In the Global Element Properties dialog box, select theAdvancedtab in the second
tab bar.
8. ClickOK.
● Write DataWeave expressions for basic XML, JSON, and Java transformations.
● Write DataWeave transformations for complex data structures with repeated elements.
● Define and use global and local variables and functions.
In this walkthrough, you create a new flow that receives flight POST requests that you will
use as the input for writing transformations in the next several walkthroughs. You will:
● Create a new flow that receives POST requests of JSON flight objects.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow that receives POST requests and returns the payload
as Java
5. Drag a Transform Message component from the Mule Palette to the bottom of the
canvas; a new flow should be created.
7. In the Transform Message properties view, set the expression topayload.
NOTE: If you see a metadata propagation error on theTransform Message, you can proceed
normally.
10.Return tointerface.xml.
12.Locate thepost:\flights:application\json:mua-flights-api-configflow.
14.In the Flow Reference properties view, set the flow name and display name to
postFlight.
16.Openflight-example.jsoninsrc/test/resources.
18.In Advanced REST Client, change the method to POST and remove any query
parameters.
24.Step to theLogger; you should see the payload now has a mediaType of
application/java and is a LinkedHashMap.
26.Examine the input section of the Transform Message properties view; note the field
for the optional ID property.
27.Return tointerface.xml.
34.In the Custom Metadata dialog box, locate and expand the expected payload on the
Input Metadata tab; note the absence of the optional ID property.
35.ClickOK.
37.In the Transform Message properties view for the transformation in postFlight; you
should now see updated metadata for the input.
38.Openapplication-types.xmlinsrc/main/resources.
41.In the input section of the Transform Message properties view, right-click the
payload and selectEdit Sample Data; you should seea new tab calledpayloadand
it should contain the sample input of type JSON.
NOTE: If sample data doesn't automatically appearin the preview section, click theCreate
required sample datato execute the preview link.
45.Openjson.json.
47.In the Transform Message properties view, click theAdd new targetbutton.
50.ClickOK.
51.Click the dropdown menu for the output; you should see that you can switch
between the two transformations.
52.For the new transformation, set the output type to json and set the expression to
payload.
62.In the Transform Message Properties view, make sure the payload output expression
is selected.
64.In the Selection dialog box, change the source code selection frominlinetofile.
66.ClickOK.
Locate and review the code that uses an external DataWeave script
70.Openjson_flight_playground.dwl.
76.Mouse over the icon located to the left of the code; you should see a message that
there was an exception trying to output the second root<flightCode>.
77.Click the icon above the code; aList of warningsand errorsdialog box should open.
79.ClickOK.
NOTE: You will learn how to successfully transform to XML in the next walkthrough.
82.In the Mule Debugger, step once; you should get an error.
83.Review the error information; you should see there is a DataWeave error when trying
to output the second root.
In this walkthrough, you continue to work with the JSON flight data posted to the flow. You
will:
● Write scripts to transform the JSON payload to various JSON and Java structures.
● Write scripts to transform the JSON payload to various XML structures.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the Transform Message properties view for the transformation in
postFlight.
2. In the output dropdown menu, make sure thepayloadoutput expressionis
selected.
4. Type a period after payload and double-clickprice(or navigate with row keysand
pressEnter) in the auto-completion menu.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
22.Modify the expression so the code and airline properties are child elements of a new
element calledflight.
24.In the Logger properties view, set the message to the value of theDWoutput
variable.
27.In the Mule Debugger, step to the Logger; you should see the transformed JSON
payload and that the DWoutput variable has a mediaType of application/xml.
29.Look at the Logger output in the console; you should see the XML.
In this walkthrough, you create a new flow that allows multiple flights to be posted to it, so
you have more complex data with which to work. You will:
● Create a new flow that receives POST requests of a JSON array of flight objects.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Create a new flow that receives POST requests of a JSON array of flight
objects
2. Drag out anHTTP Listenerfrom the Mule Palette tothe bottom of the canvas.
4. In the HTTP Listener properties view, set the display name toPOST /multipleflights.
6. Set the path to/multipleflightsand set the allowed methods to POST.
NOTE: You are bypassing the APIkit router becausea corresponding resource/method pair
is not defined in the API.
8. In the Transform Message properties view, set the expression topayload.
12.In the Transform Message Properties view, you should now see metadata for the
input.
13.In the input section, right-click the payload and selectEdit Sample Datato get
sample input data.
NOTE: If sample data doesn't automatically appearin the preview section, click theCreate
required sample data to executepreview link.
15.Look at the preview section; the sample output should be an array of objects.
21.Change the DataWeave expression to payload.price; you should get the same result.
[payload.price, payload.emptySeats]
Use the map function to return object collections with different data
structures
24.Change the DataWeave expression to set a property calledflightfor each object that
is equal to its index value in the collection.
NOTE: If you want to test the application, changethe output type to application/json and
then in Advanced REST Client, make a request to http://localhost:8081/multipleflights and
replace the request body with JSON from the flights-example.json file.
34.Click the warning icon above the code, review the issues, then click OK.
35.Change the DataWeave expression to create a root node calledflights; you should
still get issues.
36.Click the warning icon above the code, review the issues, then clickOK.
In this walkthrough, you continue to work with the JSON data for multiple flights posted to
the flow. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Change the expression to map each item in the input array to an XML element.
3. Look at the preview; the JSON should be transformed to XML successfully.
4. Modify the expression so the flights object has a single property calledflight.
7. In the Select metadata type dialog box, selectflights_xmland clickSelect.
8. In the Transform Message Properties view, you should now see new metadata for
the input.
9. In the input section, click thexon the payload tabto close it.
10.In the Close Sample Data dialog box, clickClose taband Keep file.
11.Right-click the payload and selectEdit Sample Datato get sample input data.
NOTE: You may see more than one issue. If so, onlyone should be an error, the rest
warnings.
16.In the input section, click on theContexttab tolook at the payload metadata.
18.Change the DataWeave expression so that the map is iterating over the repeated
return elements of the input.
NOTE: If you want to test the application with AdvancedREST Client, be sure to change the
content-type header to application/xml and replace the request body with XML from the
flights-example.xml file.
24.In the DataWeave expression, remove the flight property; you should get an object
consisting of an array of five objects.
In this walkthrough, you continue to work with the DataWeave transformation in
postMultipleFlights. You will:
● Define and use a global variable that is equal to a lambda expression.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
3. In the header, define a global variable callednumSeatsthat is equal to400.
totalSeats: numSeats
7. In the header, define a global variable callednumSeatsthat is equal to a lambda
expression with an input parameterx equal to 400.
totalSeats: numSeats()
11.Add aplane propertyto the DataWeave expression equalto the value of the input
planeType values.
15.Inside the expression, add an if/else block that checks to see if planeType contains
the string 737 and sets numSeats to150 or 300otherwise.
totalSeats: numSeats(object.planeType)
150
else
300
23.In the body, change the totalSeats property to be equal to the result of the
getNumSeats function.
totalSeats: getNumSeats(object.planeType
as
String)
27.After the if/else block, add a body separator then set the body of the do scope to the
maxSeatslocal variable.
In this walkthrough, you continue to work with the XML flights data posted to the
postMultipleFlights flow. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
Format a string
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Use the upper function to return the plane value in uppercase.
5. In the preview, look at the data type of the prices; you should see that they are
strings.
6. Change the DataWeave expression to use theaskeywordto return the prices as
numbers.
9. Click theTexttab and look at the preview; you shouldsee the prices are now either
integer (Integer objects) or non-integer (Double objects).
10.Click theTreetab.
11.Change the DataWeave expression to use the class metadata key to coerce the prices
to java.lang.Double objects.
12.Look at the preview; you should see the prices are now all Double objects
(non-integers).
Format a number
15.Coerce the price to a String and use the format schema property to format the prices
to zero decimal places.
17.Change the DataWeave expression to format the prices to two decimal places.
19.Change the DataWeave expression to format the prices to two minimal decimal
places.
20.Look at the preview; all the prices should now be formatted to two decimal places.
NOTE: If you are not a Java programmer, you may wantto look at the Java documentation
for the DecimalFormatter class to review documentation on DecimalFormat patterns.
https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html
date: object.departureDate
22.Look at the preview; you should see the date property is a String.
26.Change the DataWeave expression to use the format schema property to specify the
pattern of the input date strings.
NOTE: If you are not a Java programmer, you may wantto look at the Java documentation
for the DateTimeFormatter class to review documentation on pattern letters.
https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html
27.Look at the preview; you should see date is now a Date object.
Format a date
28.Use the as operator to convert the dates to strings, which can then be formatted.
29.Look at the preview section; the date is again a String – but with a different format.
30.Use the format schema property with any pattern letters and characters to format
the date strings.
31.Look at the preview; the dates should now be formatted according to the pattern.
In this walkthrough, you continue to work with the flight JSON posted to the flow. You will:
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
2. Select and cut the string formatting expression for the prices.
3. In the header section of the expression, define a custom data type calledCurrency.
6. Look at the preview; the prices should still be formatted as strings to two decimal
places.
7. Open theFlight.javaclass in the project's src/main/javafolder, look at the names of
the properties then close the file.
8. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
9. In the header section of the expression, define a custom data type calledFlightthat
is of typecom.mulesoft.training.Flight.
NOTE: Click the Preview button (Cmd+Shift+PorCtrl+Shift+P)if the preview section is not
displayed.
destination: object.destination,
NOTE: If you want to test the application with AdvancedREST Client, be sure to change the
content-type header to application/xml and replace the request body with XML from the
flights-example.xml file.
● Use functions in the Core module that are imported automatically.
● Use a function in another module that you must explicitly import into a script to use.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the Transform Message properties view for the transformation in
postMultipleFlights.
4. For planeType, use the replace function to replace the stringBoingwithBoeing.
6. For planeType, replace the upper function with the dasherize function.
8. In the script header, add an import statement to import dasherize from the Strings
module.
import
dasherize
from
dw::core::Strings
10.In the preview section, look at the flight prices; the flights are not ordered by price.
11.Add parentheses around the value of the flights root node then use the orderBy
function to order the flights by price.
orderBy $.price
13.Look at the three $283 flights; there is a duplicate and they are not ordered by date.
14.Change the DataWeave expression to sort flights by date and then by price.
15.Look at the preview; the flights should now be ordered by price and flights of the
same price should be sorted by date.
17.Look at the preview; you should now see only two $283 flights to PDX instead of
three.
18.Add an availableSeats field that is equal to the emptySeats field and coerce it to a
number.
19.Look at the preview; you should get three $283 flights to PDX again.
20.In the preview, look at the values of theavailableSeatsproperties; you should see
one is equal to zero.
21.Use the filter function to remove any objects that have availableSeats equal to 0.
22.Look at the preview; you should no longer get the flight that had no available seats.
● Trigger flows when new records are added to a database table.
● Persist and share data in flows using the Object Store.
In this walkthrough, you load data from a local CSV file when a new file is added to a
directory. You will:
Starting file
If you did not complete walkthrough 2-4, you can get a starting file h
ere. This file is also
located in the solutions folder of the student files ZIP located in the Course Resources.
1. In your computer’s file browser, return to the student files for the course.
2. Open the resources folder and locate the accounts.csv file and the input and output
folders.
5. Openaccounts.xml.
7. Select the File connector in the right side of the Mule Palette and drag and drop it
into the left side.
8. If you get a Select module version dialog box, select the latest version and clickAdd.
9. Locate theOn New or Updated Fileoperation for the File connector in the right side
of the Mule Palette and drag and drop it at the top of the canvas to create a new
flow.
12.ClickCreate.
13.In the Choose Global Type dialog box, selectConnectorConfiguration > File Config
and clickOK.
14.In the Global Element Properties dialog box, select theConnectioncheckbox then
click the browse button next to Working Directory.
17.Select and cut the value of the working directory that got populated and replace it
with a property${file.accountsDir}.
19.Openconfig.yamlinsrc/main/resources.
NOTE: Users on all OSs, including Windows, shoulduse forward slash characters as shown.
21.Return toaccounts.xml.
22.In the On New or Updated File properties view, change the display name to
accounts.csv.
27.In the Post processing action section, set the move to directory tooutput.
28.In the General section, review the default scheduling information; the endpoint
checks for new files every 1000 milliseconds.
31.In the Logger properties view, set the display name to payload and the message to
display the payload.
#[payload]
34.In your computer’s file browser, return to the resources folder in student files for the
course.
39.In your computer’s file browser, return to the student files for the course; you should
see accounts.csv has been moved to the output folder.
40.Return to Anypoint Studio and look at the console; you should see the file contents
displayed.
#[attributes.fileName ++ ".backup"]
44.In your computer’s file explorer, move theaccounts.csvfile from the output folder
back to the input folder; you should see it appear in the output folder with its new
name.
45.Move theaccounts.csv.backupfile from the outputfolder back to the input folder; it
should not be processed and should stay in the input folder.
In this walkthrough, you work with the accounts table in the training database. You will:
● Add and configure a Database listener to check a table on a set frequency for new
records.
● Use the listener’s automatic watermarking to track the ID of the latest record
retrieved and trigger the flow whenever a new record is added.
● Use a form to add a new account to the table and see the CSV file updated.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
1. Return to the coursesnippets.txtfile and copy thetext for the MUA Accounts URL.
2. In a web browser, navigate to theMUA accountsby pasting the URL.
3. Review the data and the names of the columns which match those of a database
table.
6. Locate the watermark mode setting in the General section and look at its possible
values.
8. Select the Database connector in the right side of the Mule Palette and drag and
drop it into the left side.
9. If you get a Select module version dialog box, select the latest version and clickAdd.
10.Locate the On Table Row operation for the Database connector in the right side of
the Mule Palette and drag and drop it at the top of the canvas to create a new flow.
NOTE: The database information you see may be differentthan what is shown here; the
values in the snippets file differ for instructor-led and self-study training classes.
NOTE: If necessary, refer to the detailed steps inWalkthrough 4-2 of the Getting Started
with Anypoint Platform course.
19.Return toaccounts.xml.
20.In the On Table Row properties view, set the following values:
23.ExpandPayloadin the Input tab in the DataSense Explorer; you should see the
operation will get an account with account information from the Database
operation.
26.In the Transform Message properties view, change the output type to
application/csvand add a header property equal tofalse.
32.Save all files then, in the main menu, selectRun> Debug Configurations.
34.In the Debug Configurations dialog box, locate the Clear Application Data section in
the General tab and change it to Prompt.
NOTE: You need to rerun or debug an application toget the prompt; you cannot just save to
redeploy.
35.ClickDebug.
45.Return to the resources folder in your computer’s file explorer; you should see a new
DBaccounts.csvfile appear in the output folder.
47.Close theDBaccounts.csvfile.
50.Look at the console; you should see no new records output (unless someone else
just added one!).
52.ClickAdd account.
Note:Set the postal code to a specific value. Inthe next walkthrough, you will retrieve only
new records with this specific postal code, so you do not get all of the records.
55.Return to the console in Anypoint Studio; you should see your new record.
57.Return to your computer’s file explorer; the modified date on the DBAccounts.csv file
should have been updated.
59.Close theDBaccounts.csvfile.
In this walkthrough, you continue to work with the accounts table in the training database.
You will:
● Use the Scheduler component to create a new flow that executes at a specific
frequency.
● Retrieve accounts with a specific postal code from the accounts table.
● Use the Object Store component to store the ID of the latest record and then use it
to only retrieve new records.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. Drag aSchedulercomponent from the Mule Palette anddrop it at the top of the
canvas to create a new flow.
5. In the Scheduler properties view, set the frequency to10 seconds.
6. From the Mule Palette, drag a Database Select operation and drop it in the flow.
● SQL query text: SELECT * FROM accounts WHERE postal= :postal
8. In the Input Parameters section, use expression mode to create a postal input
parameter with the specific postal code you used in the previous walkthrough.
{ postal:
'yourPostalValue'
}
NOTE: If you want, you can store the postal code asa property in config.yaml and then
reference it here in the DataWeave expression as { postal: p('propertyName')}.
10.In the properties view for the Write operation, set the following values:
12.Add a Logger at the end of the flow and change the display name toCSV payload.
14.In the properties view for the syncDBaccountsToCSV flow, set the initial state to
stopped.
17.Watch the console, you should see the same records displayed every 10 seconds.
Note:Right now, all records with matching postalcode are retrieved – over and over again.
Next, you will modify this so only new records with the matching postal code are retrieved.
19.Return to the resources folder in your computer’s file browser; you should see the
newDBaccountsPostal.csvfile in the output folder.
20.Open the file, review the contents then close the file.
23.Select the ObjectStore connector in the right side of the Mule Palette and drag and
drop it into the left side.
24.If you get a Select module version dialog box, select the latest version and clickAdd.
25.Drag the Store operation for the ObjectStore connector from the Mule Palette and
drop it after the Database Select operation.
26.In the Store properties view, set the display name and key to lastAccountID.
27.Set the value to an expression for the maximum value of lastAccountID in the
payload containing the retrieved records.
max(payload.*accountID)
30.Select theAdvancedtab and set the target variableto lastAccountID so the value is
stored in a variable called lastAccountID.
Modify the query to only retrieve new records with a specific postal
code
31.In the accounts Select properties view, add a second query input parameter called
lastAccountIDthat is equal to the watermark value.
{postal: '
yourValue
', lastAccountID: vars.lastAccountID}
32.Modify the SQL query text to use this parameter to only retrieve new records.
36.In the default branch Logger properties view, set the display name and message to
No new records.
37.In the Choice router, click thewhenscope and in the properties view, add an
expression to route the event when the payload is not empty.
#[not isEmpty(payload)]
41.In the Mule Debugger, step to the Select operation; you should see a lastAccountID
variable with a value of 0.
42.Step into the Choice router; you should see record(s) were retrieved from the
database.
44.Step to the Select operation; you should see the lastAccountID variable now has a
non-zero value.
45.Step into the Choice router; you should see no records were retrieved from the
database (unless someone else just added one with the same postal code!).
47.Return to your computer’s file explorer and locate and open the new
DBaccountsPostal.csv file in the output folder.
NOTE: If you see the same records more than once,it is because during debugging, the flow
was executed again before the watermark was stored.
48.Close theDBaccountsPostal.csvfile.
51.In the Mule Debugger, step to the Select operation; you should see a lastAccountID
variable with the same non-zero value.
52.Step into the Choice router; no new records should have been returned.
54.Make sure there are no other breakpoints in the flow then clickResumeto continue
application execution.
NOTE: If your application still halts at the Retrieve operation, stop then debug the project
without clearing the application data.
56.ClickAdd account.
57.Fill out the form with data and use the same postal code.
58.ClickSave.
59.You should see your new account on the MUA accounts page.
60.Return to Anypoint Studio; you should see your new record in the console.
63.Close theDBaccountsPostal.csvfile.
In this walkthrough, you send a JMS message for each new database record so it can be
processed asynchronously. You will:
● Add and configure a JMS connector for ActiveMQ (that uses an in-memory broker).
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
3. Select theJMS connectorin the right side of theMule Palette and drag and drop it
into the left side.
4. If you get a Select module version dialog box, select the latest version and clickAdd.
6. ClickCreate.
7. In the Choose Global Type dialog box, selectConnectorConfiguration > JMS Config
and clickOK.
8. In the Global Element Properties dialog box, make sure the connection is set to
ActiveMQ Connection.
9. Click theConfigure > Add Mavendependency optionfor the ActiveMQ Broker.
10.In the Maven dependency dialog box, enteractivemq-brokerin the Search Maven
Central field.
12.ClickEdit selected.
14.ClickFinish.
16.For Factory configuration, selectEdit inline; theBroker url should already be
populated.
17.ClickOK.
18.Return toaccounts.xml.
19.Drag out aJMS Publishoperation from the Mule Paletteand drop it after the Write
operation in syncDBaccountsWithPostal.
23.Use expression mode and set it equal to an object with a key calledpublisherand a
value oftraining.
{"publisher":"training"}
24.Drag out theJMS On New Messageoperation from theMule Palette and drop it in
the canvas to create a new flow.
26.In the On New Message properties view, set the following values:
32.Wait until the project deploys; application execution should stop in
receiveJMSMessages.
33.In the Mule Debugger view, look at the value of the payload.
35.Step through the rest of the application; you should see the JSON message in the
console.
NOTE: If you want to test further, return to the MUAAccounts in the web browser and add a
new record with the same postal code.
In this walkthrough, you split a collection and process each item in it. You will:
● Use the For Each scope element to process each item in a collection individually.
● Examine the payload before, during, and after the scope.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. In the properties view for the syncDBaccountsWithPostal flow, set the initial state to
stopped.
4. ExpandgetCSVaccounts.
6. Locate the For Each scope and drag and drop it before the Logger.
7. Add a Transform Message component before the For Each scope.
9. In the Transform Message properties view, leave the output type set tojavaand set
the expression topayload.
11.In the Set Payload properties view, set the display name and value to processed.
12.Set the Logger display name to payload and have it display the payload.
15.Save the file, debug the project, and do not clear application data.
19.In the Mule Debugger view, look at the payload type and value.
20.Step to the For Each scope; the payload should now be an ArrayList of
LinkedHashMaps.
21.Step into the Set Payload in the For Each scope; the payload should now be a
LinkedHashMap.
23.Step again; you should see the payload for this record inside the scope has been set
to the string, processed.
24.Step again and look at the payload and counter for the second record.
25.Step through the application to the Logger after the For Each scope; the payload
should be equal to the original ArrayList of LinkedHashMaps and not a list of
processed strings.
28.In the console, locate the thread number used to process each item in the
collection; the same thread should be used for each:cpuIntensive.01in the
following screenshot.
In this walkthrough, you create a batch job to process the records in a CSV file. You will:
● Examine the payload that contains information about the job in the On
Complete phase.
● Look at the threads used to process the records in each step.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
2. Drag a Flow scope from the Mule Palette and drop it above getCSVaccounts.
4. Select the On New or Updated File operation in getCSVaccounts and copy it.
8. In the Transform Message properties view, change the body expression topayload.
16.Drag aBatch Stepscope from the Mule Palette anddrop it in the process records
phase of the Batch Job scope after the first batch step.
Stop the other flow watching the same file directory from being
executed
19.In the properties view for the getCSVaccounts flow, set the initial state tostopped.
21.Save the file, debug the project, and do not clear application data.
22.Return to the student files in your computer’s file browser and move accounts.csv
from the output folder to the input folder.
23.In the Mule Debugger view, watch the payload as you step to the Batch Job scope; it
should go from CSV to an ArrayList.
24.In the Mule Debugger view, expandVariables; you shouldsee the size variable.
26.In the Mule Debugger view, look at the value of the payload; it should be a
HashMap.
28.Step through the rest of the records in the first batch step and watch thepayload
and thecnamevariable change.
29.Step into the second batch step and look at thepayloadand thecnamevariable;
you should see the cname variable is defined and has a value.
30.Step through the rest of the records in the second batch step and watch the value of
cname.
31.Step into the On Complete phase; you should see the payload is an
ImmutableBatchJobResult.
35.In the console, locate the thread number used to process each record in the
collection in each step of the batch process; you should see more than one thread
used.
In this walkthrough, you use a batch job to synchronize account database records to
Salesforce. You will:
● Use a batch job to synchronize database records (with your postal code) to
Salesforce.
● In a first batch step, check to see if the record already exists in Salesforce.
● Use a batch step filter so the second batch step is only executed for specific records.
Starting file
If you did not complete the previous walkthrough, you can get a starting file h
ere. This file is
also located in the solutions folder of the student files ZIP located in the Course Resources.
4. Look at the existing account data; a Salesforce Developer account is populated with
some sample data.
5. Notice that countries and postal codes are not displayed by default.
7. In the New List View dialog box, set the list name toAll Accounts with Postal Code.
9. ClickSave.
11.In the Select Fields to Display dialog box, selectBilling Zip/Postal Codeas the
available field and click theMove selection to VisibleFieldsbutton.
14.ClickSave; you should now see all the accounts withpostal codes and countries.
16.Click theNewbutton.
17.In the New Account dialog box, enter an account name (one that matches one of
the accounts you added with your postal code to the database) and clickSave.
20.Drag a Batch Job scope from the Mule Palette and drop it before the Logger in the
receiveJMSmessages flow.
22.Change the name of the batch step inside the batch job toisAccountInSalesforce.
27.In the Transform Message properties view, look at the metadata in the input section.
30. In the Transform Message properties view, click the Show Graphics button and map
the following fields:
NOTE: If you do not get Salesforce metadata for theAccount object, you can copy the
DataWeave transformation from the course snippets.txt file.
32.Set the parameter value topayload.Name, ensure itis aString, and give it a default
value.
33.Modify the Salesforce query to look for accounts with this name.
34.Select theAdvancedtab.
39.In the properties view for the syncDBaccountsWithPostal flow, change the initial
state tostarted.
43.In the Mule Debugger, wait until application execution stops in the
receiveJMSmessages flow.
44.Step to the Logger in the first batch step and expand Variables; you should see the
existsvariable set totrue or false.
45.Step through the application; you should see theexistsvariable set to false for
records with names that don’t exist in Salesforce and true for those that do.
49.In the properties view for the second batch step, set the accept expression so that
only records that have the variable exists set to false are processed.
#[not vars.exists]
Use the Salesforce Create operation to add new account records to
Salesforce
53.Drag aBatch Aggregatorscope from the Mule Paletteand drop it in the aggregator
phase of the second batch step.
55.In the Batch Aggregator properties view, set the aggregator size to 3.
57.Save the file, debug the project, and clear the application data.
58.Step through the application until you step into the Batch Aggregator.
59.ExpandPayload.
61.Return to Salesforce and look at the accounts; you should see the records from the
legacy MySQL database are now in Salesforce.
NOTE: You could also check for the records by makinga request to
http://localhost:8081/sfdc.
62.Stop the application then run it again but do not clear the application data; no
records should be processed.
63.Return to salesforce.com and locate your new record(s); they should have been
inserted only once.