Sun GlassFish Mobility Platform 1.1 Installation Guide

Chapter 3 Setting Up and Running the MusicDB Sample Application

This chapter explains how to set up and run the a sample application, secure MusicDB, to verify your Sun GlassFish Mobility Platform software installation. This exercise is an optional part of the installation process. You only need to complete it to verify that your Sun GlassFish Mobility Platform installation was successful.

Overview of the Secure MusicDB Application

Secure MusicDB is a simple application that quickly shows you how to set up and use the Sun GlassFish Mobility Platform software to complete an end-to-end run from the client through to a MySQL or Oracle database without having to undergo the arduous process of setting up and configuring a more complex EIS/EAI system. The application can be run in a single-tier or two-tier environment.

Figure 3–1 shows the secure MusicDB application running in a single tier.

Figure 3–1 Secure MusicDB Application Running in a Single-Tier Environment

Diagram showing secure MusicDB application running in
a single-tier Sun GlassFish Mobility Platform environment

Figure 3–2shows the secure MusicDB application running in a two-tier environment.

Figure 3–2 Secure MusicDB Application Running in a Two-Tier Environment

Diagram showing secure MusicDB application running in
a two-tier Sun GlassFish Mobility Platform environment

    To run the secure MusicDB application you need to do the following:

  1. Configure the Sun GlassFish Mobility Platform Gateway

  2. Download the client application JAD file

  3. Populate the album table

  4. Run the MusicDB client application using the WTK client emulator on a Windows system

Configuring the Gateway

Create a Sun GlassFish Mobility Platform user for the MusicDB sample application.

    If you have a two-tier Sun GlassFish Mobility Platform installation, perform this task on the tier1, or Gateway tier, system.

  1. In a browser window, open http://tier1host:8080/sync/admin.

    The Gateway Administration Console login screen appears.

  2. Log in using user admin and password adminpass.

    The Sun GlassFish Mobility Platform Administration Console appears.

  3. Click the Users tab, then click the Create User tab.

  4. In the Email Address field, type the user's email address, such as musicdbuser@mycompany.com.

  5. In the Password field, type musicdbpass.

  6. In the Username field, type musicdbuser.

  7. Optionally, type the telephone number for the mobile device in the Phone Number field.

    This telephone number will be used for SMS notification.

  8. Select MusicDb from the Enterprise Connector drop-down list.

  9. Click Register.

  10. Click the Edit User tab to verify that the user was created.

Downloading the MusicDB Client Application

    Complete the following steps to download and unzip the Sun GlassFish Mobility Platform client bundle and locate the secure-musicdb.jad file that you will run with WTK 2.5.2 in a subsequent procedure to verify your Sun GlassFish Mobility Platform installation.

  1. Download the sjsmep-client-1_1–fcs.zip client bundle if you haven't already done so.

  2. Unzip the client bundle.

    The bundle unzips into the sjsmep-client-1_1–fcs directory.

  3. Check the contents of the samples/secure-musicdb subdirectory and locate the secure-musicdb.jad file.

    This is the client application file that you will run in a subsequent section.

Populating the album Table

The album table in the musicdb database was created during the Sun GlassFish Mobility Platform installation, but it does not contain any data. This procedure explains how to populate the album table so you have data to manipulate with your client application in subsequent steps.

If you have a two-tier Sun GlassFish Mobility Platform installation, perform this task on the tier2, or Enterprise tier, system.

    Complete the following steps to add data to the album table:

  1. Connect to the musicdb database.

    If you are using Oracle, start SQL*Plus and connect as follows:


    $ sqlplus musicdbuser/musicdbpass@musicdb
    

    If you are using MySQL, start the mysql utility and connect as follows:


    $ mysql -umusicdbuser -pmusicdbpass musicdb
    
  2. Verify that the album table was created during the Sun GlassFish Mobility Platform installation and that it has no contents:


    select * from album;
    
  3. Add your first album:


    insert into album (name, artist, date_published, rating, username) 
    values ('Crossroads', 'Eric Clapton', DATE '1988-04-18', 5, 'musicdbuser');
    
  4. Add another album:


    insert into album (name, artist, date_published, rating, username) 
    values ('Unplugged', 'Eric Clapton', DATE '1992-08-25', 5, 'musicdbuser');
    
  5. Add a third album:


    insert into album (name, artist, date_published, rating, username) 
    values ('The Road to Escondido', 'Eric Clapton', DATE '2006-11-06', 
    5, 'musicdbuser');
    
  6. If you are using Oracle, commit your changes.


    sqlplus> commit;
    
  7. Check that the album table contains the three albums that you just added:


    select * from album;
    
  8. Exit the utility:


    exit
    

Running the Secure MusicDB Client Application

    Start the client emulator on a Windows system:

  1. Choose Start->All Programs->Sun Java Wireless Toolkit 2.5.2 for CLDC->Wireless Toolkit 2.5.2.

    The Sun Java Wireless Toolkit 2.5.2 for CLDC screen is displayed.

  2. To configure the toolkit security settings, complete the following steps:

    1. Select Edit from the menu bar and then select Preferences.

      The Preferences screen is displayed.

    2. Select Security in the Category pane.

      The Security tab is displayed.

    3. Ensure that MSA is selected for the Security Policy.

    4. Ensure that maximum is selected for the Security domain.

    5. Click OK when you are done.

      The console will display messages indicating that your Preferences have been updated and saved.

  3. If you plan to use HTTPS instead of HTTP as the transport between the mobile client (the toolkit) and the gateway, complete the following steps:

    1. Change to the config subdirectory in the Gateway tier Sun GlassFish Mobility Platform installation:


      $ cd as-install/domains/domain-dir/config
      
    2. Export the keystore to a file:


      $ keytool -export
      -keystore keystore.jks
      -alias s1as
      -file sjsas.cer
      -storepass adminpass
      
    3. Copy the exported keystore to the system from which you will run the toolkit.

    4. In the toolkit, select File from the menu bar, then select Utilities.

    5. Select Manage Certificates and press the Launch button.

    6. In the Java ME Platform Certificate Manager, select Import Certificate.

    7. Locate the certificate, s1as.cer, that you generated in step 3b and copied locally and press Import.

    8. Select Maximum from the Select Security Domain drop-down and then press OK.

      The Key Details pane, on the right side of the window, reports that the certificate has been imported and is enabled.

  4. Select File from the menu bar, then select Create project from JAD/JAR file.

    The Create new project from JAD screen is displayed.

  5. Locate the secure-musicdb.jad file in the samples/secure-musicdb subdirectory, then click Open.

    After the WTK opens the project, it displays the following message:


    Project "secure-musicdb" loaded
  6. Click Run in the toolbar.

    The emulator appears with MepSecureJdbcMIDlet selected.

  7. To launch the client application, click Launch (the top right button on the keypad, with a dot on it).

    The Initialize PIN screen displays.

  8. In the Enter Secret field, type any sequence of characters. You do not need to remember what you typed.

  9. In the Set Your PIN field, type a sequence of alphanumeric characters. You can type up to 32 characters but keep in mind that you need to remember what you typed for your PIN.

  10. Click OK.

    The Sun GlassFish Mobility Platform JDBC Client configuration screen displays. This screen includes several settings for the application.

  11. In the sync server url field, type http://hostname.dnsdomainname:port-number/sync.

    You'll need to edit the URL that is shown by default.

    If you have a two-tier Sun GlassFish Mobility Platform installation, type the hostname.dnsdomainname :port-number of the tier1, or Gateway tier, system.

  12. In the email field, type the email address that you used when you created the musicdbuser in Configuring the Gateway (for example, musicdbuser@mycompany.com).

  13. In the password field, type musicdbpass.

  14. In the syncType pane, use the emulator arrow keys and the Select button (the big square button) to select Slow sync.

  15. Click Menu and select Sync.

    A Sync Successful message appears briefly, followed by a description of the synchronization results.

  16. To verify that the albums have been downloaded from the server, click Menu then select Albums.

    The three albums that you created in Populating the album Table appear.

  17. Create a new album.

    1. Click Menu and select New Album.

    2. Type data in the Name, Artist, Publish Date, and Rating fields and click OK when you are done.

      The album name appears with a .alb suffix.

    3. Click Back.

      The Sun GlassFish Mobility Platform JDBC Client screen appears.

  18. Synchronize the data with the MusicDB database.

    1. Select the Two-way sync type, then click Menu and then select Sync.

      A Sync Successful message appears, and the synchronization results are displayed.

    2. Click Ok.

      The albums are displayed.

      The data on your client device and the data in the MusicDB database are now synchronized.