concept next listing in category mule

appears as: The next listing, next listing, next listing
Mule in Action, Second Edition

This is an excerpt from Manning's book Mule in Action, Second Edition.

Clicking on the Configuration XML tab below the flow will show you the Mule configuration XML that corresponds to this application. The next listing shows what the XML looks like for the flow you developed.

Now that you know how to configure a transformer, let’s have some fun chaining a few of them. You have two choices to chain transformers: you can put them in a flow in the desired order, or you can use the transformer-refs element that will accept a whitespace-separated list of transformer references. Let’s see both styles in action in the next listing.

Let’s now consider a more complex transformation scenario and see how it’s simplified by Mule’s scripting and Groovy support. Prancing Donkey has recently decided to standardize on a canonical XML model to represent order data. The web application used to submit orders, however, is still using a legacy CSV representation. Although the web development team works on refactoring the web application to submit the order as XML data to a JMS queue, you’ve been tasked to find an interim solution. You decide to use a file inbound endpoint and implement a custom transformer to build an XML-order representation from the CSV file. Once the document has been created, it’ll be submitted to a JMS queue for further processing. The next listing shows how an example order is represented as XML.

Listing 4.28. Representing an order as XML
<orders> <order> <subscriberId>409</subscriberId> <productId>1234</productId> <status>PENDING</status> </order> <order> <subscriberId>410</subscriberId> <productId>1234</productId> <status>PENDING</status> </order> <order> <subscriberId>411</subscriberId> <productId>1235</productId> <status>PENDING</status> </order> </orders>

The next listing demonstrates the legacy CSV format you need to convert from, using the same data as listing 4.28.

Listing 4.29. Representing an order as CSV
409,1234,PENDING 410,1234,PENDING 411,1235,PENDING

Start off by writing the script to transform the CSV to XML. You’ll make use of Groovy’s builder functionality to create the XML. This will most likely be a bit too verbose to include directly in the Mule config, so you’ll define it in an external file, as detailed in the next listing.