CMP Customer Sample Application |
CMP Customer Application
This document describes how to utilize the CMP Customer sample application in conjunction with the Application Server.This sample application document contains the following sections:
- Overview
- Compiling and Assembling the Application
- Deploying the Application
- Configuring Resources
- Running the Sample Application
- Troubleshooting
Overview
The following instructions describe how to assemble and deploy the same EJB to the Application Server and how to access the EJB from a Servlet client using HTTP. Although the client application and EJB offer minimal functionality, this sample should provide you with a basic understanding CMP support in the Application Server.
Compiling and Assembling the Application
To recompile, assemble, and deploy the application, see the Sample Application Build Facility document for details on using a build facility to quickly perform these tasks.To rebuild the entire application from scratch, follow these steps:
- Compile and assemble the J2EE application.
- Execute the asant command under <install_dir>/samples/ejb/cmp/apps/cmpcustomer
- The default target core is executed to rebuild the .jar and .ear files.
- Deploy the application.
- Once you have re-created the sample application from scratch proceed to deploying the Application.
- Clean the application project area.
- Undeploy the application.
Deploying the Application
A pre-built cmpcustomer.ear file is supplied with the application server installation. The pre-built cmpcustomer.ear file is an Enterprise Archive (.ear) file that contains, the EJB .jar file, the web applicatation .war file of the application. Within each file resides the XML deployment descriptor files, application class files, and other content required by the application. You can use the pre-built .ear file to deploy the application. If you want to experience compiling and assembling the application from scratch, follow the instructions in Compiling and Assembling the Application.To deploy the application, the administrative server needs to be running. To start the administrative server if it is not already started:
Select one of the following approaches to deploy the application:
- Command Line-based Deployment describes how to manually register the application using a Command Line Interface (CLI). This is the fastest means of deploying the application.
- GUI Based Deployment describes how to use the Admin GUI to deploy the sample application.
Command Line-based Deployment
Command Line Interface is the fastest means of deploying the application.If you want to deploy through a GUI tool, follow the instructions for GUI Based Deployment. CLI deployment of the application can be done using either the asant script or using the asadmin command.Deployment process includes deploying the application EAR, configuring database and registering required resources to application server. Installation comes with already configured pointbase database. If you choose to use prepopulated pointbase database, you do not need to configure database.
Deploy the Application Using asant
Please start your database server, if not started.If you choose to use the PointBase database, execute the following steps:
- cd <install_dir>/samples/ejb/cmp/apps/cmpcustomer
- Execute the asant deploy command. It is an interactive command that may prompt you for the admin-server host, admin-server port, admin user name, admin password. This also registers the resources to the application server.
Note You must run asant undeploy before redeploying this sample. This will ensure that all modules are undeployed and the resources are disabled.
Deploy the Application File Using the asadmin Command
Now you need to register the resources to the application server. Proceed to Configuring Resources.
- cd <install_dir>/samples/ejb/cmp/apps/cmpcustomer
- Execute the command asadmin deploy --user <user-name> --password <password> --host <hostname> --port <admin server port> cmpcustomer.ear
The deployment process involves the following operations:
If you want to verify the registration of the application, proceed to Verifying Deployment.
- It authenticates against the local application server's administrative server.
- The .ear file is transferred to the administrative server.
- The administrative server begins the registration process:
GUI Based Deployment
Since a pre-built Enterprise Archive (.ear) file for the sample application is included with the application server, you can use the Admin GUI to quickly read in the .ear file and deploy it to the application server.
- Start the admin server if it is not already started. Here are the commands for each platform:
- Unix - Execute the <install_dir>/bin/asadmin start-domain domain1 command.
- Windows - Click "Start->Programs->Sun Microsystems->J2EE 1.4 SDK->Start Default Server" command.
- Open the .ear file.
- Start Admin GUI, by entering URL http://localhost:<admin.port>/asadmin in browser. See replacing "localhost" and <admin.port> note here to determine correct values to use for your environment
- You are prompted to supply the user name and password of the application server. Enter correct values for your installed application server for "User Name:" and "Password:" input fields, then click on the "Login" button.
- In the left-hand frame, click Applications-->Enterprise Applications icon in the tree.
- In the right-hand frame, click on the "Deploy..." button.
- Choose the file to be deployed by clicking on the "Browse..." button, and navigate to select component to deploy (cmpcustomer.ear).
- In the browse dialog, click on the "OK" button.
- In the right-hand frame, click on the "Next" button.
- In the right-hand frame, click on the "OK" button. (Optionally fill in remaining values for application to be deployed)
- In the left hand pane, you will see the newly deployed module's icon in the tree. In the right hand pane you will also see the component listed as deployed.
Now you need to register the resources with the application server. Proceed to Configuring Resources.
This section describes how to create resources required for running cmpcustomer application. You do not need to register them separately when you deploy the application using the asant deploy command. However, the resources can be registered as follows:
- Please start your database server, if not started.
- JDBC Resource and its Associated Connection Pool
- asadmin create-jdbc-connection-pool --host <admin host> --port <admin port> --user <user> --password <password> --datasourceclassname <datasource classname> --property User=pbpublic:Password=pbpublic:<url-property>="<database jdbc url>" cmpcustomer-pool
In case of PointBase, please use DatabaseName as <url-property>. An example of <database jdbc url> is "jdbc\:pointbase\:server\:\/\/localhost\:9092\/sun-appserv-samples".
- asadmin create-jdbc-resource --host <admin host> --port <admin port> --user <user> --password <password> --connectionpoolid cmpcustomer-pool jdbc/cmpcustomer
- Persistence Manager Factory Resource
Running the Sample Application
The application be executed, using web client and using appclient container.
Execute Servlet Client
To run the web application, go to the following URL:
http://<web server hostname>:<port>/customerIf your deployment process was successful, you should be able to access application via URL:
http://localhost:8080/customer
As an optional step, you can use the Application Server Administration GUI Tool to verify that the application has been registered. If you do not want to verify that the application has been registered, proceed directly to Running the Sample Application. To verify the registration of the application, execute the asadmin command to look at applications deployed with a server instance:
- asadmin list-components --user <user> --password <password> --type application
To understand sample application source code better, you can refer to the related javadocs. To generate javadocs run the following command:
After javadocs are generated, you can access them at
- asant javadocs
- or
- asant all
<install_dir>/samples/ejb/cmp/apps/cmpcustomer/javadocs/index.html
Troubleshooting
Make certain that you run the asant undeploy command before redeploying this sample to make sure that all modules are undeployed and the resources are disabled.
If you encounter problems when running the application, review the log files at <install-dir>/domains/<domain_name>/logs/server.log to learn what went wrong.
Copyright © 2004 Sun Microsystems, Inc. All rights reserved.
Last Updated February
12, 2004