Pramati Technologies

Running Sample Applications

Studio includes sample programs for use in learning about developing applications in J2EE environments. These applications provide sample code that can be used to build your own application.

The sample applications provided in Studio are:

This chapter helps run the sample applications provided in Studio.

IBank

Enterprise JavaBeans with version 1.1 and JavaServer Pages are used to create a simple on-line bank application. Use the sample to create an account, transfer amount between accounts, view ledger entries, and view summary of all accounts.

Three enterprise beans - LedgerBean, TransferBean and CheckingBean, are used in this EJB application with a thin HTML client brought about by JavaServer Pages.

Opening the Desk

Open the Desk from the following location <install_dir>/samples/ejb11/BankDesk/BankDesk.dsk. The Desk includes one EJB 1.1 module and one Web Module. The EJB Module contains three enterprise JavaBeans and the Web Module includes a few JSP files. Three archives - java archive (bankEJB.jar), the web archive (bankWeb.war), and the enterprise archive (BankDesk.ear) are also included in the Desk.

Working with the shipped Resource

The sample ships with a resource called demo. The resource is created using Informix Cloudscape database. To view the resource that is shipped with the application, click on Tools > Resources from the main menu.

To work with the resource provided, Informix Cloudscape server should be running. To do this on a Windows platform, run cloudscape.bat available under <install_dir>. Run cloudscape.sh available under <install_dir> on a Unix platform.

Running the .bat or .sh file displays the following messages in the command prompt to show that the server has been started:

java -cp .\server\lib\tp\cloud-
scape.jar;.\server\lib\tp\RmiJdbc.jar; RmiJdbc.R 
JJdbcServer COM.cloudscape.core.JDBCDriver 
[RmiJdbc] Starting Cloudscape RmiJdbc Server Version 
1.7.2 ... 
[RmiJdbc] COM.cloudscape.core.JDBCDriver registered in 
DriverManager 
[RmiJdbc] Binding RmiJdbcServer... 
[RmiJdbc] No installation of RMI Security Manager... 
[RmiJdbc] RmiJdbcServer bound in rmi registry 

Adding resource using other databases

The sample ships with following database script files that create the required tables on Oracle, IBM Informix and MS SQL Server:

To use another database, you may study these scripts and modify or write a suitable script. To execute the scripts and prepare the tables for the application, choose your database and follow these steps:

Oracle

  1. Open SQL*PLUS editor.
  2. Enter the username and password for accessing the database. (Oracle provides scott and tiger as an universal username-password for evaluators of its database product.)
  3. Run the following command from the SQL prompt:
    c:/pramati_studio/samples/oracle_ejb.sql

IBM Informix

  1. Start the SQL Editor.
  2. Connect to the database and run
    c:\pramati_studio\samples\informix_ejb.sql

MS SQL Server

  1. Create database protondemo using SQL Server Enterprise Manager.
  2. Open Query Analyser on SQL Server 7.0 or iSQL on SQL Server 6.5.
  3. Select protondemo as database and run
    c:\pramati_studio\samples\mssql_ejb.sql
  4. Create an ODBC32 data source, protondemo, that connects to protondemo database.

MS Access Server

  1. Create a database protondemo.mdb with protonaccount and protonledger tables.
  2. Create an ODBC32 data source called protondemo and map it to protondemo.mdb.

To add the resource on any other database, follow the given steps

Deploying the Application

To run the application, it needs to be deployed first. The application can be deployed in four ways:

Deploying the application in any one of the above methods starts the Server, if the Server is not up already and deploys the application. In the following documentation, the application is deployed by deploying the modules.

Once both the modules are deployed, the sample application is ready to be accessed by the client.

Accessing the application

To begin executing the application, just right click on bank.jsp node under Web Module and select Run.This brings up the browser, and runs the JSP with the following URL http://127.0.0.1:8181/bankWeb/bank.jsp where bankWeb is the Web Module name and acts as the context root of the application.

From an HTML client, you can create account, transfer fund from one account to another, view ledger entries, and view summary of all accounts.

Numguess

This JSP sample is a simple guess game. A random integer between 1 and 100 is generated, and a guess is submitted via an HTML client. After a comparison, the result is returned to the client, indicating if the guess is less than or greater than the actual number. This operation loops till the guess equals the actual number.

The components used in the sample are

Opening the Desk

Open the Desk from the following location <install_dir>/samples/ejb11/jspDesk/jspDesk.dsk. The jspDesk comprises one Web Module, one war file (jspDeskWeb.war) and one ear file (jspDesk.ear).

Deploying the application

Deploy the application by right clicking on the Web Module, jspDeskWeb and selecting Deploy. This starts the current server, and deploys the application.

Accessing the application

After deploying the application on the current server, right click on the JSP file, numguess.jsp (under the Web Module node in the Explore panel) and select Run. This brings up the browser, and runs the JSP with the following URL http://localhost:8181/jspDeskWeb/numguess.jsp where jspDeskWeb is the Web Module name and acts as the context root of the application.

In the browser that comes up, guess numbers between 1 to 100 till you get the correct number.

Game of Eight

In this sample application, a jumbled magic square of numbers 1 to 8 is ordered using an HTML client. The program checks for the right order every time a tile is moved. When all the tiles are ordered, a winning message, along with the time taken to solve it, is displayed.

The components used in the sample are

Opening the Desk

Open the Desk from the following location <install_dir>/samples/ejb11/jspDesk/jspDesk.dsk. The jspDesk comprises one Web Module, one war file (jspDeskWeb.war) and one ear file (jspDesk.ear).

Deploying the application

Deploy the application by right clicking on the Web Module, jspDeskWeb and selecting Deploy. This starts the current server, and deploys the application on it.

Accessing the application

After deploying the application on the current server, right click on the JSP file, gameofeight.jsp (under the Web Module node in the Explore panel) and select Run.

This brings up the browser, and runs the JSP with the following URL http://localhost:8181/jspDeskWeb/gameofeight.jsp where jspDeskWeb is the Web Module name and acts as the context root of the application. In the browser that comes up, move the tiles to order them.

OrderBook

This sample application demonstrates working with Enterprise JavaBeans with version 2.0 in Studio. Beans, JavaServer Pages and HTML files are used to create a simple on-line application that allows customers to be added, viewed, place orders for books and view the orders placed.

The JavaBeans that are used for the application are

Opening the Desk

Open the Desk from the following location <install_dir>/samples/ejb20/OrderBook/OrderBook.dsk. The Desk includes one EJB 2.0 module, orderApp and one Web Module, OrderAppWeb. Three archives - java archive (orderapp.jar), the web archive (OrderAppWeb.war), and the enterprise archive (OrderBook.ear) are also included in the Desk.

Working with the shipped Resource

The sample ships with a resource called demo. The resource is created using Informix Cloudscape database. To view the resource that is shipped with the application, click on Tools > Resources from the main menu.

To work with the resource provided, Informix Cloudscape server should be running. To do this on a Windows platform, run cloudscape.bat available under <install_dir>. Run cloudscape.sh available under <install_dir> on a Unix platform.

Running the .bat or .sh file displays the following messages in the command prompt to show that the server has been started:

java -cp .\server\lib\tp\cloud-
scape.jar;.\server\lib\tp\RmiJdbc.jar; RmiJdbc.R 
JJdbcServer COM.cloudscape.core.JDBCDriver 
[RmiJdbc] Starting Cloudscape RmiJdbc Server Version 
1.7.2 ... 
[RmiJdbc] COM.cloudscape.core.JDBCDriver registered in 
DriverManager 
[RmiJdbc] Binding RmiJdbcServer... 
[RmiJdbc] No installation of RMI Security Manager... 
[RmiJdbc] RmiJdbcServer bound in rmi registry 

Note: If Cloudscape server is running, it need not be restarted.

Adding resource using other databases

The sample ships with following database script files that create the required tables on Oracle, IBM Informix and MS SQL Server:

To use another database, you may study these scripts and modify or write a suitable script. Refer the iBank documentation to know how to execute the scripts and prepare the tables for the application, after choosing your database. If you have already executed these scripts once for the iBank sample, you need not do it again.

To add the resource on any other database, follow the given steps

Click on Add and Close the Resource Tool once the Data resource has been successfully added.

Deploying the application

To run the application, deploy it first. Deploying the application starts the current server, if the server is not up already and then deploys the application. In the following documentation, the application is deployed by deploying both the modules.

Once both the modules are deployed, the sample application is ready to be accessed by the client.

Accessing the application

To begin executing the application, just right click on index.htm node under Web Module and select Run.This brings up the browser, and runs the HTML with the following URL http://127.0.0.1:8181/OrderAppWeb/index.htm where OrderAppWeb is the Web Module name and acts as the context root of the application.

In the HTML client, try out the following

Placing an order on a product creates an entry for SalesOrder in the database against a CustomerID. Accordingly, LineItem is generated with the OrderID and ProductID. Cancelling an order leads to the deletion of SalesOrder and LineItem from the database.

Stock Market

The sample illustrates implementation of Message Driven Beans in Studio. The sample uses both Publish-Subscribe and Point-to-Point messaging techniques. The application requires both Pramati Server and Pramati Message Server to deploy.

A server (StockServer) receives stock quotes continuously from topic StockMarket on the MessageServer. The Java client, StockServer.java accesses this stock information through the JavaBean, SubscriberBean.java. This bean delivers the client actions (buy/sell) to the resources - BuyQueue and SellQueue on the Message Server.

The beans - BuyAgentMDB.java and SellAgentMDB.java, on receiving these messages update the resource StockMarket, which gets reflected on the java client StockServer.java. Clients subscribe to SellQueue or BuyQueue depending on their action.

The application demonstrates

Opening the Desk

Open the Desk from the following location <install_dir>/samples/ejb20/StockMarket/StockMarket.dsk. The Desk includes one EJB 2.0 Module, mdbsampleapp and one Java Module, JavaModule. Two archives - java archive (mdbsampleapp.jar) and the enterprise archive (StockMarket.ear) are also included in the Desk.

The EJB Module contains three message driven beans:

The Java Module contains a java client, StockServer.java. This is used to provide stock price fluctuations and the company name to subscribers continuously.

Working with the shipped Resource

The sample ships with four JMS resources. To view these resources, click on Tools > Resources from the main menu.

Deploying the application

Pramati Message Server is required to deploy the application. To configure the JMS server, click on Tools > Server Configuration. In the panel that comes up, check the option Start JMS Sever. This operation should be performed before starting the in-built server.

To deploy the application, right click on the EJB Module node in the Explore panel and select Deploy. This deploys the application. The Java client can now access the application.

Accessing the application

To begin executing the application, just right click on the Java client, StockServer.java node in the Explore panel and select Run.This brings up a new panel, and runs the Java Client.

The application displays the stock symbols, and the Price details along with online buying/selling information.

Deploying the application on WebLogic Server

To deploy the application on WebLogic Server, follow the given steps:

  1. Open the Java Client, StockServer.java stored under the Java Module in the Desk.
  2. Remove the comments from the following lines of code
//env.put("java.naming.factory.initial", 
"weblogic.jndi.WLInitialContextFactory"); 
//env.put("java.naming.provider.url", "t3://local-
host:7001"); 
  1. Right click on the Java Module node in the Explore panel and select Properties.
  2. In the Properties panel that comes up, click on the Build tab, and add the weblogic.jar to the classpath.
  3. Configure the WebLogic embedded JMS Server. Refer the chapter, Working with WebLogic Server 6.1 for details.
  4. Select the current server as WebLogic Server.
  5. Deploy the application on WebLogic and run the client

Note: Refer the relevant chapter for details on working with WebLogic Server.


Pramati Technologies  © Copyright   TOCPREVNEXTINDEX