Debugging the Loan Broker Example Application
This page steps you through a debugging session using the Flow Analyzer screen to track down a logic bug in the simple loan broker example application.
Flow analysis is not available for clusters. It is primarily a development-time tool. However, you can use it on a standalone server running an application that you plan to deploy to a cluster.
As the application developer, you suspect that the program is not returning the bank providing the lowest rate quote. To track this down, you want to focus on the loan-broker-sync flow, since you know that it collects quotes from the different banks and uses some Java code to determine the bank with the lowest rate quote. You are particularly interested in the following program logic in simple loan broker:
- The loan-broker-sync flow does the bulk of the work, receiving customer loan rate requests from a browser, transforming the requests, and passing the request to the appropriate message processors.
- Once the customer is credit approved, the loan-broker-sync flow passes the request to the appropriate banks and collects rate quotes.
- Using the
LowestQuoteProcessorto do the rate comparison, the loan-broker-sync selects the lowest quote from the list and returns the bank and quote to the browser.
You strongly suspect that the error is in the
LowestQuoteProcess.java module. To verify your suspicions, you deploy and run the simple loan broker application and follow the processing via the Flow Analyzer.
As soon as you deploy the simple loan broker application, you use the Flows tab to check that the application is running properly. Then, you set up the Flow Analyzer audit parameters. Since you know the problem is not with the Credit Agency service, you don't include it in the audit trail.
Next, you start testing and submit a loan rate request for $3,675,000 through a browser window, getting back the results indicating that Bank #2 had the best rate, approximately 7.179.
You go to the console Flow Analyzer screen and see that the Message List pane shows the message flow for the loan rate request. You verify that the first invocation of the loan-broker-sync flow received the request amount you entered.
You can see in the Message List that a message for a rate request was sent to two banks: bank1 and bank2. You now check the amounts that the loan-broker-sync flow got back from both bank1 and bank2. You click the loan-broker-sync flow immediately after bank1, then click the outbound message processor in the Message Flow pane. The Before Payload pane shows that Bank 1 returned a rate of approximately 3.308. (You also check the rate returned by Bank 1 by clicking the bank1 flow in the Message List, then the component message processor in the Message Flow pane. You see the same 3.308 rate in the After Payload pane.)
Right away, this doesn't look right, since the application returned a much higher rate from Bank 2. Using the Flow Analyzer screen, you click the bank2 flow, then the component message processor, to check the rate actually returned by Bank 2. The After Payload pane shows that the rate from Bank 2 is indeed 7.179.
Finally, you click the loan-broker-sync flow immediately after the bank2 flow and then check
LowestQuoteProcessor and its message payload. It seems that the
LowestQuoteProcessor processor has an error.
Now that you're confident that the error occurred in
LowestQuoteProcessor, you bring the source into the IDE and go through the code carefully.
Sure enough, you discover that you have an incorrect comparison operator (you used the greater than operator rather than the less than operator) in the following line:
You correct this line, changing the code as follows:
Now you need to verify that you have correctly made the necessary fix. You redeploy the changed simple loan broker application and submit a quote request. This time, you get a rate back from Bank 1 for 4.14.
Using the Flow Analyzer screen, you verify that the loan request amount was received correctly, Then, you check the message payloads for the two banks that processed the rate quote to see what each bank calculated. This time, you see that Bank 1's rate of 4.14 was much lower than Bank 2's rate of 8.10.
You have verified that the loan-sync-broker correctly returned the lower rate quote.
In an environment where applications rely on numerous message processors, the ability to audit flows and get details on message processing and message payloads is invaluable for debugging. The Flow Analyzer screen can provide enormous help in this regard.