If you already went through the deployment process you can run the application by clicking here.
This sample application illustrates the implementation of a global Container-Managed Transaction (CMT). The application simulates a transfer of funds from one account to another in which the accounts may come from different banks. The transaction is "global" because it involves multiple data sources: a local bank and a foreign bank.
The first page of the application is an HTML form that allows the user to enter the following:
When the user clicks the Transfer Funds button, the GlobalCmtServlet is invoked and it calls GlobalBankServiceEJB.transferFunds( ) to do the following:
The GlobalCmtServlet locates the GlobalBankServiceEJB which performs the following steps in its transferFunds( ) method without explicitly starting a transaction -- the transaction is implicitly started by the container when GlobalBankServiceEJB.transferFunds( ) is called.
This section describes how to register an underlying database driver with iPlanet in the event that a driver was not registered during installation of the application server. The following instructions address only the registration of the database driver. A subsequent section of this document describes how to populate the database tables and register the data sources required by the sample.Determine if the iPlanet Type 2 Driver is Registered
On Windows, the application server automatically detects whether or not drivers for any of the supported databases are available. If a suitable driver is present, the driver will be automatically registered during installation of the application server.On UNIX, if during installation, either "Typical" or "Express" options were selected, JDBC database drivers will not be registered with the application server. If you are unsure as whether or not the client driver was registered, use the application server administrative tool to determine the drivers registered with the application server.
1. Start the application server administrative tool:install_dir/ias/bin/ksvradmin
2. If the application server instance is not listed automatically, connect to your application server instance by selecting File->New->Server. Click on Localhost to specify the default connection settings. Enter the iPlanet Application Server administrator's password and click on OK.3. Click on the Database button and expand the server name (default name of iAS1) to see the database driver settings. If you see a red X on the client driver entry of interest, then you need to run the db_setup.sh script to register the native client driver with the application server. Go to the next section to register the driver.
UNIX: Type 2 Database Driver Registration
2. Execute the database driver registration script:
Select the component you want to install ? (1/2) [1]:
Enter 1 and hit Return or simply hit the Return key.
Enter the Oracle home directory [/usr/oracle/product/8.1.6]:
/usr/oracle/product/8.1.6
Enter the ORACLE_SID [IAS]:
IAS
For example, here is how the Resource Managers are created for the scenario
where the Local Bank database is in an Oracle server called fondue.red.iplanet.com,
and the Foreign Bank database in another Oracle server called nasguru.red.iplanet.com:
How many Resource Managers do you want to configure [1]?
2
Enter Resource Manager Name: [rm1]:
fondue
Enter Database Type: (Oracle) [Oracle]:
Oracle
Construct OpenString:
Please enter database server name: fondue.red.iplanet.com
Please enter database user name: system
Please enter database user password: manager
Enable this Resource Manager (y/n) [y]?
y
Enter Resource Manager Name: [rm2]:
nasguru
Construct OpenString:
Please enter database server name: nasguru.red.iplanet.com
Please enter database user name: system
Please enter database user password: manager
Enable this Resource Manager (y/n) [y]?
y
8. Verify that the database driver was registered, by going through the steps in the previous section, Determine if the iPlanet Type 2 Driver is Registered.
For example, to create a Resource Manager named fondue for an Oracle
database server called fondue.red.iplanet.com:
Note that the Open String for Oracle is in this format:
Oracle_XA+DB=<SERVER_INSTANCE>+Acc=P/<USERNAME>/<PASSWORD>+Sqlnet=<SERVER_INSTANCE>+SesTm=<SESSION_TIME_OUT>+Threads=<IS_THREADSAFE>
IMPORTANT:
To create the catalog tables required for Oracle:
For details on how to set up a resource manager, please refer to the iPlanet Application Server Administration Guide's section on Setting Up Resource Managers for Distributed Transactions.- Navigate to the <ORACLE_HOME>/rdbms/admin directory and find the xaview.sql script:
- Login to Oracle's sqlplus utility as user sys and run the xaview.sql script:
SQL> @xaview
The following example shows how to create 2 new users: localbank and foreignbank using the Oracle SQL Plus utility. It is mandatory that the localbank and foreignbank users be used to create the database tables for this sample application.
To define a new Oracle user called localbank:
SQL > create user localbank identified by localbank;
The first localbank is the user name and the second localbank is the password.
2. Grant connect, resource, and dba privileges to the localbank Oracle user.
SQL> grant connect, resource, dba to localbank identified by localbank;
SQL > create user foreignbank identified by foreignbank;
The first foreignbank is the user name and the second foreignbank is the password.
2. Grant connect, resource, and dba privileges to the foreignbank Oracle user.
SQL> grant connect, resource, dba to foreignbank identified by foreignbank;
Go to the install_dir/ias/ias-samples/transactions/global/schema
directory and find the appropriate file that corresponds to the database of
interest.
The following instructions assume that you have either the Oracle sqlplus facility or the Sybase client software loaded on your system.
1. Ensure that the RDBMS environment variable is set appropriately. For example, ORACLE_HOME or SYBASE.
2. Run setup_localbank_<rdbms type>.sh on Unix or setup_localbank_<rdbms type>.bat on Windows.
Oracle Table Creation and Population
For example, with Oracle, run the setup_localbank_ora.sh
script as shown below:
<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance.
localbank and localbank are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.
<Resource Manager> is the name of the Resource Manager
that is associated with the database server where the Local Database resides.
This must be the same name that was used when a Resource Manager was created
for the Local Database in the previous section, Create
Resource Managers.
Go to the install_dir/ias/ias-samples/transactions/global/schema
directory and find the appropriate file that corresponds to the database
of interest.
The following instructions assume that you have either the Oracle sqlplus facility or the Sybase client software loaded on your system.
1. Ensure that the RDBMS environment variable is set appropriately. For example, ORACLE_HOME or SYBASE.
2. Run setup_foreignbank_<rdbms type>.sh on Unix or setup_foreignbank_<rdbms type>.bat on Windows.
Oracle Table Creation and Population
For example, with Oracle, run the setup_foreignbank_ora.sh
script as shown below:
<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance.
foreignbank and foreignbank are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.
<Resource Manager> is the name of the Resource Manager that is associated with the database server where the Foreign Database resides. This must be the same name that was used when a Resource Manager was created for the Foreign Database in the previous section, Create Resource Managers.
The datasource needs to be registered to the iPlanet Application Server. Go to the directory
install_dir/ias/ias-samples/transactions/global/schema
. Make necessary changes to the and localbank XML datasource files . Here is an example of a datasource file with Oracle as the database (foreignbankdb-ias-ora-type2.xml):
<ias-resource>
</ias-resource>
<resource>
<jndi-name>jdbc/transactions/global/ForeignBankDB</jndi-name>
<jdbc>
<datasource>pusti.world</datasource>
<database>dummy</database>
<username>foreignbank</username>
<password>foreignbank</password>
<driver-type>ORACLE_OCI</driver-type>
<resource-mgr>rm2</resource-mgr>
</jdbc>
</resource>
After modifying the datasource XML files for both localbank and foreignbank to suit your database connection requirements, run the iasdeploy command against each file to register the datasource in the application server.
For example, if you are using Oracle,
1. Go to the directory
install_dir
/ias/ias-samples/transactions/global/schema
.2. Execute the following command to register the JDBC datasources:
iasdeploy regdatasource localbankdb-ias-ora-type2.xml
iasdeploy regdatasource foreigndb-ias-ora-type2.xml
Now that you've registered the JDBC driver and datasources for the sample, you're ready to deploy the application.
Command Line Interface (CLI)-based Deployment describes how to manually register the sample application in iPlanet using a Command Line Interface (CLI). This is the fastest means of deploying the application to the application server.Graphical User Interface (GUI)-based Deployment describes how to use the iPlanet Deployment Tool to import and deploy the sample application. Alternatively, you can also assemble the application from scratch and deploy it using the Deployment Tool.
The transactions-globalcmt.ear file is an Enterprise Archive (EAR) file that contains the Web Archive (WAR) file for the application. Since this application does not have any EJB's, there is no JAR file involved.
Deploying the pre-built transactions-globalcmt.ear file is simple.
1. Go to the root of the application's directory:
install_dir/ias/ias-samples/transactions/global/cmt/2. Execute iasdeploy to deploy the application to the application server:
install_dir/ias/bin/iasdeploy deployapp transactions-globalcmt.ear3. Restart the application server using the iascontrol stop and iascontrol start commands.The deployment process will take 30 seconds to a minute or so to complete.
The deployment process involves the following operations:
iasdeploy authenticates against the local application server's administrative server. the EAR file is transferred to the administrative server. the administrative server begins the registration process: parses the EAR file and embedded WAR and EJB JAR files registers the J2EE application in the iPlanet Registry within the directory server registers the embedded J2EE modules (WARs and EJB JARs) in the iPlanet Registry within the directory server extracts the EJB JAR and WAR modules to the JAR/ directory. expands the content of the J2EE modules to the APPS/transactions-globalcmt directory.
Now that the application has been deployed, proceed to Verifying Registration.
Two approaches to using the Deployment Tool are described:
Import Pre-existing EAR File to quickly deploy the application. None of the application assembly steps are covered by this section. On average, this approach will take 15 minutes.or
Assemble Application from Scratch to learn how to use Deployment Tool to assemble and deploy the application from scratch. On average, this approach will take from 30 to 60 minutes.
1. Launch the Deployment Tool.
UNIX: Execute install_dir/ias/bin/deploytool2. Open the transactions-globalcmt.ear fileWindows: Start->Programs->iPlanet Application Server 6.0->iAS Deployment Tool
To compile the application sources, do the following from the command line:
1. Launch the Deployment Tool:UNIX: Execute install_dir/ias/bin/deploytool&2. Create transactions-GlobalContainerManaged.jar:Windows: Programs->iPlanet Application Server 6.0->iAS Deployment Tool
3. Insert all class files needed in the transactions-GlobalContainerManaged.jar file:
- In the startup dialog, select New EJB Application (.jar file)
- Alternatively, if Deployment Tool is already started, select File -> New.
- Click on EJB JAR Module.
- Enter transactions-GlobalContainerManaged.jar as the File Name.
- Click on Browse to navigate to install_dir/ias/ias-samples/transactions/global/cmt/assemble
- Click on OK to exit the dialog window.
- The EJB JAR module appears in the EJB pane of the Deployment Tool window.
- Click on Component View to see only the name of the EJB JAR module without the directory path.
5. Edit the EJB Descriptor.
- Select transactions-globalcmtEjb from the EJB Modules window and right click. Select Insert (Alternatively, select the module, select Edit->Insert)
- Navigate to this directory:
install_dir/ias/ias-samples/transactions/global/cmt/build/classes/samples/transactions/components- In the left hand pane, select all class files. Click on the right arrow (>) to move the selected files into the right side of the dialog window.
- Navigate to this directory:
install_dir/ias/ias-samples/transactions/global/cmt/build/classes/samples/transactions/global/cmt/ejb- In the left hand pane, select all class files. Click on the right arrow (>) to move the selected files into the right side of the dialog window.
- Click on Resolve to determine if any of the included classes depend on classes that are not part of the EJB JAR module
- Click on Insert to add the classes to the EJB JAR module.
- Since you selected Component View, you'll see the EJB listed in the EJB module window.
- Expand the transactions-globalcmtEjb folder from the EJB Modules window.
- Select the GlobalBankServiceEJB bean, right click and select Edit Descriptor.
- Set EJB Name to samples.transactions.globalbmt.ejb.GlobalBankServiceEJB to insure uniqueness.
- Set Transaction Management to Container. This will enable the Transactions tab.
- Select the Transactions tab and set the Default Transaction Attribute to Supports.
- Click Add at the bottom of the Transactions tab to enter the following information:
Method Transaction Attribute transferFunds( ) Required getFromAccountOldBalance( ) Supports getToAccountOldBalance( ) Supports getFromAccountNewBalance( ) Supports getToAccountNewBalance( ) Supports - Select the References tab from the EJB Descriptor window.
- Enter the following information in the References to Resources section:
Resource Name Description Resource Class Authorization JNDI Name jdbc/transactions/LocalBankDB Local Bank Database javax.sql.DataSource Container jdbc/transactions/global/LocalBankDB jdbc/transactions/ForeignBankDB Foreign Bank Database javax.sql.DataSource Container jdbc/transactions/global/ForeignBankDB Close the EJB Descriptor window by clicking on the X in the upper right hand corner of the window. Click on Yes when asked to save the changes.
1. Create a new WAR file.
2. Insert all class files needed in the WAR file.
- In the startup dialog, select New Web Application (.war file). Alternatively, if Deployment Tool is already started, select File -> New.
- Click on Web Application.
- Enter transactions-globalcmt.war as the File name.
- Click on Browse to navigate to this directory:
install_dir/ias/ias-samples/transactions/global/cmt- Click on the assemble folder and click the OK button to exit the dialog window.
- The WAR file appears in the Web Applications pane of the Deployment Tool window.
- Click on Component View to see only the name of the WAR file without the directory path.
3. Add all JSP and HTML files needed in the WAR file.
- Select transactions-globalcmt from the Web Applications window. Right click and select Insert. Alternatively, select Edit->Insert from the menu bar.
- Navigate to this directory:
install_dir/ias/ias-samples/transactions/global/cmt/build/classes/samples/transactions/global/cmt/servlet- Select all files.
- Click on the right arrow (>) to move all classes into right side of the dialog window.
- Click on Resolve to determine if any of the included classes depend on classes that are not part of the WAR module.
- Click on Insert to add the classes to the WAR module.
4. Edit the Web Application Descriptor.
- Select transactions-globalcmt from the Web Applications window. Right click and select Insert. Alternatively, select Edit->Insert from the menu bar.
- Navigate to this directory: install_dir/ias/ias-samples/transactions/global/cmt/src/docroot
- Select all files.
- Click on the right arrow (>) to move these files into right side of the dialog window.
- Click on Resolve to modify the location of these files relative to the root of the WAR file.
- For each file: click the file name, set the Update Dest. Path to blank since the application requires that these files be located at the root of the WAR module. Click on Update to modify the relative location.
- Click on OK to close the Resolve dialog window.
- Click on Insert to close the insert dialog window and to add the files to the WAR file.
5. Save and close the WAR file.
- Select the transactions-globalcmt WAR file from the Web Applications window. Right click and select Edit Descriptor. Alternatively, select Edit->Edit Descriptor from the menu bar.
- Click on the References tab.
- Click the Add button in the References to EJBs defined elsewhere section.
- Enter the following information:
Reference Linked to Bean Bean Type Bean Home Interface Bean Remote Interface ejb/samples.transactions.global.cmt.ejb.GlobalBankServiceEJB samples.transactions.global.cmt.ejb.GlobalBankServiceEJB Session samples.transactions.global.cmt.ejb.GlobalBankServiceHome samples.transactions.global.cmt.ejb.GlobalBankService Make sure you hit the Return or Enter key after each entry.
- Click on X in the upper right hand corner of the Web App Descriptor window in order to close it. Click on Yes when asked to save the changes.
- Select the transactions-globalcmt file from the Web Applications window.
- Select File->Close from the menu bar and click on Yes when asked to save the changes.
1. Create a new EAR file:
2. Add JAR and WAR files:
- In the startup dialog, select New J2EE Application (.ear file). Alternatively, if Deployment Tool is already started, select File -> New.
- Click on J2EE Application.
- Enter transactions-globalcmt.ear as the File name.
- Click on Browse to navigate to this directory:
install_dir/ias/ias-samples/transactions/global/cmt/assemble- Click on OK to exit the dialog window.
- The EAR file appears in the J2EE Applications pane of the Deployment Tool window.
- Click on Component View to see only the name of the EAR without the directory path.
3. Set Context Root for Web Application
- Select transactions-globalcmt from the J2EE Applications window. Right click and select Insert.
- Navigate to the directory install_dir/ias/ias-samples/transactions/global/cmt/assemble
- Select both transactions-globalcmtEjb.jar and transactions-globalcmt.war files.
- Click on the right arrow (>) to move the file into right side of the dialog window.
- Click on Resolve to modify the location of this file relative to the root of the EAR file.
- Select the file and set the Update Dest. Path to blank since the J2EE modules should appear at the root of the EAR file. Click on Update to modify the relative location.
- Click on OK to close the Resolve dialog window.
- Click on Insert to close the Insert dialog window and to add the files to the EAR file.
Next, we need to set the context root of the web application. This value will appear in URLs that access web application components. For example, in the URL http://localhost/NASApp/transactions-globalcmt/index.html the transactions-globalcmt value is the context root of the web application.
4. Save the EAR file.
- Select the EAR file from the J2EE Applications window. Right click and select Edit Descriptor
- Under the Context Root tab, set both the web application (WAR) name and the context root totransactions-globalcmt
- Close the Application Descriptor window by clicking on the X in the upper right hand corner of the window. Click on Yes when asked to save the changes.
- Select the transactions-globalcmt EAR file from the J2EE Applications window.
- Select File->Save to save the EAR file.
1. Select the transactions-globalcmt EAR file from the J2EE Applications window.2. Select File -> Deploy
3. If you have not already registered a target application server, do so now by clicking on the Register button. Enter the host name, administrative port number and username/password for the target application server. Otherwise, select a pre-registered target server.
Note: You may authorize additional users to deploy applications to an application server server by using the application server's Administrative Console. See the Security settings tab in the Administrative Console.
4. Click on Overwrite modules in case you are repeating the deployment step.
5. Click on Deploy to start the deployment process.
6. Now the file transfer and application registration begins. See the Deploy tab for the status of the deployment. The deployment may take several minutes to complete. Once the status of the deployment changes to Success, proceed to the next step.
7. Restart the application server using the iascontrol stop and iascontrol start commands.
1. Start the Application Server Admin Tool
UNIX: install_dir/ias/bin/ksvradmin2. Connect to your application server instance by selecting File->New->Server. Click on Localhost to specify the default connection settings. Enter the application server administrator's password and click on OK.Windows: Start->Programs->iPlanet Application Server->iAS Administration Tool
3. Select the server name (default name of iAS1) and select the Application button in the top right hand corner of the window to see the applications registered in this instance of the application server.
4.You should see a folder for the transactions-globalcmt J2EE application. The transactions-globalcmt folder with the world icon represents the web application module while the transactions-globalcmtEjb folder represents the EJB module that is packaged as part of the application.
To see more details associated with the application, you can use the Registry Editor tool:
1. Launch the Registry Editor: install_dir/ias/bin/kregedit
2. Navigate to the SOFTWARE/iPlanet/Application Server/6.0/ portion of the tree.
3. Browse the J2EE-Application/ tree and look for the transactions-globalcmt application.
4. Expand the transactions-globalcmt folder and explore this portion of the directory tree.
5. Now open the J2EE-Module/ tree and look for the transactions-globalcmt web application module entry and the transactions-globalcmtEjb EJB module entry.
6. Expand each of these folders and explore their contents.
1. Start the application either by clicking here or, if you've deployed the web server on a separate machine, by accessing:
http://<web server hostname>:<port>/NASApp/transactions-globalcmt/index.html2. Enter a value for Source Bank, Source Account ID, Recipient Bank and Recipient Account ID.
The Local Bank Accounts are listed below:
|
|
|
|
|
|
|
|
|
The Foreign Bank Accounts are listed below:
|
|
|
|
|
|
3. Enter a value for Transfer Amount. This must be a value that is not less than 0. If the Source Account is from a Local Bank, this value must not be more than the Local Account's Maximum Withdrawal Amount.
4. Click on Transfer Funds to execute the transaction.
|
|
Solution |
Please correct your entries. | The values entered in the required fields are either blank or contain incorrect values. | Make sure there is a value for all the required fields.
Transfer Amount must be a number greater than 0. |
Account ID X does not exist. | The value X that was entered for either the Source Account ID or Recipient Account ID is not one of the valid Account ID's listed above. | Make sure that both Source Account ID and Recipient Account ID are in the list of valid Account ID's shown above. |
Cannot withdraw from Source Account: Account has insufficient funds. | The Source Account does not have enough funds to transfer the requested amount to the Recipient Account. | Reduce the Transfer Amount to be less or equal to the Source Account Balance. |
Cannot withdraw from Source Account: Maximum withdrawal amount is 300. | The Transfer Amount exceeds the Maximum Withdrawal Amount that was defined for the Source Account. This only happens when the Source Account is from a Local Bank. Foreign Bank Accounts do not have a maximum withdrawal amount. | Reduce the Transfer Amount to be less or equal to the Account's Maximum Withdrawal Amount. |
For example, to rebuild the entire application from scratch, follow these steps:
1. Compile and Assemble Components and Web ApplicationExecute build in the install_dir/ias/ias-samples/transactions/global/cmt/src directory.
This will compile the source code and rebuild the JAR, WAR and EAR files.
2. Redeploy Application
Execute build deploy in the install_dir/ias/ias-samples/transactions/global/cmt/src directory.
3. Restart the Application Server using iascontrol stop and iascontrol start on the command line.
Copyright (c) 2001 Sun Microsystems, Inc. All rights reserved.