In this step, you will add functionality to generate a credit score for the loan applicant.
To generate the credit score, you will use an in-house, legacy credit scoring application. (The legacy application is already running on WebLogic Server as part of the Workshop sample domain: this is the server you selected when you created the Tutorial: Java Control application.) To make this legacy application available to other components, it has been exposed through a Java messaging service (JMS). You will send an XML message to the credit scoring application containing loan applicant data, and receive an XML message containing a credit score.
Messaging systems are often used to create bridges between otherwise incompatible software components. Messaging is also useful when asynchronous communication is needed, since the requesting component doesn't have to wait for a response in order to continue working. Here, asynchrony is useful because you have no way of knowing how long the credit scoring application will take to respond to your request. For more information about messaging, see Overview: Messaging Systems and JMS.
The tasks in this step are:
Your Java control now includes the creditScoreJMS control, as shown in the following illustration.
To Add Code to Construct an XML Message
The credit score application exposed over JMS is designed to expect an incoming XML message of the following shape.<score_request> <credit_remaining>[integer_value]</credit_remaining> <is_bankrupt>[boolean_value]</is_bankrupt> </score_request>In this task you will add a method that constructs a message of this shape using XMLBeans compiled from the schema file ScoreMessageJMS.xsd, a schema file already included in the Schemas project.
import org.openuri.bea.samples.workshop.ScoreRequestDocument; import org.openuri.bea.samples.workshop.ScoreRequestDocument.ScoreRequest; import org.openuri.bea.samples.workshop.ScoreResponseDocument;Note: these XMLBean classes know how to parse and construct the XML documents that form the JMS traffic between the Investigate Java control and the legacy credit scoring application. These XMLBean classes were produced by the compilation of the schema file ScoreMessageJMS.xsd.
/** * This method uses the XMLBean ScoreRequestDocument (compiled from the XML schema * ScoreMessageJMS.xsd) to construct a string of the following form. * * <score_request> * <credit_remaining>[integer_value]</credit_remaining> * <is_bankrupt>[boolean_value]</is_bankrupt> * </score_request> */ private String makeMessageToJMS(int availableCredit, boolean currentlyBankrupt) { ScoreRequestDocument reqDoc = ScoreRequestDocument.Factory.newInstance(); ScoreRequest req = reqDoc.addNewScoreRequest(); req.setCreditRemaining((short)availableCredit); req.setIsBankrupt(currentlyBankrupt); String str = reqDoc.xmlText(); return reqDoc.xmlText(); }
To Add Code to Invoke the JMS Control
In this task you will add code to invoke the JMS control.public void creditCardReportControl_onCreditCardDataReady(java.lang.String cardData) { try { /* * When a report is delivered, extract the relevant credit card info, * and store it in m_currentApplicant */ CreditCardDataDocument cardInfo = CreditCardDataDocument.Factory.parse(cardData); CustomerType[] customer = cardInfo.getCreditCardData().getCustomerArray(); CardType[] cards = customer[0].getCardArray(); for(int i = 0; i < cards.length; i++) { m_currentApplicant.availableCCCredit += cards[i].getAvailableCredit(); } /* *Send the complete report back to the client.*/ //callback.onCreditReportDone(m_currentApplicant);} catch(XmlException xe) { /* * If there is a problem with extracting the credit card info, * store an error message in m_currentApplicant. */ m_currentApplicant.message = "There was an error retrieving the credit card information. Please call (555) 555-5555 for assistance."; /* * Send an error message back to the client. */ callback.onCreditReportDone(m_currentApplicant); } /* * Construct and send an XML message through the JMS control * to the credit scoring application. */ String messageToJMSControl = makeMessageToJMS(m_currentApplicant.availableCCCredit, m_currentApplicant.currentlyBankrupt); creditScoreJMS.subscribe(); creditScoreJMS.sendTextMessage(messageToJMSControl); }
To Edit the Callback Handler to Parse the XML Response
In this task you will use the XBeans classes to parse the XML response from the JMS control and extract the credit score.
public void creditScoreJMS_receiveTextMessage(java.lang.String payload) { try { /* * Extract the the credit score from the JMS response string * and store it in m_currentApplicant. */ ScoreResponseDocument scoreInfo = ScoreResponseDocument.Factory.parse(payload); m_currentApplicant.creditScore = scoreInfo.getScoreResponse().getCalculatedScore(); /* * Send the complete report back to the client. */ callback.onCreditReportDone(m_currentApplicant); } catch(XmlException e) { m_currentApplicant.message = "There was a problem retrieving the credit score. Please call (555) 555-5555."; /* * Send the the error message back to the client. */ callback.onCreditReportDone(m_currentApplicant); } }
Note: Due to a problem in WebLogic Workshop, before you test the Investigate control again, you may need to dirty the InvestigateTest.jws web service and save it again. This will ensure that the test web service is redeployed to the server and that it exhibits the expected changes. You can do this by simply adding a comment to the source code for InvestigateTest.jws.
Note: Use one of the following (9 digit) taxID's to test your Java control throughout the tutorial:
Click Refresh until callback.onCreditReportDone
appears in the Message Log. Click callback.onCreditReportDone.
Note that a new piece of information appears in the applicant profile:
<creditScore>810</creditScore>. This new piece of information
was returned by the legacy credit scoring application exposed over
JMS.
Click one of the following arrows to navigate through the tutorial: