The Investigate web service sends callbacks to its clients. But not all clients can hear callbacks, so not all clients can use the Investigate web service as an access point to the Investigate Java control. In this step you will build a synchronous web service interface that allows non-callbackable clients to access the Investigate Java control.
The tasks in this step are:
In this step you will add two member variables to the InvestigateSync web service: one to store the credit report returned by the Investigate Java control, the other to record the status of the investigation process.
/* * m_applicant stores the credit report returned by the Investigate Java control * for retrieval at a latter time by the client. */ public investigateJCS.Applicant m_applicant = new investigateJCS.Applicant(); /* * m_isReportReady is set to true when the credit report from the Investigate Java control * has been received, signaling the client to retrieve the report. */ public boolean m_isReportReady = false;
In this task you will add the methods through which the client will request and collect the credit report from the InvestigateSync web service. These methods are designed to work in the following way: (1) the client invokes the web service's requestCreditReport method. (2) The web service pass the request onto the Investigate Java control and waits for a callback containing the credit report. (3) When the callback from the Investigate Java control arrives the Investigate web service stores the report in the member variable m_applicant and sets m_isReportReady to true. (4) If the client has been checking the value of m_isReportReady (through the isReportReady method), it now knows that it can collect the credit report through the getCreditReport method.
These methods are collectively referred to as "polling logic" because the client polls the methods, asking for the status of the credit report.
/** * Calling this method requests a credit report from the Investigate Java control. * * @common:operation * @common:message-buffer enable="true" * @jws:conversation phase="start" */ public void requestCreditReport(String taxID) { investigateControl.requestCreditReport(taxID); } /** * After making a request for credit report, clients check this method periodically * to see if the report is ready. When this method returns true, clients should invoke * the getCreditReport method to retrieve the credit report. * * @common:operation * @jws:conversation phase="continue" */ public boolean isReportReady() { return m_isReportReady; } /** * Clients collect the completed credit report by invoking this method. * * @common:operation * @jws:conversation phase="continue" */ public investigateJCS.Applicant getCreditReport() { /* * If m_isReportReady is true (i.e., if the callback handler investigateControl_onCreditReportDone * has been invoked) return the results to the client. * If m_isReportReady is false, tell the client to check back later for the results. */ if(m_isReportReady) { return m_applicant; } else { m_applicant.message = "The report is not yet ready. Please check back later."; return m_applicant; } } /** * This method allows the client to cancel the request for a credit report. * * @common:operation * @jws:conversation phase="finish" * @jws:message-buffer enable="true" */ public void cancelInvestigation() { investigateControl.cancelInvestigation(); } /* * When the callback handler is invoked by the Investigate Java control, * store the credit report in the member variable m_applicant * and set m_isReportReady to true. */ public void investigateControl_onCreditReportDone(investigateJCS.Applicant applicantReport) { m_applicant = applicantReport; m_isReportReady = true; }
To Add Code to End the Conversation
There is one problem yet to be solved: how will the web service's conversation ever end, since the client will typically never invoke a method marked with the annotation @jws:conversation phase="finish"? You will solve this problem by adding an API call to the getCreditReport method.
/** * @common:context */ com.bea.control.JwsContext context;
public investigateJCS.Applicant getCreditReport() { /* * If m_isReportReady is true (i.e., if the callback handler investigateControl_onCreditReportDone * has been invoked) return the results to the client. * If m_isReportReady is false, tell the client to check back later for the results. */ if(m_isReportReady) { /* * Calling context.finishConversation ends the current conversation. * * Although the call to context.finishCoversation() appears before the return * statement, it is executed after the return statement. */ context.finishConversation(); return m_applicant; } else { m_applicant.message = "The report is not yet ready. Please check back later."; return m_applicant; } }
The Workshop Test Browser is an appropriate client for testing InvestigateSync.jws because it is a client that cannot hear callbacks from web services.
Note: Use one of the following (9 digit) taxID's to test your web service throughout the tutorial:
Using Polling as an Alternative to Callbacks
Click one of the following arrows to navigate through the tutorial: