diff --git a/modules/ROOT/pages/tut-af-integrate-use-dataweave.adoc b/modules/ROOT/pages/tut-af-integrate-use-dataweave.adoc index a49be264c..80ab9752a 100644 --- a/modules/ROOT/pages/tut-af-integrate-use-dataweave.adoc +++ b/modules/ROOT/pages/tut-af-integrate-use-dataweave.adoc @@ -14,168 +14,26 @@ Complete these procedures: . xref:tut-af-integrate-am-flights.adoc[] . xref:tut-af-integrate-connect-to-a-db.adoc[] -[[snippets]] -== Create a User Snippet for the Transformation - -Define snippets in the `mule-xml.json` file. For information about snippets, see xref:work-with-code-snippets.adoc[]. - -// Pointer to Configure Snippets -include::partial$acb-reusable-steps.adoc[tags="configure-user-snippets"] -. In the *Select Snippets File or Create Snippets* field that opens, enter: -+ -[source,command] ----- -mule-xml.json (Mule XML) ----- -. If the file has no configurations, `mule-xml.json` provides comments within curly braces: -+ -[source,json] --- -{ - // Place your snippets for mule-xml here. Each snippet is defined under a snippet name and has a prefix, body and - // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: - // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the - // same ids are connected. - // Example: - // "Print to console": { - // "prefix": "log", - // "body": [ - // "console.log('$1');", - // "$2" - // ], - // "description": "Log output to console" - // } -} --- -. Add this snippet code to the file: -+ -[[collapsible]] -[source,json] ----- -{ - "Transform Message": { - "prefix": "muledx:transform-message", - "body": [ - "", - " ", - " ", - " ", - " ", - " ", - "" - ] - }, - "Mule Flow": { - "prefix": "muledx:flow", - "body": [ - "", - "", - "" - ] - }, - "HTTP Listener Config": { - "prefix": "muledx:http-listener-config", - "body": [ - "", - " ", - "" - ] - }, - "HTTP Listener": { - "prefix": "muledx:http-listener", - "body": [ - "" - ] - }, - "Set Payload": { - "prefix": "muledx:set-payload", - "body": [ - "" - ] - }, - "Set Variable": { - "prefix": "muledx:set-variable", - "body": [ - "" - ] - }, - "Logger": { - "prefix": "muledx:logger", - "body": [ - "" - ] - }, - "Database Config - MySQL": { - "prefix": "muledx:db-config-mysql", - "body": [ - "", - " ", - "" - ] - }, - "Database Select": { - "prefix": "muledx:db-select", - "body": [ - "", - " ", - " ", - " ", - "" - ] - } -} ----- -+ -The snippets provide starting configurations for several Mule components, including Transform Message. -. Proceed to <>. - [[return-payload]] == Return the Payload as JSON . In Anypoint Code Builder, open `american-ws-anypoint-code-builder.xml`. -. From the canvas, insert the snippet `Transform Message` below the *Database Select* operation. -+ -After the listener, click the image:icon-plus.png["",15,15] (*Add component*) icon and navigate to *Snippets* > *User Snippets* > *Transform Message*. +. From the canvas, add a *Transform Message* component after the *Database Select* operation. + -If the *User Snippets* panel is empty at first, wait a moment, and try again. Alternatively, navigate to the `muledx:transform-message` snippet from the configuration XML: +After the listener, click the image:icon-plus.png["",15,15] (*Add component*) icon and add a *Transform Message* component. +. Enter this DataWeave script into the script editor: + -//TODO: image seems out of date; where's the plus icon? -image::transform-with-output-json.png["Transform component highlighted"] -+ -.User snippet XML: -[source,xml] +[source,dataweave] ---- - - - - - - - +%dw 2.0 +output application/json +--- +payload ---- -. In the configuration XML, add the `doc:name` value *Transform Message* or similar to the `` component: + ----- - -... ----- -. Within `` add a DataWeave script that outputs the message payload to a JSON format: +The `payload` variable holds the output from the previous component, which in this case is the array of flight data from the *Database Select* operation. + -[source,dataweave] --- - - - - - - - --- +. Use the *Preview* tab to see the JSON output. . Deploy your app within the IDE by selecting *Run* > *Start Debugging (F5)*. + For guidance, see xref:tut-af-integrate-am-flights.adoc#run[Run Your App in Debug Mode].