EJB Hotel Enquiry and Reservation Application

Table Of Contents 

Overview of the application

This sample application implements the Hotel Reservation System(HRS) using an Enterprise Java Bean(EJB) component. The application implements an EJB component, HotelSystemBean which is used by the client application, to perform hotel reservation and enquiry on all the hotels in the system.

The EJB component uses SQLJ to perform database access.

In this sample, two clients have been implemented,
  - A servlet based thin Web Client
  - A Java application GUI client

Both the clients use the same HotelSystemBean EJB.

This sample application illustrates EJB features such as :
  - EJB component location and instantiation.
  - Calling methods on an EJB component from a client application.
  - A Servlet client that accesses EJB deployed to Oracle9iAS in the J2EE framework.
  - A Java GUI client that accesses EJB deployed to Oracle9iAS in the J2EE framework.

  In this example, we will be creating EAR (Enterprise ARchive) file that will be deployed to Oracle9iAS.

 

Required Software

The software required for running the sample are : 

  • Oracle9iAS (9.0.3.0.0) Containers for J2EE or later, downloadable from here
  •  Oracle9i JDeveloper 9.0.3, dowloadable from here
    or
    Ant Version 1.5.1 or later downloadable from here 
  • Oracle9i Database Release 9.0.2 or later, downloadable from here
  • Oracle9i Travel Schema, downloadable from here

Notations Used

This following notations are used through out this document
 

Notation

Description

<OC4J_HOME>

Folder where OC4J is installed. For example, D:\oc4j

<J2EE_HOME>

Folder where J2EE setup is installed. For example, D:\oc4j\J2EE\HOME

<SAMPLE_HOME>

Folder where OneEJBHotel sample will be unzipped. For example, C:\Samples

<JAVA_HOME>

Folder where JAVA is installed. For example, C:\jdk1.2

<ORACLE_HOME>

Folder where Oracle database is installed. For example, c:\Oracle9i

<ANT_HOME>

Folder where the ANT is installed. For example, C:\ant

Extracting the source code

Execute the following command to extract the sample application
 
> jar xvf OneEJBHotel.jar

The above command extracts all the sample files to OneEJBHotel folder. Click here to view the directory structure and description of sample files.
     

Configuring the application

Preparing the Database

Ensure that 'Travel Schema' is loaded into the database. For more details about loading the Travel Schema Click here.

Deploying the application using Oracle9i JDeveloper

This section describes the steps required in deploying this application to the Standalone OC4J using Oracle9i JDeveloper

Step 1. Open <SAMPLE_HOME>\OneEJBHotel\OneEJBHotel.jws in Oracle9i JDeveloper. The workspace contains three projects viz. OneEJBHotel.jpr, Client.jpr, Web.jpr .

Step 2. Ensure that the following libraries have been added to the respective projects.(To add a library to a project, right click on the project name from the System Navigator and select Project Settings -> Development -> Libraries. Then include the libraries in the "Available" list to "Selected" list.)

Project Name

Libraries

OneEJBHotel.jpr

JDeveloper Runtime, J2EE, Oracle9iAS,SQLJ Runtime, Oracle JDBC

Web.jpr

JDeveloper Runtime, J2EE, Oracle9iAS, Servlet Runtime

Client.jpr

JDeveloper Runtime, J2EE, Oracle9iAS

Step 3. Edit config.properties available in <SAMPLE_HOME>\OneEJBHotel\config directory. Change the JNDI parameters based on your system settings. Save the changes made.

Step 4. Create a Database Server Connection

Select Database Server under the Connections Node.
Right click on Database Servers and select "New Connection".
i) In Step 1 of the wizard, enter the Connection Name as 'Travel'.
ii) In Step 2 of the wizard, provide 'travel' as user name and password for the travel schema. (by default travel).
iii) In Step 3 of the wizard, provide the appropriate database connection information where travel schema is loaded.
iv) In Step 4 of the wizard, test the connection and select 'Finish' button.

Step 5. Create an Application Server Connection. From System Navigator, Connection ->Application Server. Right click on Application server, click on New Connection. The Application Server Connection wizard starts. Provide appropriate connection parameters of the Application server to which you wish to deploy the EJBs.

NOTE: To test the application server connection, you need to start OC4J server. Navigate to <J2EE_HOME> and execute the following command:

> java -jar oc4j.jar

Step 6. To deploy Enterprise Archive (EAR), Web Archive (WAR) file to OC4J server, from System Navigator, go to Web.jpr->OneEJBHotel-Web.deploy. Right click on OneEJBHotel-Web.deploy. Click on Deploy to <Your_Application_Server_Connection>.

Where <Your_Application_Server_Connection> refers to the connection you have created in Step 5.

 

Deploying the application using ANT

This section describes the steps required in deploying this application to the Standalone OC4J using ANT Tool.

Step 1.  SET Environment Variables

  1. Open the Command Prompt and navigate to <SAMPLE_HOME>\OneEJBHotel directory
  2. Ensure that JAVA_HOME environment variable is pointing to your JDK installation directory
  3. Ensure that <JAVA_HOME>\bin is set in the system PATH
  4. Ensure that <ANT_HOME>\bin is set in the system PATH
  5. Ensure that sqlj.exe available at <ORACLE_HOME>\bin is set in the system PATH

Step 2. To create SQLJ class files, ensure that you have added the following libraries in the CLASSPATH available at the given locations

Library/File Name Available at
translator.jar <OC4J_HOME>\sqlj\lib
runtime12ee.jar <OC4J_HOME>\sqlj\lib
ejb.jar <J2EE_HOME>\lib
classes12dms.jar <OC4J_HOME>\jdbc\lib

Navigate to <SAMPLE_HOME>\OneEJBHotel\src\oracle\otnsamples\OneEJBHotel\ejb directory. Execute the following command :

> sqlj HotelSystemSQLJ.sqlj *java

Step 3. Edit config.properties available at <SAMPLE_HOME>\OneEJBHotel\config. Change JNDI parameters based on your system settings. Save the changes. The default port for ormi for Standalone OC4J is 23791.

Step 4.  To build the .EAR (Enterprise Archive) file, we will use a tool called ant.

The ant tool compiles all the Java files and creates the .jar, .war and finally the .ear files. It does so by taking input from a file called build.xml that contains all the relevant information. The ant output will indicate the success of the operation.

Build the EAR file, navigate to <SAMPLE_HOME>\OneEJBHotel directory, execute ant 

> <SAMPLE_HOME>\OneEJBHotel>ant

Step 5. Ensure that the OC4J server is up. To start the OC4J server, navigate to <J2EE_HOME>, use the following command:

> java -jar oc4j.jar

Having created OneEJBHotel.ear file, to deploy this application to Standalone OC4J using the following command, from <SAMPLE_HOME>/OneEJBHotel directory.
 

> java -jar <OC4J_HOME>\j2ee\home\admin.jar ormi://localhost:23791 admin <oc4j password> -deploy -file <SAMPLE_HOME>\OneEJBHotel\build\OneEJBHotel.ear -deploymentName OneEJBHotel
For example,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -deploy -file C:\samples\OneEJBHotel\build\OneEJBHotel.ear -deploymentName OneEJBHotel

Step 6.  Now, bind the web application using the following command.
 

> java -jar <OC4J_HOME>\j2ee\home\admin.jar ormi://localhost:23791 admin <oc4j password> -bindWebApp OneEJBHotel OneEJBHotel-web http-web-site /OneEJBHotel
For example,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -bindWebApp OneEJBHotel OneEJBHotel-web http-web-site /OneEJBHotel

Now, the application is deployed to the Standalone OC4J. 

Step 7. Add data source to the application by executing the following command, substitute database host name, database listening port and database SID appropriately.
 
> java -jar <OC4J_HOME>\j2ee\home\admin.jar ormi://localhost:23791 admin <oc4j password> -application OneEJBHotel -installDataSource -url jdbc:oracle:thin:@<DB_HOST>:<DB_PORT>:<DB_SID> -location jdbc/TravelCoreDS -username travel -password <schema password> -connectionDriver oracle.jdbc.driver.OracleDriver -className oracle.jdbc.pool.OracleConnectionPoolDataSource 
For example,
> java -jar D:\oc4j\j2ee\home\admin.jar ormi://localhost:23791 admin welcome -application OneEJBHotel -installDataSource -url jdbc:oracle:thin:@demo.oracle.com:1521:orcl -location jdbc/TravelCoreDS -username travel -password travel -connectionDriver oracle.jdbc.driver.OracleDriver -className oracle.jdbc.pool.OracleConnectionPoolDataSource 

 

Running the Servlet Client

Step 1. Ensure that the OC4J server is up. To start the OC4J server, navigate to <J2EE_HOME>, use the following command:
> java -jar oc4j.jar

Step 2. Access the sample using
http://<host_name>:<port>/OneEJBHotel/EJBHotelServlet
http://demo.oracle.com:8888/OneEJBHotel/EJBHotelServlet

where, <host_name> is the machine on which OC4J is running and <port> is Port to which the OC4J server listens to HTTP requests. The default HTTP port is 8888. 

 

Running the Java Client

Ensure that the OC4J server is up. To start the OC4J server, navigate to <J2EE_HOME>, use the following command:
> java -jar oc4j.jar

Using Oracle9i JDeveloper To run the sample right click on Client.jpr and select "Run Client.jpr". This runs OneEJBHotel Java Application.

Using Console

Add the following class libraries to the class path and execute the jar

<J2EE_HOME>/oc4j.jar
<J2EE_HOME>/lib/ejb.jar
<SAMPLE_HOME>/OneEJBHotel/build/Client.jar

Execute the following command:

> java oracle.otnsamples.OneEJBHotel.client.EJBHotelSample

 


Please enter your comments about this sample in the OTN Sample Code Discussion Forum.

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy