What is covered?
Description
Demonstrates how to use AJAX to communicate from a Mule Service to the browser.
Under the Hood
The interactive HTTP endpoint
The example receives input from a HTTP request at the endpoint http://localhost:11081. This first transforms the request's body to a Map using the HttpRequestToMap transformer. It then calls a Groovy script to crate a CustomerQuoteRequest object from the Map. (Alternatively, the example can receive already constructed CustomerQuoteRequest's athttp://localhost:11080. This isn't used when running the example interactively, but is quite handy for unit testing.) This endpoint contains all the logic for converting between HTTP messages and the objects that the example processes. Note the Groovy transformer, which applies default values for anything not specified in HTTP. HTTP Inbound endpoint
Loan Broker processing
Next the CustomerQuoteRequest is passed to a DefaultLoanBroker instance. Its configuration has bound its CreditAgencyService provider to the endpoint named CreditAgency (http://localhost:18080/mule/TheCreditAgencyService?method=getCreditProfile). The DefaultLoanBroker will call this credit agency to create a credit profile, which will be used to determine which lenders to request loan quotes from and a LoanBrokerQuoteRequest is returned. Calling a Java component
Lenders are called
Now an expression-filter is used to filter out any requests that don't include any lenders (as the example is written, this will never occur) and all other requests are sent, via recipient list router, to all of their specified lenders. These are the endpoints Bank1 through Bank 5, each of which is a CXF JAX-WS client handled by a simple-service that is a JAX-WS service implemented by the class org.mule.example.loanbroker.bank.Bank. These return loan quotes that are sent to the custom message processor org.mule.example.loanbroker.processor.LowestQuoteProcessor, which returns the lowest one. Loan Quote Processing
Final processing
Last, the quotes returned by the lenders are processed by the inbound-endpoint's response transformers. Any errors generated are copied to the main message, and the result is returned to the browser.