...
Enterprise Java Beans has been one of the corner stones in( 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, lifecycle management and state management. In this article, you 'll ( will ) see how an initial database application is extended and used for both locally( local ) and remotely reffered application clients for ( an ) Enterprise Java Beans back end. The application uses inbuilt Apache Derby as ( its )the database. (The banking application example used in this article will guide you on the simplification of your enterprise development process.) 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 one(delete-one) of these clients demonstrate how to refer Entrprise( Enterprise ) Java Beans in remote and local interfaces respectively. Both of(delete-of) these clients are reffering 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 & 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 via different(s) differents kind of clients.
This article is organized in to following sections.
...
As mentioned above the Banking application (delete -of this article)of this article supports two types of business application clients.(The overview of each client is given below) Following are the overview of each client.
- Banking Remote Application
A small Swing swing application client which has more (delete -of) of super user capabilities in the banking enviroment. Only a limited number of banking staff has ( have ) access to this application. It allows to ( viewing and updating of balance of bank accounts) view and update the balance of bank accounts. - Banking Web Application
A This is a Web application that is going to (delete - going to) 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) Geronimo context.
Both of these clients are using (Both clients use ) a common business service layer. Behind that buisiness ( business ) service layer, there are three common business entities appeared ( that appear ) in the banking application - domain Account, Customer and ExchangeRate. Each Customer can have more than one Account while ( an ) Account can only be only owned by one Customer. ExchangeRate represents a rate value given by the bank in (delete -in) relative to a ( relative to the ) USD for ( a ) particular currency.
(The ) Following following figure gives the overall architecture of the banking application.
Application contents
The Banking application consist(s) consists of ( the ) following list of packages and classes.
- 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, represent(s) represents customer entity related data.
- ExchangeRateBean - BMP Entity Bean, represent(s) 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 request(s) requests of Exchange Rate viewing scenario.
Finally ( the ) banking application will be deployed as an EAR to the application server. Overview of the structure's ( 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 all the EJBs are using XDoclet to generate their meta information and most of the interfaces. ejb-jar.xml is a such XDoclet generated file which contains standard information about EJBstheir interfaces.
Corresponding openejb-jar.xml defines Geronimo specific features of EJBs. It has both EJB information and their relationships. In addition , to that (delete - to that) it gives a link to the database pool of the application. Entity Beans in the apllication ( application ) are depending( dependant ) on this pool. Also note ( that the ) final part of this file defines a 1- (to) N Container Managed Relation (CMR) between Customer and Account Entity Beans.
...
geronimo-application.xml and application.xml define the main components of the EAR. Both EJB component and Web archive information are given in this(these) files as usual(delete - as usual)these files. Additionally, these two XML files define Database application scoped database connection pool information 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 as a local interface. Those (The) additional configuration information of EJBs required for the EJB reference can be found in the web.xml.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <welcome-file-list> <welcome-file>/jsp/index.jsp</welcome-file> </welcome-file-list> <servlet> <display-name>CustomerServiceServlet</display-name> <servlet-name>CustomerServiceServlet</servlet-name> <servlet-class>org.apache.geronimo.samples.bank.web.CustomerServiceServlet</servlet-class> </servlet> <servlet> <display-name>CommonServiceServlet</display-name> <servlet-name>CommonServiceServlet</servlet-name> <servlet-class>org.apache.geronimo.samples.bank.web.CommonServiceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CustomerServiceServlet</servlet-name> <url-pattern>/customer_info</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>CommonServiceServlet</servlet-name> <url-pattern>/exchange_rates</url-pattern> </servlet-mapping> <!-- To refer local EJB's --> <ejb-local-ref> <ejb-ref-name>ejb/BankManagerFacade</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeHomeLocal</local-home> <local>org.apache.geronimo.samples.bank.ejb.BankManagerFacadeLocal</local> <ejb-link>BankManagerFacadeBean</ejb-link> </ejb-local-ref> </web-app> |
Account Balance Modifier Swing Application refer(s) swing application refers the same BankManagerFacade Session bean as a remotely (remote) refer (delete - refer) EJB. It's configuration information can be found in the bank_client.properties file.
...
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 consist(s) of following(delete - following) consists of three tables, CUSTOMER ,ACCOUNT and EXCHANGE_RATE. The fields for each of these tables are described below.
...
The CUSTOMER table stores the data related to the customers.It store(s) stores only the identification number and his/her name ( and the name). ACCOUNT table has a unique account number ( for ) to the (delete - to the) identification. Account type and balance are the other information stored. CUSTID_FK is a foriegn key to the Customer table which is the owner of the Account. EXCHANGE_RATE table has a primary key of RATE_ID for an identification. Each record of EXCHANGE_RATE has CURRENCY name and RATE paid by the bank.
...
After decompressing the given file, the bank directory is ( will be ) created.
Configuring
Configuration of the application consists of creating the database and defining the connection pool to access it.
...
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 building(build) from the (delete - the) 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(is this right?) directories.
Also set the correct network information in the bank_client.properties file, which are( is ) going to reffered by remote application client.
...
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 and copy (the)with a list of jar files reffered by the client application. Now, you are ready to deploy bank application in to(delete - to) the Geronimo Application server.
...
Deploying sample application is pretty straight forward as we are going to use the Geronimo Console.
- Travel (Scroll down to ) Deploy New from the Console Navigation ( panel).
- Load Bank.ear from bank/releases folder in to the Archive input box.
- Press Install button to deploy application in the server.
...
Core business application logic of the banking application is shared between two different clients. Testing of each client will be ( is given below) given in below.
Banking Web Application
To test the sample web application open a browser and type http://localhost:8080/Bank. It will forward you in(delete - in) 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.
...
Banking remote application client can be run ( by issuing the )providing java -jar bankclient.jar 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.
Note |
---|
Always consider ( that the ) lib folder inside of(delete - of) releases are a part of this client application.Check your Operating Sytem's security configuration when you are (delete - are) connecting ( connect ) from a remote machine. |
Summary
Anchor | ||||
---|---|---|---|---|
|
This article has shown you how to use the EJB features of the Apache Geronimo. It ( has ) provided a (delete - a) step-by-step instructions to build an application, deploy and run it to elaborate those features.
...
- Apache Geronimo is a J2EE 1.4 Certified application server and it provides all the necessary features to get for Enterprise applications.
- Create and configure Session and Entity Beans (both BMP and CMP).
- Use Container Managed Relations (CMRs) to manage relations between CMP Entity Beans.
- Access defined enterprise level services by different sorts of clients.