package examples.ejb.basic.statelessSession; import java.rmi.RemoteException; import java.util.Properties; import javax.ejb.CreateException; import javax.ejb.RemoveException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; /** * This class illustrates calling a stateless Session Bean and performing * the following exercises: * * * @author Copyright (c) 1998 by WebLogic, Inc. All Rights Reserved. * @author Copyright (c) 1998-2000 by BEA Systems, Inc. All Rights Reserved. */ public class Client { private static final String JNDI_NAME = "statelessSession.TraderHome"; private String url; private String user; private String password; private TraderHome home; public Client(String url, String user, String password) throws NamingException { this.url = url; this.user = user; this.password = password; home = lookupHome(); } /** * Runs this example from the command line. Example: *

* java examples.ejb.basic.statelessSession.Client "t3://localhost:7001" scott tiger *

* The parameters are optional, but if any are supplied, * they are interpreted in this order: *

* @param url URL such as "t3://localhost:7001" of Server * @param user User name, default null * @param password User password, default null */ public static void main(String[] args) throws Exception { log("\nBeginning statelessSession.Client...\n"); String url = "t3://localhost:7001"; String user = null; String password = null; // Parse the command-line parameters switch(args.length) { case 3: password = args[2]; // fall through case 2: user = args[1]; // fall through case 1: url = args[0]; break; } Client client = null; try { client = new Client(url, user, password); } catch (NamingException ne) { System.exit(1); } try { client.example(); } catch (Exception e) { log("There was an exception while creating and using the Trader."); log("This indicates that there was a problem communicating with the server: "+e); } log("\nEnd statelessSession.Client...\n"); } /** * Runs this example. */ public void example() throws CreateException, RemoteException, RemoveException { // create a Trader log("Creating a trader"); Trader trader = (Trader) narrow(home.create(), Trader.class); String [] stocks = {"BEAS", "MSFT", "AMZN", "HWP" }; // execute some buys for (int i=0; i