Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Application Server 7, Enterprise Edition Migrating and Redeploying Server Applications Guide

Chapter 6
Importing 6.5 Applications in
Sun ONE Studio

This chapter describes the use of Sun ONE Studio in migrating the application developed using Sun ONE Application Server 6.5. This chapter gives step-by-step instructions to migrate each component of an application using Sun ONE Studio for Java. The iBank sample that is bundled with Sun ONE Application Server 6.5 is used as an example to demonstrate the steps.

For a detailed specification of the iBank application, see Appendix A, "iBank Application Specification."

Preparing for Migrating the Application

Before you migrate your applications using Sun ONE Studio, perform the following steps to setup your development environment for migration:

  1. Install Sun ONE Application Server 7 EE and Sun ONE Studio for Java 4.0 on your development environment.
  2. For information on installing the Application Server and Sun ONE Studio, see the Sun ONE Application Server Installation Guide.

  3. Extract the application, which is in a zip format in a local directory.
  4. The source for the iBank application (iBank65.zip) can be found at the migration site http://www.sun.com/migration/sunonetools.html. Unzipping the file iBank65.zip would create the following directory structure:

    iBank
    /docroot
    /session
    /entity
    /script

    • /docroot contains HTML, JSPs and Image files in its root. It also contains the source files for servlets and EJBs in the sub-folder WEB-INF\classes following the package structure com.sun.bank.*. A war file is generated through the contents of this directory.
    • /session contains the source code for the session beans following the package structure com.sun.bank.ejb.session. This directory forms the EJB module for the session beans.
    • /entity contains the entity beans following the package structure com.sun.bank.ejb.entity. This directory would form the EJB module for the entity beans.
    • /scripts contain the sql scripts for the database setup.
  5. Setup the schema for iBank application by executing the sql scripts provided in the /scripts folder. These scripts are for oracle database. These scripts creates user and tables and insert data into the tables. Execute the scripts in the following order:
    • 01_iBank_CreateUser.sql
    • 02_iBank_CreateTables.sql
    • 03_iBank_InsertData.sql
    • In order to execute the above scripts, you must have the Oracle database and the SQL command installed on your system.

  6. Start Sun ONE Application Server.
  7. For instructions, see the Sun ONE Application Server Getting Started Guide.

  8. Prepare Sun ONE Studio for assembling and deploying the sample application ‘iBank’.
  9. Invoke Sun ONE Studio tool through the runide.sh file that is stored in the following location:

    Sun ONE App Server_Root/AppServ/Sun ONE Studio forJava_Root/bin

    1. In the explorer window of the IDE, Select the Runtime tab.
    2. Click ‘Server Registry’.
    3. Click ‘installed servers’.
    4. Choose Sun ONE Application Server.
    5. Setup the Admin Server by right clicking on the Sun ONE Application Server node and then selecting ‘Add Admin Server’.
    6. Enter the following details:
      • host - where Sun ONE Application Server is installed. If the application server is installed on your local machine, enter localhost.
      • port number - port number at which the application server can be accessed. The default value of the port number is 4848.
      • username - User name as specified during the installation.
      • password - Password specified during the installation of the application server.
    7. Once the admin server is setup, click on it to install the server instance.
    8. Set the server instance as the default server by right clicking on the server instance and selecting the option ‘Set As Default’.

Migrating the Application Components

This section gives step-by-step instructions to migrate each component of the iBank application.

For information on migrating the deployment descriptors, see"Migrating Deployment Descriptors".

Creating a Web application module in Sun ONE Studio for Java

To create a Web module in Sun ONE Studio for Java, follow the procedure below:

  1. Mount the /docroot directory that contains the source files. To mount the directory in the Sun ONE Studio for Java, select FileSystems Explorer tab in the left pane. Select Mount the FileSystem from the File menu. Choose the directory to be mounted in the Browser dialog box.
  2. Mount the directories containing the EJBs in the source file directory structure, namely, entity and session.
  3. Create an empty directory for the web module in the root directory structure. For example, WarContent.
  4. Mount the newly created directory WarContent.
  5. Convert the FileSystem WarContent into a Web module. Select the mounted directory in the Explorer, right-click and select the option ‘Convert FileSystem to Web Module’ from the Tools sub menu.
  6. Copy the source JSP, HTML and image files to the web application root. i.e., to the directory WarContent from the docroot directory.
  7. Copy servlets and auxiliary class sources to the WEB-INF/classes directory. That is, copy the sub folder com in the docroot directory to the WEB-INF/classes directory.
  8. Copy the tag library present in the WEB-INF of the docroot directory to the WEB-INF of WarContent directory.
  9. Edit the source code wherever required to migrate it to Sun ONE Application Server 7 (if it has not been modified through the migration tool), by following the steps below:
    • Check the JSPs that have to be changed.
    • Check if any custom JSP tags are used in the application.
    • Open the selected JSP code in Sun ONE Studio. To open a JSP file in Sun ONE Studio, select the JSP file in the left pane, right click and select the Open option from the popup menu.
    • Follow the steps given in the section "Migrating Java Server Pages and JSP Custom Tag Libraries" to modify the source.
    • Similarly, migrate the servlets by following the steps given in the section, "Migrating Servlets".
  10. Assemble the application and edit the deployment descriptor web.xml (in the WEB-INF/ directory). Click on the web.xml file and edit the properties of the elements. During this assembly phase, configure each servlet, JSP page and JSP tag library, as well as the EJB or data source references used in the web application.

The following topics describe how you can assemble the web application in Sun ONE Studio for Java:

Configuring a Servlet

To configure a Servlet in the deployment descriptor:

  1. Select the web module from the Warcontent folder. Right click on the web module and select the properties option from the popup menu. The Properties window is displayed.
  2. To configure the servlets, in the Deployment tab, click the Servlets button. The Servlets dialog box is displayed.
  3. Click Add to add servlets. For each servlet in the web application, you specify the name of the servlet, the full name of its implementation class by clicking the Browse button, the mapping elements for the servlet by clicking Mappings, and any initialization parameters.
  4. Figure 6-1  Configuring Servlet
    Figure shows how to configure servlets using Sun ONE Studio.

    The list of servlets and their mappings in iBank application are listed in the table, "Servlets and Mappings." The left column lists the servlet name, the center column lists the display name and the third column on the right lists the mapping.

    Table 6-1  Servlets and Mappings

    Servlet Name

    Display Name

    Mapping

    LoginServlet

    LoginServlet

    /CheckLogin

    CheckTransferServlet

    CheckTransferServlet

    /CheckTransfer

    CustomerProfileServlet

    CustomerProfileServlet

    /CustomerProfile

    DataSourceTestServlet

    DataSourceTestServlet

    /DataSourceTest

    HelloWorldServlet

    HelloWorldServlet

    /HelloWorld

    LookUpDataSourceTestServlet

    LookUpDataSourceTestServlet

    /LookUpDataSourceTest

    ProjectEarningsServlet

    ProjectEarningsServlet

    /ProjectEarnings

    ShowAccountSummaryServlet

    ShowAccountSummaryServlet

    /ShowAccountSummary

    TestContextServlet

    TestContextServlet

    /TestContext

    TransferFundsServlet

    TransferFundsServlet

    /TransferFunds

    UpdateCustomerDetailsServlet

    UpdateCustomerDetailsServlet

    /UpdateCustomerDetails

    Configure all the above servlets such that web.xml has entries for all of them.

    After completing the above steps, the Deployment tab shows 11 servlets mappings and 11 servlets.

Configuring a JSP tag library

To configure a JSP tag library:

  1. In the Deployment tab of the properties window, click the Tag Libraries button. The Tab Libraries dialog box is displayed.
  2. To define a JSP tag library in the web application deployment descriptor, click Add. In the Add Tablig dialog box, enter the URI of the library which is the identifier that the JSP pages will use to access it, and the path to the library's deployment descriptor (.tld file).
  3. In iBank, there is one JSP Tag library TMBHisto.tld. The deployment descriptor is stored under the WEB-INF folder.

    Figure 6-2  Configuring Taglib
    Figure shows Sun ONE Application Server archtiecture.

Add Resource Reference

To add resource reference to the deployment descriptor:

  1. Select the References tab in the Properties window. Click the Resource Reference button.
  2. To add a new resource, click Add. In the Standard tab of the Resource Reference dialog box, enter the details of the resource reference. The following figure shows adding a new resource jdbc/iBank for data source in iBank.
  3. Figure 6-3  Adding Resource Reference
    Figure shows a dialog box to configure a JDBC resource for Sun ONE Application Server using  Sun ONE Studio.

  4. In the Sun ONE App Server tab, set the JNDI name as jdbc/IBank and also set the user name and password depending on the database schema you are using.
  5. Figure 6-4  Adding Resource Reference entry for Sun ONE Application Server
    Figure shows a dialog box to add JDBC resource reference for Sun ONE Application Server using  Sun ONE Studio.

Add Context Parameter

To add a context parameter for the JNDI name to lookup iBank data source:

  1. In the Deployment tab of the Properties window, click the context parameter button. The Add Context Parameter dialog box is displayed.
  2. To add a context parameter, click Add. Enter the details of the context parameter as shown in the figure below.
  3. Figure 6-5  Adding Context Parameter
    Figure shows a dialog box to add a Context Parameter for Sun ONE Application Server using  Sun ONE Studio.

Specify the Welcome File

In the Deployment tab, click the Welcome Files button to specify the welcome files. In case of iBank, index.jsp is the welcome file.

Converting CMP Entity EJBs from 1.1 to 2.0

The iBank application has Entity Beans with CMP 1.1. To convert the entity beans with CMP 1.1 to CMP 2.0, see section on "Migrating CMP Entity EJBs".

The Account entity bean has Enumeration used in its code. The code for this has to be changed manually. This topic discusses the procedure to convert the Account entity bean from CMP 1.1 to CMP 2.0.

The following are the related files for Account entity bean:

Account.java
AccountEJB.java
AccountHome.java
AccountPK.java

The changes that you must carry out in the above mentioned files are described below:

Creating an EJB module in Sun ONE Studio for Java

The following steps describes the procedure to create an EJB module in Sun ONE Studio for Java, using the existing source files:

Creating Module for Session Beans

The folder session contains the following bean classes and the interfaces for the following session beans:

To create a module for the session beans:

  1. In the FileSystems tab of the left pane, select the mounted directory session. Navigate through the com sub folder and select the package session.
  2. Right click on the session package. From the File menu, select the New. In the New Wizard, navigate through the options and select J2EE -> EJB Module.
  3. Specify the main characteristics of the EJB such as, the name of the EJB, the state of the bean, whether stateless or stateful, the package for the EJB. The following figures shows the creation of Session Bean BankTeller which is a Stateful Session bean, whereas, the InterestCalculator session bean is Stateless. Click the browse button to specify the package.
  4. Figure 6-6  Creation of New Session Bean
    Figure shows how to create a Session Bean using Sun ONE Studio for Sun ONE Application Server 7.

  5. To specify the implementation class, the home and the remote interfaces that match the existing source files, use the Modify button in the dialog box and choose "Select an existing source file."
  6. Repeat the steps above to create all the session beans.

    The following figure shows specifying the bean class, the home interface and the remote interface for the session bean. Clicking the modify button and choosing the option to use an existing class, shows the existing files, which can be selected.

    Figure 6-7  Specifying the Bean class, Home Interface and the Remote Interface
    Figure shows how to create a Session Bean’s Bean class, Home and Remote Interface using Sun ONE Studio for Sun ONE Application Server 7.

    Create the InterestCalculator session bean following the above mentioned steps.

  7. Edit the properties of the EJBs.
  8. By editing the properties of an EJB, you can declare the EJB Resource References; specify an EJB's environment entries.

    Figure 6-8  Properties window of the Session Bean BankTeller
    Figure shows the properties of a  Session Bean.

    The following figure shows the declaration of an environment entry for the BankTeller session bean. InterestCalculator bean does not require this entry.

    Click at the Environment Entries in the 'References' tab and then click Add to add a new entry for the Data Source Name.

    Figure 6-9  Adding Environment Entry to BankTeller Session Bean
    Figure shows a Dialog Box to add a Environment  Entry for a session bean using Sun ONE Studio.

    In the references tab of the Properties window for the BankTeller session bean, click Resource Reference to add a new resource. Add a new resource jdbc/iBank for the data source in iBank.

    Select Sun ONE App Server tab to set the JNDI name as 'jdbc/iBank' and username and password depending on the database schema used.

    InterestCalculator bean does not require this entry.

    In the References tab of the Properties window, click the EJB Reference button to add EJB references. The following figure shows adding EJB Reference for the BankTeller session bean. BankTeller session bean has references to the entity bean Account and Customer. You need to add these entity bean references to the BanTeller session bean.

    Specify the Home and Remote interfaces by clicking the modify button and then choosing the existing source for the beans option.

    Figure 6-10  Add EJB Reference
    Figure shows a Dialog Box to create a EJB Reference to a session bean using Sun ONE Studio.

    In the Sun ONE App Server tab in the EJB Reference, specify the JNDI name. The following figure shows the JNDI entry ejb/Account, made for the Account entity bean. Similarly, when the EJB reference for the Customer bean is added, specify the JNDI name in the Sun ONE App Server tab as jndi/Customer.

    Figure 6-11  Adding EJB Reference entry for Sun ONE Application Server
    Figure shows a Dialog Box to add a EJB Reference to Sun ONE Application Server using Sun ONE Studio.

  9. Compile the source files.
  10. Create an EJB module and assemble the EJBs within it.
  11. In accordance with the J2EE 1.3 specification, in Sun ONE Application Server 7 EE, you must group the EJBs together in an EJB module. Create a new EJB module named as SessionModule at the root directory session. To create a new session EJB module, select the session folder. From the File menu, select New -> J2EE -> EJB Module. After creating the module, add the session EJB's into it.

    The figure below shows how the BankTeller and InterestCalculator EJBs are added to an EJB module SessionModule.

    Figure 6-12  Adding Session Beans to EJB Module
    Figure shows how to add a EJB to a EJB Module using Sun ONE Studio.

Creating Module for Entity Beans
  1. The folder for the entity beans contains the bean class, remote and Home interface for the following entity beans:
    • Account
    • AccountType
    • Branch
    • Customer
    • Transaction
    • TransactionType
    • The Customer entity bean is bean managed and others are container managed.

  2. Configure the JDBC driver.
  3. In the Runtime view of the Explorer, navigate through the tree to select the Drivers under Databases. Right click and select the option Add Driver from the pop-up menu. In the Add Driver dialog box, specify the driver name, implementation class, and the prefix of the relevant URL. The corresponding JAR or ZIP for the driver must be accessible to Sun ONE Studio for Java, and must therefore be copied into the Sun ONE Studio for Java Root/lib/ext directory.

    To place the driver classes in the appropriate Sun ONE Studio for Java directory in Solaris, run the following command from the shell (sh or ksh):

    cp $ORACLE_HOME/jdbc/lib/classes12.zip Sun ONE Studio for Java Root/lib/ext

  4. Define the database connection properties
  5. In the Runtime view of the Explorer, select Database. Right click and select the Add Connection... option from the pop-up menu. In the New Database Connection dialog box, specify the driver used, the full connection URL, the user name, the related password, and the appropriate database schema:

    Figure 6-13  Configuring a database connection (Oracle) in Sun ONE Studio for Java
    Figure shows a Dialog Box to configure a database connection in Sun ONE Studio.

  6. Create new EJBs from existing source files.
  7. Select the File Systems tab in the Explorer. Select the mounted directory entity. From the File menu, select New -> J2EE -> CMP Entity EJB. The New EJB wizard is displayed.

    Specify the name of the EJB and define the package for the EJB. Under the Source for Entities and Fields pane, select the option, Table from Database Connection in order to be able to specify the database table to be used for the persistence of the EJB fields.

    Figure 6-14  Creation of an Entity bean with container-managed persistence
    Figure shows a wizard to create and configure CMP Entity bean in Sun ONE Studio.

    In the following Wizard screen, select the right connection from the list of database connections defined. Once the connection is selected, list of tables accessible from this connection are shown, and select the appropriate table:

    Figure 6-15  Choosing a table for mapping CMP bean fields
    Figure shows a wizard to choose and map a database table to CMP Entity bean fields in Sun ONE Studio.

    The next screen is used to the configure mapping between the columns of the table selected and the CMP fields of the bean. Particular care should be taken to correctly indicate the names of the bean fields and associate the Java types.

    Figure 6-16  Mapping between table columns and CMP fields of the bean
    Figure shows the mapping between database table fields and CMP Entity bean fields in Sun ONE Studio.

    The next screen allows you to specifying the source files for the entity bean.

    Figure 6-17  Mapping between table columns and CMP fields of the bean
    Figure shows a wizard to specify the source files for the CMP Entity beans in Sun ONE Studio.

    The next step involves informing Sun ONE Studio for Java that you want to create the EJB from the existing source files, which can be specified by clicking the Modify Class button.

    If you receive any error while pointing to the existing source files, it may have caused because you made a mistake in the previous steps or the source is not migrated properly. Such errors should be handled by making changes as and when reported.

    The next screen shows the process of selecting the existing source file for the EJB bean class.

    Figure 6-18  Specifying EJB Bean class by selecting option for Existing Source files
    Figure shows how to create a Bean class by selecting an existing Bean class.

    Repeat the above steps to create all the entity beans.


    Note

    This might give some errors giving options to select the existing class or using another one, select the 'using same class' option. Sun ONE Studio might show some unexpected results, in such condition, exit Sun ONE Studio and restart the tool.


  8. Edit the properties of the EJBs.
  9. Select the new EJB in the explorer window, right click and select Properties option from the pop-up menu. The Properties window is displayed.

    In the properties window, select the References tab, click on the Resource References button, on the right hand edge of this text field.

    In the Add Resource Reference dialog box, set the following properties for the entity bean Customer.

    In the Standard tab, give the full name of the data source (“jdbc/DataSourceName”) the resource type (javax.sql.DataSource), and select Container from the drop-down list of options for managing access to this resource (Authorization).

    Once the declaration has been made, select the Sun ONE App Server tab, and specify the JNDI name of the data source jdbc/iBank in the JNDI Name column of the entry that corresponds to the resource reference defined previously. Also specify the username and the password.

    In the properties window select the Sun ONE AS tab, click on the Reference Resource Mapping and choose the data source i.e, jdbc/IBank on the server instance which has to be used.

    Figure 6-19  Resource Reference Mapping for Sun ONE Application Server
    Figure shows the mapping of a resource reference to Sun ONE Application Server.

  10. Set EJB QL for finders other than the findByPrimaryKey method.
  11. EJB QL has to be specified for finders. As per the CMP 2.0 specification, the finders will use EJB QL.

    In the iBank application, the entity bean that would require this type of editing is the Account bean. Select the AccountEJB node in the Sun ONE Studio explorer window and expand the finder methods in it. Click on any finder method other than the findByPrimaryKey to open its properties window:

    Figure 6-20  Properties of Finder Method
    Figure shows the properties of a Finder Method.

    Click the EJBQL Query field to enter the query. The following figure shows the query entered:

    Figure 6-21  Editing EJB QL for the Finder
    Figure shows a Dialog box where you can edit EJB QL script..

  12. Create an EJB module and assemble the EJBs within it.
  13. Create new EJB module named EntityModule and add all entity beans into this module by right clicking on the EJB module and selecting the option to add the EJBs. As per the J2EE 1.3 specification, you must group EJBs together in a EJB module.

  14. Create a new Database Schema.
  15. From the File menu select new and then select new Database Schema. Provide the connection information for the database from which the schema has to be captured.

  16. Map the database entries for Sun ONE Application Server 7.
  17. Select an EJB node in the EJB module, right click the node to choose the properties window and select Sun ONE AS tab. Specify the database schema and the primary table name for this particular entity bean. Repeat the process for other entity beans in the EJB module.

    The following figure shows the selection of primary table for the entity bean Account.

    Figure 6-22  Database Mapping
    Figure shows the mapping between a Bean and the Database.

    Click Next for specifying the mappings for the cmp fields of bean with the table fields.

    Now select the Sun ONE Mapping tab from the Properties window and re-enter the mappings.

    The following figure shows the mappings for the Account EJB.

    Figure 6-23  Properties of entity bean ‘Account’
    Displas the properties of entity bean Account

    Similarly, set the mappings for all the entity beans.

    See "Defining Entity Bean Relationships" for the details on the mapping of a particular entity bean to a corresponding database table field.

  18. Add a CMP resource.
  19. Select EntityModule and view its properties. Select the Sun ONE AS tab, and now click the CMP Resource button to configure the persistence manager factory.

    The following figure shows the configuration:

    Figure 6-24  Adding CMP Resource
    Figure shows the property editor for a CMP resource.

Creating an Enterprise Application in Sun ONE Studio for Java

After creating the Web application and the EJB files, the next step is to create an enterprise application, which groups all the modules together. The process for creating an enterprise application is as follows:

  1. Create a new enterprise application module in a new directory say 'IBank' under the same package available for the source.
  2. Add the Web module and EJB modules to the enterprise application module.
  3. The following figures show an enterprise application called iBank, containing a Web module called WarContent and an EJB module called SessionModule and EntityModule.

    Figure 6-25  Adding Modules to the Application
    Figure shows how to create a application in Sun ONE Studio and add EJB, Session and WEB modules to the application.

    The following figure shows the application iBank having 3 modules in it.

    Figure 6-26  File System showing Application ‘iBank’ having different modules
    Figure shows the iBank application file system having different modules.

  4. Edit the enterprise application properties.
  5. The property editor allows you to set the different properties of the enterprise application module. In particular, this is where the root context name is defined for the web module of the enterprise application:

    Figure 6-27  Specifying the Web Context
    Figure shows how to specify the Web Context.

  6. Export the EAR file.
  7. Export the EAR file by right clicking the enterprise application and selecting the option for exporting the EAR file. This EAR file contains JAR files, a WAR file, and XML files. This EAR file has all the Sun ONE specific XML files required for the deployment on Sun ONE Application Server 7. This EAR file can now be deployed.

Deploying an Application in Sun ONE Application Server 7

The last stage is to deploy the application on an instance of Sun ONE Application Server 7. The process for deploying an application is described below:

  1. Deploying an application on Sun ONE server 7 instance from Sun ONE Studio for Java.
  2. Right click on the EAR file and select the option ‘Deploy. This would deploy the application on the default server instance. Restart the server instance and then test the application.

  3. Deploying an application on an instance using Sun ONE Application Server 7 asadmin utility:
  4. An alternative to using Sun ONE Studio for Java to deploy enterprise applications on a Sun ONE Application Server instance is to use the Sun ONE Application Server 7 asadmin utility, after creating and exporting the application EAR archive from Sun ONE Studio for Java.



Previous      Contents      Index      Next     


Copyright 2003 Sun Microsystems, Inc. All rights reserved.