Java™ Pet Store Demo 1.4 > Configuring the Demo
Java BluePrints

Configuring the Demo

The Java Pet Store Demo allows various behaviors to be configured. This section describes the following customizations:

Connecting to a Different Server/Port

By default, Petstore is set to connect to a server running on localhost at port 8080.   If you've installed the Application Server using a different HTTP Server port than default 8080 port, you must modify runtime XML files to match this modified port value accordingly.

To change the port to which Petstore connects, open the following files in a text editor. (If you edit these files you ensure that each time you rebuild the application, the changes are permanent. However, you must rebuild the application after following these instructions.)

NOTE:  You must do this before you proceed with compiling/deploying. Change all instances of "8080" to match your new default HTTP Server port number used during installation.  Files to be modifed to match your default HTTP Server port number are:

  <petstore.home>/src/components/catalog/src/sun-ejb-jar.xml
  <petstore.home>/src/apps/supplier/src/sun-ejb-jar.xml
  <petstore.home>/src/apps/opc/src/sun-ejb-jar.xml
  <petstore.home>/src/apps/petstore/src/docroot/WEB-INF/sun-web.xml

For example, if you changed default port from 8080 to 80 during installation, look for
the following XML entry in file <petstore.home>/src/apps/petstore/src/docroot/WEB-INF/sun-web.xml

<resource-ref>
<res-ref-name>url/CatalogDAOSQLURL</res-ref-name>
<jndi-name>http://localhost:8080/petstore/CatalogDAOSQL.xml</jndi-name>
</resource-ref>


which needs to be changed to become:

<resource-ref>
<res-ref-name>url/CatalogDAOSQLURL</res-ref-name>
<jndi-name>http://localhost:80/petstore/CatalogDAOSQL.xml</jndi-name>
</resource-ref>

Replace all occurrences of localhost and 8080 with the name of the host and the port on which the server is running in each of these files.





Setting Up E-mail Notifications Using the J2EE SDK Deployment Tool

You can configure the Java Pet Store Demo to send customers e-mail notifications regarding the status of their orders. By default, these notifications are disabled, but you can enable them at deployment time.

To set up e-mail notifications using the J2EE SDK deployment tool , follow these steps:

    Open the OPC EAR (OrderProcessingCenter EAR).
      From the menu, select File -> Open.

      The Open Object dialog appears.

      Find <petstore.home>/opc.ear (or <petstore.home>/src/apps/opc/build/opc.ear if you built the EAR) and click Open Object.

      The OPC EAR appears in the Applications tree on the left panel.

    Enable order approval notifications.
      In the Applications tree on the left panel, select OrderProcessingCenterEAR -> OrderProcessingCenterJAR -> MailOrderApprovalMDB.

      In the inspector on the right panel, select the Env. Entries tab.

      Select the param/SendApprovalMail entry, and set its value to true.

    Enable order confirmation notifications.
      In the Applications tree on the left panel, select OrderProcessingCenterEAR -> OrderProcessingCenterJAR -> MailInvoiceMDB.

      In the inspector on the right panel, select the Env. Entries tab.

      Select the param/SendConfirmationMail entry, and set its value to true.

    Enable order completion notifications.
      In the Applications tree on the left panel, select OrderProcessingCenterEAR -> OrderProcessingCenterJAR -> MailCompletedOrderMDB.

      In the inspector on the right panel, select the Env. Entries tab.

      Select the param/SendCompletedOrderMail entry, and set its value to true.

    Configure the mail service.
      In the Applications tree on the left panel, select OrderProcessingCenterEAR -> MailerJAR -> MailerMDB.

      In the inspector on the right panel, select the Resource Refs tab.

      Select the mail/MailSession entry and edit the deployment settings at the bottom of the panel:

        Change the From field to the e-mail address for the From: header of the confirmation messages.

        Change the Host field to the name of the mail server through which the confirmation e-mails should be sent.

        Change the User Name to the name you use to access the mail server.

    Save your changes.

    From the main menu, select File -> Save.

Setting Up E-mail Notifications by Editing the Deployment Descriptors

To set up e-mail notifications by editing the deployment descriptors , follow these steps:
    Open the OPC application's standard EJB deployment descriptor.

    Using a text editor, open <petstore.home>/src/apps/opc/src/ejb-jar.xml

    Enable order approval notifications.

    Look for these lines:

    <env-entry>
    <env-entry-name>param/SendApprovalMail</env-entry-name>
    <env-entry-type>java.lang.Boolean</env-entry-type>
    <env-entry-value>true</env-entry-value>
    </env-entry>
    Ensure that the env-entry-value entry is set to true .

    Enable order confirmation notifications.

    Look for these lines:

    <env-entry>
    <env-entry-name>param/SendConfirmationMail</env-entry-name>
    <env-entry-type>java.lang.Boolean</env-entry-type>
    <env-entry-value>true</env-entry-value>
    </env-entry>
    Ensure that the env-entry-value entry is set to true .

    Enable order completion notifications.

    Look for these lines:

    <env-entry>
    <env-entry-name>param/SendCompletedOrderMail</env-entry-name>
    <env-entry-type>java.lang.Boolean</env-entry-type>
    <env-entry-value>true</env-entry-value>
    </env-entry>
    Ensure that the env-entry-value entry is set to true .

    Save your changes to the standard EJB deployment descriptor.

    Open the application's build.properties file.

    Using a text editor, open <petstore.home>/src/build.properties .

    Configure the mail service.

    Look for these lines:

    mail.host=localhost
    mail.username=petstore
    mail.fromaddress=petstore@localhost.com

      Change the value of the mail.fromaddress entry to the e-mail address for the From: header of the confirmation messages.

      Change the value of the mail.host entry to the name of the mail server through which the confirmation e-mails should be sent.

      Change the value of the mail.username entry to the name you use to access the mail server.

    Save your changes to the build.properties file.

    Rebuild the OPC EAR.

    If you use the provided build files to rebuild the application, the OPC EAR is placed in <petstore.home>/apps/opc/build/opc.ear and copied to <petstore.home>/ for convience. (For more information on building the application, see Building the Demo.)

After you make your changes, the Java Pet Store Demo sends e-mail notifications the next time you deploy the OPC EAR.

To test the e-mail notifications, visit the Storefront, create a new user with your e-mail address, and complete an order. If the order is approved, you will receive an e-mail. You will receive one or more e-mails as parts of the order are fulfilled. When the order is completely fulfilled, you will receive one final e-mail. (For more information on how orders work in the pet store application, see Using the Demo.)

Adding a New Localization

The Storefront of the Java Pet Store Demo is internationalized, and comes with the English (en) and Japanese (ja) localizations.

To add another localization, follow these steps:

    Add new JSP pages for the locale.

    Place these in the subdirectory <petstore.home>/src/apps/petstore/src/docroot/<locale.code>/ , where <locale.code> is the string representation of the locale.

    For example, the JSP pages for the Japanese localization are located in the directory <petstore.home>/src/apps/petstore/src/docroot/ ja/.

    Create a localized screen definitions file.

    Place the screen definitions (which use your localized JSP pages, of course) in a file called <petstore.home>/src/apps/petstore/src/docroot/WEB-INF/screendefinitions_<locale.code>.xml , where <locale.code> is the string representation of the locale.

    For example, the Japanese screen definitions are stored in <petstore.home>/src/apps/petstore/src/docroot/WEB-INF/screendefinitions_ ja_JP.xml.

    Add new catalog data for the locale.

    The XML file <petstore.home>/src/apps/petstore/src/docroot/populate/Populate-UTF8.xml contains the data used to populate the pet store's database. Localizing the catalog for a particular language involves adding new data to this XML file.

    To support localization, the CategoryDetails, ProductDetails , and ItemDetails elements take a xml:lang locale attribute. Before adding your own localized data, you may find it helpful to refer to the Japanese data in the XML file for examples.

Configuring the Database

The Storefront and Supplier applications in the Java Pet Store Demo can be configured to use a different database from the default one (Pointbase). Using a different database may require different SQL statements (e.g. create table, drop table) from the default ones. These statements can be specified by editing some of the sample application's XML configuration files.

To configure the sample application to use a different database:

  1. Add a new entry to the <petstore.home>/src/apps/petstore/src/docroot/populate/PopulateSQL.xml configuration file.

    Each database for which the sample application is configured has a DatabaseStatements entry, which contains fragments for performing various SQL operations on the application's database tables. For example, here is a fragment from the default (Pointbase) entry:

    <DatabaseStatements database="pointbase">
    <TableStatements table="category">
    <CheckStatement>
    select * from category
    </CheckStatement>
    <CreateStatement>
    create table category (catid char(10) not null,
    constraint pk_category primary key (catid))
    </CreateStatement>
    <InsertStatement>
    insert into category values (?)
    </InsertStatement>
    <DropStatement>
    drop table category
    </DropStatement>
    </TableStatements>
    ...
  2. To create a new DatabaseStatements entry for a different database, it is easiest to copy the default entry and edit the fragments in the new copy. Note that each DatabaseStatements entry has a database attribute uniquely identifying the database to which it belongs. So, before editing the new copy, make sure to change the value of this attribute to a unique identifier. Remember this identifier as you complete the rest of these steps.

    When editing the new DatabaseStatements entry, edit only the fragments. The sample application expects certain elements and attributes in this file. Also, make sure that the parentheses are balanced.

  3. Add a new entry to the <petstore.home>/src/apps/petstore/src/docroot/CatalogDAOSQL.xml configuration file.

    Each database for which the sample application is configured has a DAOStatements entry, which contains fragments for performing select statements on the application's database tables. For example, here is a fragment from the default (Pointbase) entry:

        <DAOStatements database="pointbase">
    <SQLStatement method="GET_CATEGORY">
    <SQLFragment parameterNb="2">
    select name, descn
    from category a, category_details b
    where a.catid = b.catid and locale = ? and a.catid = ?
    </SQLFragment>
    </SQLStatement>
    <SQLStatement method="GET_CATEGORIES">
    <SQLFragment parameterNb="1">
    select a.catid, name, descn
    from category a, category_details b
    where a.catid = b.catid and locale = ? order by name
    </SQLFragment>
    </SQLStatement>

    ...

    To create a new DAOStatements entry for a different database, it is easier to copy the default entry and edit the fragments in the new copy. Note that each DAOStatements entry has a database attribute uniquely identifying the database to which it belongs. So, before editing the new copy, make sure to change the value of this attribute to the unique identifier you chose in step 1.

    When editing the new DAOStatements entry, edit only the fragments. The sample application expects certain elements and attributes in this file. Also, make sure that the parentheses are balanced.

  4. Edit the Storefront's Web deployment descriptor, <petstore.home>/src/apps/petstore/src/docroot/WEB-INF/web.xml .

    Look for the following entry:

    <init-param>
    <param-name>Database</param-name>
    <param-value>pointbase</param-value>
    </init-param>

    Change the value of the param-value sub-entry to the unique identifier you chose in step 1.

    Also look for the following entry:

    <env-entry>
    <env-entry-name>param/CatalogDAODatabase</env-entry-name>
    <env-entry-value>pointbase</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
  5. Change the value of the env-entry-value sub-entry to the unique identifier you chose in step 1.

  6. Edit the catalog component's EJB deployment descriptor, <petstore.home>/src/components/catalog/src/ejb-jar.xml .

    Look for the following entry:

    <env-entry>
    <env-entry-name>param/CatalogDAODatabase</env-entry-name>
    <env-entry-value>pointbase</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
  7. Change the value of the env-entry-value sub-entry to the unique identifier you chose in step 1.

You also have the option of changing the catalog and inventory information used to populate the sample application's database. To modify this data, edit the file <petstore.home>/src/apps/petstore/src/docroot/populate/Populate-UTF8.xml .


Configuring for use with the Oracle Database (using TYPE 4 JDBC driver for Oracle from i-net)


The product application requires the following database setup prior to running:

    Ensure Database Requirements are Met

    See the Application Server Release Notes for database version requirements.

    Register JDBC Driver

    Please refer to Using Oracle with samples for registering Oracle Driver to Application Server.

    Create a new Oracle JDBC Connection Pool

    If you have followed the instructions for Compiling, Assembling and Deploying the Application against the PointBase server then:

Change to the directory <petstore.home>/src

Execute the command:
    asant undeploy

    Edit <install_dir>/samples/database.properties file with correct values for oracle host(oracleInet.host), port(oracleInet.port), sid (oracleInet.dbname), user (oracleInet.user), and password (oracleInet.passwd)
    Set default.database as oracleInet in the same file.

    Execute the command:
    asant deploy


    Otherwise, do the following:

The correct values for Oracle  host (oracleInet.host), port (oracleInet.port), sid (oracleInet.dbname), user (oracleInet.user), and password (oracleInet.passwd)should first be specified in <install_dir>/samples/database.properties
Set default.database as oracleInet in the same file.

    Run the Sample Application
    You may now run the application again using the steps under Running the Sample Application section.

Configuring for Use with Java Enterprise System (JES)

Before deploying or rebuilding this application on an instance of Sun Java System Application Server 8.1 that was installed as part of JES, please follow the steps listed in Section 10 of this file.



Copyright © 2004 Sun Microsystems, Inc. All Rights Reserved.