The Pet Store sample application (demo) is a relatively robust, well-documented demonstration of J2EE technology and concepts. It implements MVC (Model-View-Controller) architecture.
The Pet Store demo can allow developers to gain familiarity with J2EE concepts including application portability, a key J2EE design objective.
The Pet Store has been successfully deployed in JBoss PRE 2.1 configured to use Embedded Tomcat and Tomcat 3.2.1/Apache using Sun 1.3 jdk on Linux. The steps provided below apply to JBoss PRE 2.1 since 21st January 2001.
Please post your experiences with deploying the Pet Store in JBoss to the jboss-user mailing list.
The Pet Store implements non-portable security code that works only with the J2EE RI (Reference Implementation) server.
The non-portable code is contained in the J2eeSecurityAdapter class. The JBoss Pet Store patch replaces this class with a JBossSecurityAdapter class that implements the SecurityAdapter interface.
The steps below change the value for securityAdapterClassName in the Pet Store application to use JBossSecurityAdapter.
See the /docs/security.html page in the Pet Store demo for more information.
In order to add new users, you have to configure Tomcat to use a JDBCRealm. See below for details.
You can get the source from Sun's J2EE Download Page. It's in the "J2EE Blueprints" package. Download the 1.1.1 version. Unpack it anywhere. The root directory of the Pet Store demo is referred to below as $PETSTORE.
Running the Pet Store demo in JBoss requires several minor changes to deployment files in the Pet Store application (.ear) file. The patch is currently available in the file section of the manual, it is named petstore-1.1.1-patch.zip.
Copy the patch file to a temporary directory and unzip it. The patch contains a zip file that patches the Pet Store demo.
You need a servlet container to run the petstore. These instructions use Tomcat 3.2.1. You can either use a bundled binary JBoss + Tomcat, or see the instructions to configure JBoss to use Embedded Tomcat in the section called “Tomcat and JBoss - A Full J2EE Stack”.
The Pet Store demo uses the Cloudscape database by default.
The Pet Store demo theoretically should work with just about any JDBC compliant database. However, to avoid problems with SQL syntax doing a Product Search, use Cloudscape if at all possible.
The following step overwrites several files in the Pet Store application sources. You may want to make a separate copy of the JBoss version of the Pet Store.
This step adds the file jboss-web.xml to the WEB-INF directory in petstore.war, modifies the serverType in the web.xml file of that directory to identify the JBoss server to the application, and modifies the application.xml file in the META-INF directory of petstore.ear.
Note: This will overwrite the original web.xml file.
cd $PETSTORE unzip petstore-jboss-mods.zip
Run build.sh or build.bat in the $PETSTORE/src/petstore/src/build directory.
The result is a new petstore.ear in the $PETSTORE/src/petstore/build directory.
This is the file you deploy by copying it to $JBOSS_HOME/deploy
The JBoss Petstore patch file includes the file jboss.jcml. This file defines Pet Store DB Pools for Cloudscape using port 1098.
Cloudscape uses port 1099 by default. JBoss uses port 1099 for JNDI.
If you will be using a different database, you will need to define DB pools appropriate for your database. See Chapter 3., JDBC for details
Modify the Cloudscape startup command to use port 1098.
You do this by adding -port port_number. For example:
java ... RmiJdbc.RJJdbcServer -port 1098 COM.cloudscape.core.JDBCDriver
Whichever product you're using, create a database or instance or schema (the terminology varies) and then run the appropriate script to populate it.
Copy your DB driver JAR to the lib/extdirectory of your JBoss installation ($JBOSS_HOME).
Copy tools.jar from the J2 SDK to the lib/ext directory of your JBoss installation ($JBOSS_HOME).
For Cloudscape, copy cloudscape.jar and RmiJdbc.jar to the lib/ext directory.
Find the following code in the Tomcat server.xml file and comment it out.
<RequestInterceptor className="org.apache.tomcat.request.SimpleRealm" debug="0" />
Add the following code just below the code you commented out.
<RequestInterceptor className="org.apache.tomcat.request.JDBCRealm" debug="99" driverName="COM.cloudscape.coreRmiJdbcDriver" connectionURL="jdbc:rmi://localhost:1098/jdbc:cloudscape:CloudscapeDB" userTable="users" userNameCol="user_name" userCredCol="user_pass" userRoleTable="user_roles" roleNameCol="role_name" connectionName="estoreuser" connectionPassword="estore" />
Make sure the JbossRealm interceptor follows the JDBCRealm definition.
<RequestInterceptor className="org.jboss.tomcat.security.JbossRealm" />
Change to the $PETSTORE directory and run the dbrealm script to set up the default Pet Store user.
The patch contains a tomcat-users.xml file that adds the default Pet Store user. You can copy this file to your $TOMCAT_HOME/conf directory, or add the following line to your existing tomcat-users.xml file.
You don't need to do this if you configure a JDBCRealm as described above.
<user name = "j2ee" password = "j2ee" roles = "customer" />
Start JBoss and copy the new petstore.ear to the deploy directory. You should see JBoss deploy the Pet Store EJBs.
Point your browser to http://your-server-name.your-domain:8080/estore to start the Pet Store.