Beehive Sample: Petstore
Introduction
The Petstore sample demonstrates how to integrate all three Beehive technologies (Page Flows, Controls and Web Services) in one application.
The Page Flows provide customers with web access to the Petstore. There are separate Page Flows for different customer activities: the 'shop' Page Flow (located at: petstoreWeb/shop/) lets users browse the catalog of pets, the 'checkout' Page Flow (petstoreWeb/checkout) lets users purchase selected items from a shopping cart, etc.
The Web Service provides employee access to the Petstore. Through the web service (located at petstoreWeb/WEB-INF/src/PetstoreInventoryManager.jws) employees can update the current inventory and prices displayed to customers through the web site. A Swing client for the web service is provided in the sample Petstore Dashboard.
Most of the Page Flows have associated Control files (located at: petstoreWeb/WEB-INF/src/org/apache/beehive/samples/petstore/controls/). The Controls handle the backend data traffic and encapsulate the operations of the web application, such as retrieving data from a database and handling user orders.
Petstore Directory Structure
The table below describes the functions of the most important files in the Petstore web application.
Directory | Description |
---|---|
petstoreWeb | |
account | Page Flow (=Controller.jpf + JSP files) user interface for managing user accounts. |
auth | Page Flow user interface for managing login and logout. |
checkout | Page Flow user interface for managing the shopping cart. |
search | Page Flow user interface for searching the Petstore. |
shop | Page Flow user interface for browsing the catalogue of pets. |
site | Contains the Petstore "skin", including the CSS file, HTML frameset, and template file. |
webappRoot | |
WEB-INF | Contains configuration files for deployment, validation, and security (web.xml). |
lib | JAR resources |
lib/PetstoreInventoryManager.jws | Web service for employee access to the store |
src/.../controls | Beehive Controls encapsulating different functionalities, including handling user account data, catalogue data, and order processing. |
src/.../forms | Form Beans: each form bean is a server-side representation of an HTML form appearing in the user interface. |
src/.../model | Java object classes used by the Controls. |
Running the PetStore Sample on Tomcat 5
The following explains how to run the Petstore sample on Tomcat 5. The Petstore sample will run on other web containers, but we have chosen Tomcat 5 for convenience.
To Set up the Environment
Before proceeding, complete all of the necessary and optional steps in the following topic: Beehive Installation and Setup
Open a command shell and confirm that you have the following variables have been set:
- ANT_HOME
- JAVA_HOME
- CATALINA_HOME
Also ensure that the following elements are on your PATH:
- ANT_HOME/bin
- JAVA_HOME/bin
To Copy the Petstore Application to a Project Folder
To keep your Beehive distribution directory pristine, you should copy the petstoreWeb folder to another location before proceeding. The following instructions assume that you have copied the folder petstoreWeb into the directory C:/beehive_projects, resulting in the following directory structure.
C: beehive_projects petstoreWeb
Edit the build.properties File
In this section you will edit the build.properties file--the file that sets the build-related properties for your web application.
Open the file C:/beehive_projects/petstoreWeb/WEB-INF/src/build.properties in a text editor.
Edit the file so that the beehive.home property points to the top-level folder of your beehive installation. For example, if you beehive installation resides at C:/apache/apache-beehive-1.0, then your build.properties file would appear as follows.
beehive.home=C:/apache/apache-beehive-1.0 servlet-api.jar=${os.CATALINA_HOME}/common/lib/servlet-api.jar jsp-api.jar=${os.CATALINA_HOME}/common/lib/jsp-api.jar context.path=petstoreWeb
To Compile the Petstore Application
To compile the Petstore app, enter the following Ant command:
ant -f C:\beehive_projects\petstoreWeb\WEB-INF\src\build.xml clean build Copy and Paste version: ant -f C:\beehive_projects\petstoreWeb\WEB-INF\src\build.xml clean build
To Start Tomcat
To start Tomcat, run the following command:
%CATALINA_HOME%\bin\startup.bat
To Deploy to Tomcat
To deploy the web application, click the following link. We recommend that you open the link in a new browser window. Each time you want to redeploy the application, simply refresh the browser.
This method of application deployment assumes that you have added the manager role to your Tomcat installation. For instructions on adding the manager role, see Beehive Installation and Setup.
If you are prompted for a username/password, enter: manager/manager
(For an explanation of this method of deploying an application to Tomcat, see the Tomcat 5 documentation: Deploy A New Application from a Local Path)