Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

Building, Packaging, Deploying, and Running the Application

To build the Duke's Bank application, you must have downloaded and unzipped the tutorial bundle as described in About the Examples. When you install the bundle, the Duke's Bank application files are located in the <INSTALL>/j2eetutorial14/examples/bank/ directory:

/bank
  /provided-jars
- packaged Web client and J2EE application
    containing the enterprise beans and application client
  /sql - database scripts
  /src
    /com - component classes
      /sun/ebank/appclient
      /sun/ebank/ejb
      /sun/ebank/util
      /sun/ebank/web
  /web - JSP pages, images

After you compile the source code, the resulting files will reside in the <INSTALL>/j2eetutorial14/examples/bank/build/ directory.

Setting Up the Servers

Before you can package, deploy, and run the example, you must first set up the PointBase database server with customer and account data, and you must add some resources to the Application Server.

Creating the Bank Database

You create and enter data into the appropriate tables so that the enterprise beans have something to read from and write to the database. To create and populate the database tables, follow these steps:

  1. Start the PointBase database server.
  2. In a terminal window or command prompt, go to the <INSTALL>/j2eetutorial14/examples/bank/ directory and execute the command asant create-db_common. This task invokes the PointBase console tool library to execute the SQL contained in <INSTALL>/j2eetutorial14/examples/bank/sql/bank.sql. The SQL statements in this file delete any existing tables, create new tables, and insert data. The first time the script is run the tables don't exist, so you will see SQL errors. You can just ignore them.

Creating the JDBC Data Source

The Duke's Bank enterprise beans reference the database having the JNDI name jdbc/BankDB. That JNDI name must be mapped to a JDBC data source in the Application Server. You create the data source using the Admin Console following the procedures described in Creating a Data Source. When you create the JDBC data source, name it jdbc/BankDB and map it to PointBasePool.

Adding Users and Groups to the File Realm

To enable the Application Server to determine which users can access enterprise bean methods and resources in the Web client, add users and groups to the server's file security realm using the Admin Console following the procedures described in Managing Users. Add the users and groups listed in Table 36-3.

Table 36-3 Duke's Bank Users and Groups 
User
Password
Group
200
j2ee
bankCustomer
bankadmin
j2ee
bankAdmin

Compiling the Duke's Bank Application Code

To compile the enterprise beans, application client, and Web client, go to the <INSTALL>/j2eetutorial14/examples/bank/ directory of the tutorial distribution and execute the command asant build.

Packaging and Deploying the Duke's Bank Application

The instructions that follow for packaging and deploying Duke's Bank assume that you are familiar with the deploytool procedures for packaging enterprise beans, application clients, and Web applications described in previous chapters of the tutorial. If after following these procedures you have trouble deploying or running the application, you can use the EAR provided in <INSTALL>/j2eetutorial14/examples/bank/provided-jars/ to run the example.

Packaging the Enterprise Beans

  1. Invoke the Enterprise Bean wizard for each entity bean in Table 36-4. For each bean, select Bean-Managed Persistence as the persistence management type and java.lang.String as the primary key class.
    Table 36-4 Entity Beans 
    Entity Bean
    Home Interface
    Local Interface
    Implementation Class
    AccountBean
    AccountHome
    Account
    AccountBean
    CustomerBean
    CustomerHome
    Customer
    CustomerBean
    TxBean
    TxHome
    Tx
    TxBean
  2. The first time you invoke the wizard, create an EJB JAR module named DukesBankEJBJAR in <INSTALL>/j2eetutorial14/examples/bank/. Add the ejb and util packages under <INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/ to the JAR.

  3. For each entity bean, add a resource reference to a data source with coded name jdbc/BankDB. Set the Sun-specific JNDI name to jdbc/BankDB. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.
  4. For each entity bean, set the transaction attributes for all methods to Required, except for the methods listed in Table 36-5, which should be set to Not Supported:
    Table 36-5 Transaction Attribute Settings 
    Entity Bean
    Tx Not Supported Methods
    AccountBean
    getCreditLine
    findByCustomerId
    findByPrimaryKey
    CustomerBean
    remove
    findByLastName
    findByPrimaryKey
    TxBean
    remove
    findByAccountId
    findByPrimaryKey
  5. Invoke the Enterprise Bean Wizard for each of the stateful session beans in Table 36-6.
    Table 36-6 Stateful Session Beans 
    Session Bean
    Home Interface
    Remote Interface
    Implementation Class
    AccountControllerBean
    AccountControllerHome
    AccountController
    AccountControllerBean
    CustomerControllerBean
    CustomerControllerHome
    CustomerController
    CustomerControllerBean
    TxControllerBean
    TxControllerHome
    TxController
    TxBean
  6. For each session bean, add a resource reference to a data source with coded name jdbc/BankDB. Set the Sun-specific JNDI name to jdbc/BankDB. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.
  7. Add EJB references from the session beans to the local entity beans listed in Table 36-7.
    Table 36-7 EJB References to Entity Beans 
    Session Bean
    Coded Name
    Entity Bean Name
    AccountControllerBean
    ejb/account
    ejb/customer
    AccountBean
    CustomerBean
    CustomerControllerBean
    ejb/customer
    CustomerBean
    TxControllerBean
    ejb/account
    ejb/tx
    AccountBean
    TxBean
  8. Save the module.

Packaging the Application Client

  1. Invoke the Application Client wizard.
    1. Create an application client module named DukesBankACJAR in <INSTALL>/j2eetutorial14/examples/bank/.
    2. Add the appclient, util, and ejb/exception packages and the ejb/*/*Controller* home and remote interfaces (AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) under <INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/ to the JAR.
    3. Select appclient.BankAdmin as the application client main class.
  2. Add EJB references to the session beans listed in Table 36-8.
  3. Save the module.
    Table 36-8 EJB References to Session Beans 
    Coded Name
    JNDI Name of Session Bean
    ejb/accountController
    AccountControllerBean
    ejb/customerController
    CustomerControllerBean

Packaging the Web Client

  1. Create a Dispatcher servlet Web component using the Web Component wizard. Create a new Web module containing the component DukesBankWAR in <INSTALL>/j2eetutorial14/examples/bank/.
  2. Add content to the Web module.
    1. Add the web, util, and ejb/exception packages and the ejb/*/*Controller* home and remote interfaces (AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) under <INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank to the module.
    2. Add the template directory, all the JSP pages, the WebMessages*.properties files and tutorial-template.tld under <INSTALL>/j2eetutorial14/examples/bank/build/ to the module.
    3. In the Web module contents editor, drag the files WebMessages*.properties from the context root to WEB-INF/classes.
  3. Set the context root to /bank.
  4. Add the /accountHist, /accountList, /atm, /atmAck, /main, /transferAck, /transferFunds, and /logoff aliases to the Dispatcher component.
  5. Add EJB references to the session beans listed in Table 36-9.
    Table 36-9 EJB References to Session Beans 
    Coded Name
    JNDI Name of Session Bean
    ejb/accountController
    AccountControllerBean
    ejb/customerController
    CustomerControllerBean
    ejb/txController
    TxControllerBean
  6. Add a JSP property group named bank. The property group applies to the URL pattern *.jsp. Add the include prelude /template/prelude.jspf.
  7. Add a context parameter named javax.servlet.jsp.jstl.fmt.localizationContext and value WebMessages.
  8. Add a security constraint.
    1. Select Form Based as the user authentication method. The authentication settings are file for the realm name, /logon.jsp for the login page, and /logonError.jsp for the error page.
    2. Add a security constraint and a Web resource collection. Use the default names provided by deploytool.
    3. Add the URL Patterns /main, /accountList, /accountHist, /atm, /atmAck, /transferFunds, and /transferAck to the Web resource collection.
    4. Select the GET and POST HTTP methods.
    5. Add the security role bankCustomer.
  9. Save the module.

Packaging and Deploying the Application

  1. Create a J2EE application named DukesBankApp in <INSTALL>/j2eetutorial14/examples/bank/.
  2. Add the DukesBankACJAR application client module to DukesBankApp.
  3. Add the DukesBankEJBJAR EJB module to DukesBankApp.
  4. Add the DukesBankWAR Web module to DukesBankApp.
  5. Add the security roles bankAdmin and bankCustomer.
  6. Add the following security settings for the enterprise beans.
    1. AccountControllerBean: In the Security tab, restrict access to users in the bankAdmin security role for the methods setBalance, removeCustomerFromAccount, setCreditLine, setDescription, removeAccount, createAccount, addCustomerToAccount, setBeginBalance, and setType. In the General tab, click the Sun-specific Settings button, and then click the IOR button in the General frame. In the As Context frame, set Required to true.
    2. CustomerControllerBean: In the Security tab, restrict access to users in the bankAdmin security role for the methods getCustomersOfAccount, createCustomer, getCustomersOfLastName, setName, removeCustomer, and setAddress. In the General tab, click the Sun-specific Settings button, and then click the IOR button in the General frame. In the As Context frame, set Required to true.
    3. TxControllerBean: In the Security tab, restrict access to users in the bankCustomer security role for the methods getTxsOfAccount, makeCharge, deposit, transferFunds, withdraw, and makePayment.
  7. Start the Application Server.
  8. Map the bankCustomer role to the bankCustomer group.
  9. Map the bankAdmin role to the bankAdmin group.
  10. Save the application.
  11. Deploy the application. In the Deploy DukesBankApp dialog box, select the Return Client Jar checkbox.

After you have packaged all the modules, deploytool should look like Figure 36-8.

Duke's Bank Modules and Components

Figure 36-8 Duke's Bank Modules and Components

Reviewing JNDI Names

With DukesBankApp selected, click the JNDI Names tab. The JNDI Name column is shown in Figure 36-9. The order may be a little different in your own environment.

Duke's Bank JNDI Names

Figure 36-9 Duke's Bank JNDI Names

A JNDI name is the name the Application Server uses to look up enterprise beans and resources. When you look up an enterprise bean, you supply statements similar to those shown in the following code.

try {
  customerControllerHome =
    EJBGetter.getCustomerControllerHome(); 
  customer = customerControllerHome.create();
} catch (Exception namingException) { 
  namingException.printStackTrace(); 
}

public static CustomerControllerHome
  getCustomerControllerHome() throws   NamingException {
  InitialContext initial = new InitialContext();
  Object objref = initial.lookup(
    CodedNames.CUSTOMER_CONTROLLER_EJBHOME); 

The lookup takes place in the third line of code, in which the getCustomerControllerHome method of com.sun.ebank.utilEJBGetter is called. EJBGetter is a utility class that retrieves a coded JNDI name from com.sun.ebank.util.CodedNames.

In this example, the application client is looking up the coded name for the CustomerController remote interface. BankAdmin (the display name for the main class of the application client) references ejb/customerController, which is the coded name defined in CodedNames for the CustomerController remote interface.

The JNDI name is stored in the J2EE application deployment descriptor, and the Application Server uses it to look up the CustomerControllerBean bean. In Figure 36-9 you see that CustomerControllerBean is mapped to the same JNDI name as is ejb/customerController. It does not matter what the JNDI name is, as long as it is the same name for the remote interface lookup as you use for its corresponding bean. So, looking at the table, you can say that the application client (BankAdmin) looks up the CustomerController remote interface, which uses the JNDI name of CustomerControllerBean, and the Application Server uses the CustomerControllerBean JNDI name to find the corresponding CustomerControllerBean object.

The other rows in the table have the mappings for the other enterprise beans. All of these beans are stored in the JAR file you added to the J2EE application during assembly. Their implementations have coded names for looking up either other enterprise beans or the database driver.

Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

All of the material in The J2EE(TM) 1.4 Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.