Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Anchortoptop

Enterprise Java Beans has been one of the corner stones of the J2EE specification. As a J2EE 1.4 certified application server, Apache Geronimo supports EJB's extensively with the help of OpenEJB EJB Container. Although it is possible to use standard Java objects to contain your business logic and business data, using EJBs addresses many of the issues of using simple Java objects, such as scalability, life cycle management and state management. In this article, you will see how an initial database application is extended and used for both local and remotely referred application clients for an Enterprise Java Beans back end. The application uses inbuilt built-in Apache Derby as its database. Use this article to learn how to simplify your enterprise application development process.

Banking application has two types of application clients namely "Banking Remote Application" and "Banking Web Application". Each of these clients demonstrate how to refer Enterprise Java Beans in remote and local interfaces respectively. Both these clients are referring a common business layer which has been implemented with the help of Session and Entity Beans. Stateless Session Beans are acting as the business service interface between business entities and application clients. All the business entities of the application layer are implemented with the CMP & and BMP Entity Beans. Relations between CMP entities are managed as Container Managed Relations.

After reading this article you should be able get the best out of EJB features of Geronimo, such as defining Enterprise Java Beans, managing relations between them and refer EJB's EJBs via differents different kind of clients.

This article is organized in to following sections.

Overview of EJB Features Anchoroverviewoverview

EJB implementation may vary from one vendor to another. Following The following are the main list of features Apache Geronimo supports as a J2EE container.

  • Stateful and stateless Session Beans
  • BMP (Bean Managed Persistence) Entity Beans
  • CMP (Container Managed Persistence) Entity Beans
  • Message driven beans (MDBs)
  • Interoperability using RMI-IIOP or JAXRPC
  • Ability to expose stateless session beans and MDBs as Web Services
  • Support for sending and receiving messages via Web Services
  • Easy provisioning and hot deployment of EJB and JMX-based Web Services
  • Access to EJBs from external CORBA objects

Application Overview Anchorapplicationapplication

As mentioned above the Banking application supports two types of business application clients. The overview of each client is given below.

  1. Banking Remote Application
    A small swing application client which has more super user capabilities in the banking enviromentenvironment. Only a limited number of banking staff have access to this application. It allows viewing and updating of balance of bank accounts.
  2. Banking Web Application
    This is a Web application open to the Customers. It enables them to view their bank account information. Additionally, users of this application can view the exchange rates given by the bank. For the sake of simplicity, security features of each application will be ignored even though it can be achieved very easily in the context of Geronimo.

...

  • org.apache.geronimo.samples.bank.client
    • MainUI - User interface for the Account Balance Modifier.
  • org.apache.geronimo.samples.bank.dto
    • AccountDTO - Use to transfer Account entity related data between different application layers.
    • ExchangeRateDTO - Transfer ExchangeRate entity related data between different application layers.
  • org.apache.geronimo.samples.bank.ejb
    • AccountBean - CMP Entity Bean, represent account entity related data in the DB.
    • BankManagerFacadeBean - Stateless Session Bean, acting as a service class for different application clients.
    • CustomerBean - CMP Entity Bean, represents customer entity related data.
    • ExchangeRateBean - BMP Entity Bean, represents exchange rate relative to a USD.
  • org.apache.geronimo.samples.bank.util
    • PropertyLoader - Loads configuration properties to the Account Balance Modifier Client.
  • org.apache.geronimo.samples.bank.web
    • CustomerServiceServlet - Dispatches web requests of Customer Account Balance Viewer to the service layer.
    • CommonServiceServlet - Dispatches web requests of Exchange Rate viewing scenario.

Finally, the banking application will be deployed as an EAR to the application server. Overview The overview of the structural content of the EAR file is given in the following example.

...

...

First, we will look at how the business service layer of the application has been implemented with the help of EJBs. In this application enviroment environment all the EJBs are using XDoclet to generate their meta information and their interfaces.

Corresponding openejb-jar.xml defines Geronimo specific features of EJBs. It has both EJB information and their relationships. In addition, it gives a link to the database pool of the application. Entity Beans in the application are dependent on this pool. Also note that the final part of this file defines a 1-N Container Managed Relation (CMR) between Customer and Account Entity Beans.

...

...

BankPool.xml is a typical database pool configuration file, which will be connected to the BankDB defined in through the inbuilt Derby database. Entity beans of the application refer the defined database via this configuration file.

...

geronimo-application.xml and application.xml define the main components of the EAR. Both EJB component and Web archive information are given in these files. Additionally, these two XML files define application scoped database connection pool with tranql-connector-1.2.rar and BankPool.xml.

...

Since Banking Web Application is a part of EAR, the BankManagerFacade Session Bean will be reffered referred as a local interface. Those additional configuration information required for the EJB reference can be found in the web.xml.

...

Account Balance Modifier swing application refers the same BankManagerFacade Session bean as a remotely refer EJB. It's configuration information can be found in the bank_client.properties file.

...

...

...

Always check for the correct network information to run this application client out side of the local computer.

Sample Database

The sample database that is being used to demonstrate this application is inbuilt Derby database. The name of the sample database is BankDB and it consists of three tables, CUSTOMER ,ACCOUNT and EXCHANGE_RATE. The fields for each of these tables are described below.

...

Configuring, Building and Deploying the Sample Application Anchor configureconfigure

Download the bank application from the following link:
Bank

...

After starting Apache Geronimo log into the console and follow the given steps to create the BankDB.

...

  1. Select DB Manager link from the Console Navigation in the left.
  2. Give the database name as BankDB and click Create button.
  3. Select BankDB to the Use DB field.
  4. Open BankDB.sql in the bank/config directory from a text editor.
  5. Paste the content BankDB.sql to the SQL Commands text area and press Run SQL button.

...

Bank application comes with an Ant script to help users to build from source code. It has to be properly configured before using it to build from source code. build.properties file in the config directory has to modify according to your enviroment. Set the correct paths to the xdoclet.home and geronimo.home directories.
Also set the correct network information in the bank_client.properties file, which is going to reffered by remote application client.

...

...

This build script depends on XDoclet version 1.2.3 and Geronimo 1.1.1. Also make sure to use "/" as you directory separator in Windows environment when you are setting the above properties.

...

Building

Use a command prompt to navigate into the bank directory and just give ant command to build. It will create the Bank.ear and bankclient.jar under the bank/releases folder. Also note it will create a lib folder with a list of jar files reffered by the client application. Now, you are ready to deploy bank application in the Geronimo Application server.

...

Testing of the Sample Application Anchortestingtesting

Core business application logic of the banking application is shared between two different clients. Testing of each client is given below.

...

To test the sample web application open a browser and type http://localhost:8080/BankImage Removed. It will forward you to the index page of banking application which has direct links to the view customer and exchange rate information. To view the list of account information of each customer, provide a relavant customer id in the DB. Exchange rate page will display list of all currencies in the exchange rate table.
Image Removed Image Added

Banking Remote Application

Banking remote application client can be run by issuing the ant run-client in a command prompt. Use an existing account number in the database to view it's balance. Modification of account balance can be done by providing a numeric value to the balance field and using the Update button.

Summary Anchorsummarysummary

This article has shown you how to use the EJB features of the Apache Geronimo. It has provided step-by-step instructions to build an application, deploy and run it to elaborate those features.

...