|
Download
FAQ History |
|
API
Search Feedback |
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- packaged Web client and J2EE application
/provided-jars
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, imagesAfter 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:
- Start the PointBase database server.
- In a terminal window or command prompt, go to the
<INSTALL>/j2eetutorial14/examples/bank/directory and execute the commandasantcreate-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 itjdbc/BankDBand map it toPointBasePool.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 Group200j2eebankCustomerbankadminj2eebankAdmin
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 commandasantbuild.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
- 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.Stringas the primary key class.The first time you invoke the wizard, create an EJB JAR module named
DukesBankEJBJARin<INSTALL>/j2eetutorial14/examples/bank/. Add theejbandutilpackages under<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/to the JAR.- For each entity bean, add a resource reference to a data source with coded name
jdbc/BankDB. Set the Sun-specific JNDI name tojdbc/BankDB. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.- 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 toNot Supported:- Invoke the Enterprise Bean Wizard for each of the stateful session beans in Table 36-6.
- For each session bean, add a resource reference to a data source with coded name
jdbc/BankDB. Set the Sun-specific JNDI name tojdbc/BankDB. Because you have already added the JDBC resource to the Application Server, you should select the name from the drop-down menu.- Add EJB references from the session beans to the local entity beans listed in Table 36-7.
- Save the module.
Packaging the Application Client
- Invoke the Application Client wizard.
- Create an application client module named
DukesBankACJARin<INSTALL>/j2eetutorial14/examples/bank/.- Add the
appclient,util, andejb/exceptionpackages and theejb/*/*Controller*home and remote interfaces (AccountController,AccountControllerHome,CustomerController,CustomerControllerHome,TxController,TxControllerHome) under<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/to the JAR.- Select
appclient.BankAdminas the application client main class.- Add EJB references to the session beans listed in Table 36-8.
Packaging the Web Client
- Create a
Dispatcherservlet Web component using the Web Component wizard. Create a new Web module containing the componentDukesBankWARin<INSTALL>/j2eetutorial14/examples/bank/.- Add content to the Web module.
- Add the
web,util, andejb/exceptionpackages and theejb/*/*Controller*home and remote interfaces (AccountController,AccountControllerHome,CustomerController,CustomerControllerHome,TxController,TxControllerHome) under<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebankto the module.- Add the
templatedirectory, all the JSP pages, theWebMessages*.propertiesfiles andtutorial-template.tldunder<INSTALL>/j2eetutorial14/examples/bank/build/to the module.- In the Web module contents editor, drag the files
WebMessages*.propertiesfrom the context root toWEB-INF/classes.- Set the context root to
/bank.- Add the
/accountHist,/accountList,/atm,/atmAck,/main, /transferAck,/transferFunds, and/logoffaliases to theDispatchercomponent.- Add EJB references to the session beans listed in Table 36-9.
- Add a JSP property group named
bank. The property group applies to the URL pattern*.jsp. Add the include prelude/template/prelude.jspf.- Add a context parameter named
javax.servlet.jsp.jstl.fmt.localizationContextand valueWebMessages.- Add a security constraint.
- Select Form Based as the user authentication method. The authentication settings are
filefor the realm name,/logon.jspfor the login page, and/logonError.jspfor the error page.- Add a security constraint and a Web resource collection. Use the default names provided by
deploytool.- Add the URL Patterns
/main,/accountList,/accountHist,/atm,/atmAck,/transferFunds, and/transferAckto the Web resource collection.- Select the
GETandPOSTHTTP methods.- Add the security role
bankCustomer.- Save the module.
Packaging and Deploying the Application
- Create a J2EE application named
DukesBankAppin<INSTALL>/j2eetutorial14/examples/bank/.- Add the
DukesBankACJARapplication client module toDukesBankApp.- Add the
DukesBankEJBJAREJB module toDukesBankApp.- Add the
DukesBankWARWeb module toDukesBankApp.- Add the security roles
bankAdminandbankCustomer.- Add the following security settings for the enterprise beans.
AccountControllerBean: In the Security tab, restrict access to users in thebankAdminsecurity role for the methodssetBalance,removeCustomerFromAccount,setCreditLine,setDescription,removeAccount,createAccount,addCustomerToAccount,setBeginBalance, andsetType. 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 totrue.CustomerControllerBean: In the Security tab, restrict access to users in thebankAdminsecurity role for the methodsgetCustomersOfAccount,createCustomer,getCustomersOfLastName,setName,removeCustomer, andsetAddress. 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 totrue.TxControllerBean: In the Security tab, restrict access to users in thebankCustomersecurity role for the methodsgetTxsOfAccount,makeCharge,deposit,transferFunds,withdraw, andmakePayment.- Start the Application Server.
- Map the
bankCustomerrole to thebankCustomergroup.- Map the
bankAdminrole to thebankAdmingroup.- Save the application.
- Deploy the application. In the Deploy
DukesBankAppdialog box, select the Return Client Jar checkbox.After you have packaged all the modules,
deploytoolshould look like Figure 36-8.
![]()
Figure 36-8 Duke's Bank Modules and Components
Reviewing JNDI Names
With
DukesBankAppselected, 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.
![]()
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
getCustomerControllerHomemethod ofcom.sun.ebank.utilEJBGetteris called.EJBGetteris a utility class that retrieves a coded JNDI name fromcom.sun.ebank.util.CodedNames.In this example, the application client is looking up the coded name for the
CustomerControllerremote interface.BankAdmin(the display name for the main class of the application client) referencesejb/customerController, which is the coded name defined inCodedNamesfor theCustomerControllerremote interface.The JNDI name is stored in the J2EE application deployment descriptor, and the Application Server uses it to look up the
CustomerControllerBeanbean. In Figure 36-9 you see thatCustomerControllerBeanis mapped to the same JNDI name as isejb/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 theCustomerControllerremote interface, which uses the JNDI name ofCustomerControllerBean, and the Application Server uses theCustomerControllerBeanJNDI name to find the correspondingCustomerControllerBeanobject.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.
|
Download
FAQ History |
|
API
Search Feedback |
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.