Bank.jws Sample

This topic inludes the source code for the Bank.jws Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/creditReport/

Sample Source Code


01 package creditReport; 
02 
03 /**
04  * Bank.jws is a very simple service for use by the CreditReport.jws sample
05  * service.  Bank simulates a "long-running" procedure by using a timer
06  * to delay its asynchronous response.
07  *
08  * Note that Bank.jws and IRS.jws are identical except for method names
09  * and the default duration of the timer timeout.
10  * @common:target-namespace namespace="http://workshop.bea.com/Bank"
11  */
12 public class Bank implements com.bea.jws.WebService
13 
14     /**
15      * @jc:timer timeout="10 seconds"
16      * @common:control
17      */
18     private com.bea.control.TimerControl timer;
19 
20     /*
21      * Store the customer ID number that is passed in so we can use it in the
22      * asynchronous response.
23      */
24     private String ssn;
25 
26     public Callback callback;
27 
28     public interface Callback
29     {
30         /**
31          <p>onDeliverAnalysis is a callback delivered to the client when
32          * processing is complete.</p>
33          
34          * @jws:conversation phase="finish"
35          */
36         public void onDeliverAnalysis(String result);
37     }
38 
39     /**
40      <p>Starts the asynchronous analysis operation.  When analysis is complete
41      * the onDeliverAnalysis callback will be called.  If cancelAnalysis is
42      * invoked before the results are delivered, results will never be delivered.</p>
43      *
44      * @common:operation
45      * @jws:conversation phase="start"
46      */
47     public void startCustomerAnalysis(String ssn)
48     {
49         /* store the customer ID for later use */
50         this.ssn = ssn;
51         
52         /* 
53          * start the timer, which simulates starting the long-running analysis procedure
54          */
55         timer.start();
56     }
57 
58     /*
59      * Handler for onTimeout events from the "timer" Timer Control.
60      * onTimeout simulates the long-running procedure reaching completion,
61      * so a result is sent to the client via the onDeliverAnalysis callback.
62      */
63     private void timer_onTimeout(long timeout)
64     {
65         /*
66          * Use a completely arbitrary scheme to decide who's approved and
67          * who's not.  Some people think real banks work this way.
68          */
69         if ((ssn.length() 2&& (ssn.charAt(2<= '5'))
70         {
71             callback.onDeliverAnalysis("Approved");
72         }
73         else
74         {
75             callback.onDeliverAnalysis("Denied");
76         }
77     }
78 
79     /**
80      <p>Cancels the analysis.  The onDeliverAnalysis callback
81      * will not be called and the conversation is finished.</p>
82      
83      * @common:operation
84      * @jws:conversation phase="finish"
85      */
86     public void cancelAnalysis()
87     {
88         timer.stop();
89     }
90   
91   
92