TraderEJBClient.jws Sample

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

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/ejbControl/

Sample Source Code


01 package ejbControl; 
02 
03 import java.rmi.RemoteException;
04 import examples.ejb20.basic.statelessSession.TradeResult;
05 
06 /**
07  <p>A web service that demonstrates use of the EJB control TraderEJBControl.jcx,
08  * which represents the TraderEJB Stateless Session Bean and exposes its business
09  * interface to web services.</p>
10  * @common:target-namespace namespace="http://workshop.bea.com/TraderEJBClient"
11  */
12 public class TraderEJBClient implements com.bea.jws.WebService
13 
14     /**
15      * @common:control
16      */
17     private ejbControl.TraderEJBControl trader;
18 
19     /**
20      <p>Invokes the target EJB's <b>buy</b> method and returns the result.
21      * Trades are restricted to 500 shares.</p>
22      
23      @return A String describing the result of the transaction.
24      *
25      * @common:operation
26      */
27     public String buy(String tickerSymbol, int numberOfShares)
28     {
29         TradeResult tr;
30         try
31         {
32             tr = trader.buy(tickerSymbol, numberOfShares);
33         }
34         catch (RemoteException re)
35         {
36             return "Error " + re.getLocalizedMessage();
37         }
38         return String.valueOf(tr.getNumberTraded()) " shares of " + tr.getStockSymbol() " bought.";
39     }
40 
41     /**
42      <p>Invokes the target EJB's <b>sell</b> method and returns the result.
43      * Trades are restricted to 500 shares.</p>
44      
45      @return A String describing the result of the transaction.
46      *
47      * @common:operation
48      */
49     public String sell(String tickerSymbol, int numberOfShares)
50     {
51         TradeResult tr;
52         try
53         {
54             tr = trader.sell(tickerSymbol, numberOfShares);
55         }
56         catch (RemoteException re)
57         {
58             return "Error " + re.getLocalizedMessage();
59         }
60         return String.valueOf(tr.getNumberTraded()) " shares of " + tr.getStockSymbol() " sold.";
61     }
62 
63