Stock Quote Example
This example demonstrates how to invoke an ASPX web service from Mule ESB, transform the result using XSLT, and deserialize the result to a StockQuote Java bean. The example demonstrates using REST and Web Services to invoke the service.
The configuration uses the STDIO transport to receive a stock symbol from a user (System.in), invokes the StockQuote service, transforms the result using the XSLT transformer, and then uses the XmlToObject transformer to convert the result into a StockQuote Java bean. The quote is then sent to the output console (System.out).
This page describes how to run the Stock Quote example and walks you through its configuration.
Running the Application
- Make sure you have met the prerequisites and installed Mule according to the Installing Mule instructions.
- At the command line, navigate to the examples/stockquote directory under your Mule home directory.
- Type stockquote.bat on Windows or ./stockquote on UNIX.
- Follow the on-screen prompt to choose whether to run the REST, SOAP, or WSDL example.
- When prompted for a stock symbol, type ibm and press Enter. The stock information is displayed.
- To stop Mule, type 'CTRL-C' in the Mule console window.
How it Works
This section walks through the configuration of the REST version of the Stock Quote example, but the Web Service configuration is very similar. Assuming you've already seen the Echo Example, this section will discuss the configuration without going into step-by-step detail.
First, because the proxy settings are in an external properties file, we specify the file in the Mule context:
<context:property-placeholder location="proxy.properties"/>
Next, we configure the HTTP connector with the properties whose values are defined in the proxy.properties file:
<http:connector name="HttpConnector"
proxyHostname="${proxyHostname}"
proxyPassword="${proxyPassword}"
proxyPort="${proxyPort}"
proxyUsername="${proxyUsername}"/>
The next section is the configuration for the transformers. There are four transformers, which will be chained together. Note that the XSLT transformer references the XSLT file in the xsl subdirectory under the stockquote directory. The XSLT file can be anywhere on your classpath.
<xm:xml-to-object-transformer name="XmlToObject"/>
<xml-entity-decoder-transformer name="XmlDecoder"/>
<xm:xslt-transformer name="Xslt" xsl-file="xsl/rest-stock.xsl"/>
<object-to-string-transformer name="ToString"/>
Next, we set up a model as a container for the one service in this example: HTTPPostSample. This service receives messages sent to vm://stockquote and transforms them using all four transformers before passing them to the component.
<model name="Sample-Rest">
<service name="HTTPPostSample">
<inbound>
<vm:inbound-endpoint path="stockquote"
responseTransformer-refs="ToString XmlDecoder Xslt XmlToObject"/>
</inbound>
<http:rest-service-component
serviceUrl="http://www.webservicex.net/stockquote.asmx/GetQuote"
httpMethod="POST">
<http:payloadParameterName value="symbol"/>
</http:rest-service-component>
</service>
</model>
The component is the REST service component, which uses the REST service wrapper to proxy a REST service to act like a local Mule component. The REST service wrapper has a number of properties configured. The serviceUrl is the URL of the REST service to invoke. The payloadParameterName is the name of the parameter to associate with the message payload. In this case, we have only one parameter name, "symbol". The httpMethod can either be GET or POST.
The Web Service Version
The Web Service version works very similarly to the REST version but has different service configuration. The Web Service version explicitly configures an outbound pass-through router that that takes the input from one endpoint and passes it directly to the outbound Axis endpoint with no component in the middle. Instead, the outbound endpoint is configured with parameters that map to the Stock Quote service.
<model name="Sample-SOAP">
<service name="serviceProxy">
<inbound>
<vm:inbound-endpoint path="stockquote"
responseTransformer-refs="ToString XmlDecoder Xslt XmlToObject"/>
</inbound>
<outbound>
<pass-through-router>
<axis:outbound-endpoint address="http://www.webservicex.net/stockquote.asmx?method=GetQuote"
responseTransformer-refs="XmlDecoder Xslt XmlToObject"
soapAction="[methodNamespace][method]">
<axis:soap-method method="qname{GetQuote:http://www.webserviceX.NET/}">
<axis:soap-parameter parameter="symbol" type="string" mode="IN"/>
<axis:soap-parameter parameter="GetQuoteResult" type="string" mode="OUT"/>
</axis:soap-method>
</axis:outbound-endpoint>
</pass-through-router>
</outbound>
</service>
</model>