You are viewing an older version of this topic. To go to a different version, use the version menu at the upper-right. +

Stock Quote Example

This example demonstrates how to invoke a Web Service from Mule ESB, transform the result using XSLT, and deserialize the result to a StockQuote Java bean. The application demonstrates the use of REST, SOAP and WSDL to invoke the service. The process is as follows:

  • The application uses an HTTP Inbound Endpoint to receive a query from a user

  • It extracts the quote symbol from the query and invokes the Stock Quote Service with the symbol

  • When the Stock Quote Service replies, the application first transforms the result using the XSLT Transformer, then uses the XML to Object Transformer to transform it to a StockQuote Java bean. 

  • Finally, it sends the quote back to the browser, transforming it back into plain text.


This document assumes that you are familiar with Mule ESB and the Mule Studio interface. To increase your familiarity with Studio, consider completing one or more Mule Studio Tutorials.

This document describes the details of the example within the context of Mule Studio, Mule ESB’s graphical user interface (GUI). Where appropriate, the XML configuration follows the Studio interface screenshot in an expandable section.

Set Up

As with this Stock Quote example, you can create template applications straight out of the box in Mule Studio or Mule Standalone (Mule ESB without Studio). You can tweak the configurations of these use case-based templates to create your own customized applications in Mule.

Follow the procedure below to create, then run the Stock Quote application in Mule ESB.

  1. Complete the procedure in Examples and Exercises to create, then run the Stock Quote template in Mule Studio, or the Stock Quote example in Mule Standalone (Mule ESB without Studio).

  2. Open a Web browser.

  3. Depending on which flavor of the example you want to use, type one of the following URLs into the address bar of your browser, then press enter.

    • http://localhost:48309/stockquote?symbol=IBM&method=REST

    • http://localhost:48309/stockquote?symbol=IBM&method=SOAP

      The last four characters in the URL determine the method the application will use to query the Stock Quote Service. The symbol parameter allows you to choose the stock symbol whose quote you wish to obtain (in the example above, IBM).

  4. Press enter to elicit a response from the application to display data similar to the following:


How it Works

Global Configuration Elements

Some configuration elements for this application are stored in external files. To load the configuration from these files, the application uses Global Elements. To view the Global Elements for the application, click the Global Elements tab under the Studio canvas. The image below highlights the Global Elements tab, and displays the Global Elements configured in this example.

+ global.elements

The first Global Element is a Property Placeholder. It loads the properties contained in a configuration file into the Mule context. To see the configuration for this Global Element, double-click Properties Placeholder in the Global Elements tab.


<context:property-placeholder location=""/>

In this case, the Property Placeholder reads the file (see below).


The next five global elements define the configuration for the transformers. Note that the XSLT transformer references the XSLT file in the application’s xsl subdirectory. The XSLT file can be anywhere on your classpath.


HTTP_input Flow

The HTTP_input flow is the main entry point for queries to this example application. It receives HTTP requests sent to the application’s URL, and determines which subflow to call for processing the request.

+ StockQuote+HTTP+Input

The first building block in the flow, an HTTP Endpoint, receives the HTTP request from the application’s URL. The second building block, a Body to Parameter Map transformer, parses the HTTP request into a map. The flow then uses a Flow Processing Strategy to extract the method from the map (REST, SOAP or WSDL), then call the appropriate subflow for processing.

REST Subflow


The REST subflow uses a Set Payload transformer to extract the value of the stock symbol from the payload. (This value is defined in the URL; in this example the value is IBM.) Subsequently the flow sets the Content-Type property for the payload, which it posts as a form to the REST service using the HTTP Outbound Endpoint. Finally, it decodes the response and applies the XSLT transformation using the rest-stock.xsl file.

SOAP Subflow

This subflow is very similar to the REST subflow except for its service configuration. Instead of using REST, it employs a SOAP Component in the soapClient subflow to invoke the Stock Quote Service with the extracted symbol as parameter.


The second building block in the flow, called Soap Client, is a Flow Reference Component. It invokes the soapClient subflow, which in turn uses an HTTP Endpoint to post the extracted symbol as a form to the Stock Quote Service. The soapClient flow waits for a reply, then forwards it back to the SOAP subflow. The SOAP subflow decodes the reply, then applies the XSLT transformation using the soap-stock.xsl file.

WSDL Subflow

Like the REST and SOAP subflows, the WSDL Subflow uses the Set Payload transformer to extract the value of the stock symbol from the payload. It then uses a Generic Outbound Endpoint to post the request form to the Stock Quote Service.


The Outbound Endpoint in the WSDL subflow uses the wsdl-cxf prefix in its configured address. The limitation of this approach is that it only supports handling primitive data types. The correct approach in a real-life scenario is to use jaxws-client or simple-client as the address prefix.