BLOB Access
iPlanetTM Application Server Samples

Updated  June 12, 2001

If you already went through the deployment process of BLOB you can run the application by clicking here.

This sample can only be used with a Third Party JDBC driver as the iPlanet native JDBC drivers do not support BLOBs.

Overview

The BLOB sample application provides a web-based interface to an object repository in a database.  Two servlets provide the client with the ability to manage the storage of files in the database, enabling them to insert, update, delete and fetch the files.  Note that currently the majority of JDBC drivers do support the use of the JDBC 2.0 BLOB datatype.  In the cases where the JDBC 2.0 BLOB interface is not available, the driver will typically map the databases underlying blob-like datatype to the JDBC Long Varbinary type, for example.  The servlets in this sample can use either interface.

The repository is a simple database table containing a BLOB column (or similar datatype) which holds the file data along with the filename, size and mime type of the stored content.

Setting Up the Environment

Getting Started includes a checklist of pre-requisites for deploying the sample applications to iPlanet.

Configuring the Database describes how to setup the database schema, and register the JDBC data sources for the BLOB application.

Deploying and Running the BLOB Application
Select one of two approaches to deploying and registering the application:
Command Line-based Deployment describes how to manually register the blob application in iPlanet using a Command Line Interface (CLI). This is the fastest means of deploying the BLOB sample to the application server.

GUI-based Deployment describes how to use the iPlanet Deployment Tool to import and deploy the BLOB application. Alternatively, you can also assemble the application from scratch and deploy it using the Deployment Tool.

Running the Application describes how to start the application, navigate through it and how to troubleshoot in the event of problems.
Further Exploration
Compiling and Assembling the Application describes how to use command line tools to recompile the sources and rebuild the WAR module and the overall EAR file.

Configuring the Database

The blob sample application requires the following database setup prior to running the application:
Ensure Database Requirements are Met

Ensure Database Driver is Registered

Identify or Create a Database User

Create the Sample Database Tables

Ensure Database Requirements are Met

Note: This sample is not supported with Pointbase as the dtaabase since there is no BLOB support with Pointbase.

See the iPlanet Application Server Release Notes for database version requirements. Database setup scripts are provided for the following databases:

As the Informix and Oracle JDBC drivers support the JDBC 2.0 BLOB interface they have an additional setup script.

Currently this sample has been test successfully against the following databases and third party drivers:

Problems were encountered using Oracle's Type 4 JDBC Driver.  This driver does not support BLOBs directly but maps the BLOB calls into calls to PL/SQL procedures in the DBMS_LOB package.

Ensure the Third Party Database Driver is Registered

This section describes how to register a third database driver with the application server in the event that a driver was not
registered during installation of the application server. The following instructions address only the registration of the database client
driver. The subsequent section of this document will describe how to populate the database tables and register JDBC data sources.

On UNIX, if during installation the application server, either "Typical" or "Express" installation options were selected, the Third Party
database driver will not be registered in the application server. If you are unsure as whether or not the client driver was registered, use
the application server's Administrative Tool to determine status of JDBC drivers.

Start the Admin Tool

  1. Start the Admin Tool

  2.  

    <application server install path>/ias/bin/ksvradmin
     

  3. Connect to your application server instance by selecting File->New->Server. Click on Localhost to specify the default connection settings. Enter the application server's administrator's password and click on OK.
  4. Click on the Database button and expand the server name (default name of iAS1) to see the database driver settings.
  5. If you do not see the driver listed in the External JDBC Drivers folder then you will need to register the Third Party driver in the application server. Go to the next section to register the driver.

Register a Third Party JDBC Driver

To use a third party JDBC driver in conjunction with the BLOB application, you must perform three steps:
  1. Register the JDBC Driver with the Application Server
  2. Register the JDBC Data Source for the BLOB Application
  3. Restart the Application Server
The JDBC Drivers which were tested with this sample were:
 
Vendor Driver Name Classpath example Native Library Location example
Oracle oracle.jdbc.driver.OracleDriver c:\orant\jdbc\lib\classes12.zip c:\orant\bin
Merant com.merant.sequelink.jdbc.SequeLinkDriver c:\Merant\slclient\driver\lib\sljc.jar;
c:\Merant\slclient\driver\lib\sljcx.jar
IBM DB/2 COM.ibm.db2.jdbc.app.DB2Driver c:\DB2\sqllib\java\db2java.zip c:\DB2\sqllib\bin
1. Register the JDBC Driver with the Application Server

See the iPlanet Application Server SP3 Release Notes for a complete description of registering third party JDBC drivers in the application server. The basic steps are as follows:

UNIX:

    Execute the db_setup.sh script to register a third party JDBC driver.

    a) Enter the application server installation root directory:

    Please enter the iAS installation root directory:
    /usr/iplanet/ias6
    b) Select option 2, Third Party JDBC Drivers
    Do you want to use third party JDBC drivers or native drivers.
    1. Native drivers
    2. Third party jdbc drivers
    To accept the default shown in brackets, press the Enter key.

    Select the component you want to install (1/2) [1]:
    (SELECT OPTION 2 FOR JDBC )

    c) Enter a logical name for the driver. This name must be supplied in the next step when configuring the datasource XML file.

    d) Enter the driver class name.

    e) Enter the fully qualified path of the driver JAR or ZIP file.

    f) Enter the path for the driver's native libraries. (Optional: applies to Type 2 drivers only)

Windows:
    Execute the jdbcsetup.exe program to register a third party JDBC driver.

    a) Enter a logical name for the driver. This name must be supplied in the next step when configuring the datasource XML file.

    b) Enter the driver class name.

    c) Enter the fully qualified path of the driver JAR or ZIP file.

    d) Enter the path for the driver's native libraries. (Optional: applies to Type 2 drivers only)

2. Register the JDBC Data Source for the BLOB Application

Modify the supplied datasource XML files to suit your driver and database connection requirements. The logical driver name you assigned to your third party driver in the driver registration instructions must be the same name as set in the <DRIVER-TYPE> tag of the datasource XML file. See the following sample:

    ias-samples/database/blob/src/schema/BlobDB-ora-type2.xml
The following is an example of the BlobDB datasource XML file as configured for an Oracle Type 2 JDBC driver. Note that the <database> and <datasource> tags are not required when registering datasources for third party JDBC drivers.
    <ias-resource>
    <resource>
    <jndi-name>jdbc/samples/database/blob/BlobDB</jndi-name>
    <jdbc>
       <driver-type>ora-type2</driver-type>
       <database-url>jdbc:oracle:oci8:@V816_tns_alias</database-url>
       <username>blobsample</username>
       <password>blobsample</password>
    </jdbc>
    </resource>
    </ias-resource>
After modifying the datasource XML files to suit your database connection requirements, run the iasdeploy regdatasource command against each file to register the datasource in the application server. For example,
    iasdeploy regdatasource BlobDB-ora-type2.xml
3. Restart the Application Server

After restarting the application server to pick up the third party database driver and datasource changes, restart your browser and rerun the sample application.

Identify or Create an RDBMS User

You should ensure that you have an RDBMS user defined for the sample application. You can use either an existing RDBMS user or define a new RDBMS user for the sample application. This RDBMS user will own the tables created for the sample application. The following example shows how to create a new user called blobsample using the Oracle SQL Plus utility. It is strongly recommended that a user such as blobsample be used to create the BLOB database tables. This approach will help to avoid confusion between table names used in other applications.

To define a new Oracle user:

  1. Use SQL Plus to define an Oracle user name (e.g. blobsample).

  2.  

     

    SQL > create user blobsample identified by blobsample;

    Where the first blobsample is the user name and the second blobsample is the password.
  3. Grant connect and resource privileges to the blobsample Oracle user.

  4.  

     

    SQL> grant connect, resource to blobsample;

Create the Sample RDBMS Tables

A shell script named setup_<rdbms type>.sh/.bat configures the database tables, populates the tables with sample data and updates the application server's registry with database information to support the BLOB sample application. The setup_<rdbms type>.sh/.bat script performs the following steps:
  1. Dynamically creates an XML file describing the JDBC datasource.
  2. Invokes the application server's iasdeploy regdatasource command to register the data source resource in the application server's registry.
  3. Verifies connectivity to the specified database.
  4. Creates the tables required by the BLOB application.
Go to the <application server install path>/ias/ias-samples/database/blob/src/schema/ directory and find the setup_<rdbms type>.sh/.bat file that corresponds to the database of interest. Now follow these instructions:
UNIX: Create the RDBMS table

Windows: Create the RDBMS table

UNIX: Create the RDBMS table

  1. Ensure that the RDBMS enviornment variables are set appropriately. For example, ORACLE_HOME.
  2. Edit setup_<rdbms type>.sh. Set the GX_ROOTDIR environment variable to the location of the ias/ directory in your application server installation.
  3. For example,

    GX_ROOTDIR=/usr/iplanet/ias6/ias

  4. Run setup_<dbname>.sh with the following arguments:
setup_ora.sh <TNS name> <JDBC Driver Name> <dbusername> <dbpassword>
For example using Oracle:
setup_ora.sh iassample ora-816 blobsample blobsample

Where:

<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance. In the example above, "iassample" is the Oracle service or TNS name. (This assumes that the Oracle client has been configured to recognize "iassample" as a valid Oracles service/TNS name.)

<JDBC Driver Name> is the name you gave the driver when you registered it.

<dbusername> and <dbpassword> are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.

Since the setup_ora.sh script uses sqlplus, ensure that LD_LIBRARY_PATH includes $ORACLE_HOME/lib.

Windows: Create the RDBMS table

1. Ensure that the RDBMS enviornment variable is set appropriately. For example, ORACLE_HOME.

2. Run setup_<rdbms type>.bat with the following arguments:

setup_ora <TNS name> <JDBC Driver Name> <dbusername> <dbpassword>
For example using Oracle:
setup_ora iassample ora-816 blobsample blobsample
Where:

<TNS Name> is the Oracle service or TNS name which maps to the appropriate Oracle database instance. In the example above, "iassample" is the Oracle service or TNS name. (This assumes that the Oracle client has been configured to recognize "iassample" as a valid Oracles service/TNS name.)

<JDBC Driver Name> is the name you gave the driver when you registered it.

<dbusername> and <dbpassword> are the Oracle user name and password under which the tables will be created and populated. These are also the values that will be used by the sample application to access the Oracle database.


Command Line-based Deployment

You have a choice of  deploying and registering the BLOB application through either command line utilities or the iPlanet Application Server Deployment Tool GUI. Since a complete EAR file is supplied, the fastest means of setting up BLOB is to use the command line utilities as described in this section. If you would like to experience either deploying through a GUI tool or assembling an application from scratch, then follow instructions in GUI-based Deployment.

The pre-built blob.ear file is a Enterprise ARchive file that contains the Web Archive (WAR) file for the BLOB application. Within this JAR file resides the XML deployment descriptor files, application class files and other content required by the application.  The pre-built blob.ear file is configured to not to use the JDBC 2.0 BLOB interface as the majority of drivers do not support this interface.  If you wish to change this then either refer to the GUI-based Deployment instructions or you can repackage the application.

Deploying the pre-built blob.ear file is simple.

1. Go to the root of the BLOB sample directory:

install_dir/ias/ias-samples/database/blob/
2. Execute iasdeploy to deploy BLOB to the local application server instance:
install_dir/ias/bin/iasdeploy deployapp blob.ear
The deployment process will take 30 seconds to a minute or so to complete.

The deployment process involves the following operations:

Now you're ready to exercise the BLOB application. Proceed to Running the Application.

GUI-based Deployment

The Deployment Tool provides an easy to use means of assembling J2EE applications and deploying them to the application server. Compared to the effort and risks involved in the manual creation of J2EE deployment descriptors and modules, the Deployment Tool provides an easy-to-use means of deploying your application to the application server.

Two approaches to using the Deployment Tool are described:

Import Pre-existing EAR File to quickly deploy the BLOB application. None of the application assembly steps are covered by this section. On average, this approach will take 15 minutes.

or

Assemble BLOB Application to learn how to use Deployment Tool to assemble and deploy the BLOB application. On average, this approach will take from 30 to 45 minutes.

Import Pre-existing EAR File

Since a pre-built Enterprise ARchive (EAR) file for the BLOB application is shipped with the application server, you can use the Deployment Tool to quickly read in the .ear file, modify deployment settings and deploy to the application server.

Import the EAR File

Open the pre-existing BLOB EAR file.

1. Launch the Deployment Tool.

2. Open the blob.ear file

Modify Environment Settings

Modify the initial parameter settings of the DownloadServlet and UploadServlet to control the size of the internal buffers used to tranfer the BLOB data to and from the database and whether to use the BLOB interface or not.  These changes will result in modifications being made the XML deployment descriptors in the blob.war file.  Note that there is no requirement for the values to be the same.
  1. Expand the blob module.
  2. Select DownloadServlet, right click and select Edit Descriptor.
  3. Select the Init Params tab.
  4. Modify the chunkSize parameter if required.
  5. Modify the useBlob parameter if required.
  6. Repeat for the UploadServlet.
  7. Save the initialization parameter changes by closing the descriptor window.
  8. Select the blob module and select File->Save to save the descriptor changes to the EAR file.
Proceed to Deploying the Application

Assemble BLOB Application

Compile Application Sources

To compile the application sources, simply execute "build compile" under the application's src/ directory. See the section Compiling and Assembling the Application for more information on recompiling the application using the supplied build facility.

Create blob.war Module

Identify the Content for WAR File

1. Create blob.war: 2. Now insert all class files needed in the blob.war file: 3. Add the UploadForm.html file needed to the .war file

Modify the Initial Parameters of All Servlets

Our next step is to set the initial parameters for the servlets. To perform this, we must open up the descriptor for each servlet and add the initial parameters to the servlet. After saving each descriptor, we will save the WAR file to force the rename to take effect. Then we will reopen the WAR file and continue with assembling the WAR module.

Modify Web Application Descriptor

Now we need to make several changes to settings at the WAR module level. To do so, select either the WAR file path if in File View or the WAR module name if in Component View. Right click and select Edit Descriptor.

In the References Tab, enter the following data under the References to Resource Factories:

 
Resource Name Resource Class Authorization JNDI Name
BlobDataSource javax.sql.DataSource Container jdbc/samples/database/blob/BlobDB
In the Servlet Mapping Tab, enter the following mappings under the Servlet Mapping:
 
Servlet Name URL Pattern
UploadServlet /upload
DownloadServlet /download/*

Save and close blob.war

Now that we've assembled the WAR J2EE module, we're ready to move on to assembling the module into an EAR file.

Assemble blob.ear

1. Create blob.ear: 2. Add blob.war Files: 3. Set Context Root for Web Application

Next, we need to set the context root of the web application. This value will appear in URLs that access web application components. For example, in the URL http://localhost/NASApp/blob/upload the "blob" value is the context root of the web application.

5. Save blob.ear: Now that the EAR file has been assembled, the next step is to deploy the application to an application server instance.

Deploy the Application

Now you're about to deploy the application by transferring the EAR file to a target iPlanet Application Server. First, you will identify the target server. After the EAR file is deployed to the server, post processing is performed. After this step, you will be able to run the application. No server restart is required.

If you followed the assembly instructions, then blob.ear is opened in Deployment Tool. If you opened the pre-existing EAR file, you are working with <application server install path>\ias\ias-samples\blob\blob.ear. If you are following the "Create EAR File from Scratch" instructions, you are modifying <application server install path>\ias\ias-sample\database\blob\assemble\blob.ear.

If you entered all deployment information manually, you can skip the following steps 1 to 3, because you have entered this information already.

1. Select the blob.ear file under the J2EE Application window.

2. Select File -> Deploy

3. If you have not already registered a target application server, do so now by clicking on the Register button. Enter the host name, administrative port number and username/password for the target application server. Otherwise, select a pre-registered target server.

Note: You may authorize additional users to deploy applications to an application server server by using the application server's Administrative Console. See the Security settings tab in the Administrative Console.
4. Click on Overwrite modules in case you are repeating the deployment step.

5. Click on Deploy to start the deployment process.

6. Now the file transfer and application registration begins. See the Deploy tab for the status of the deployment. The deployment may take several minutes to complete. Once the status of the deployment changes to Success, proceed to the next section.

Verifying Registration

After you've deployed the application, you're ready to use several application server administrative tools to verify that the application is available.
  1. Start the Application Server Admin Tool
  2. UNIX:
    <application server install path>/ias/bin/ksvradmin
    Windows:
    Start->Programs->iPlanet Application Server->iAS Administration Tool
  3. Connect to your application server instance by selecting File->New->Server. Click on Localhost to specify the default connection settings. Enter the application server administrator's password and click on OK.
  4. Select the server name (default name of iAS1) and select the Application button in the top right hand corner of the window to see the applications registered in this instance of the application server.
  5. You should see several folders for the "blob" J2EE application. The "blob" folder with the world icon represents the web application module.
To see more details associated with the BLOB application, you can use the lower level tool named kregedit:
  1. Execute kregedit to start the application server's Registry Editor GUI.
  2. Navigate to the SOFTWARE/iPlanet/Application Server/6.0/ portion of the tree.
  3. Browse the J2EE-Application/ tree and look for the "blob" application.
  4. Expand the "blob" folder and explore this portion of the directory tree.
  5. Now open the J2EE-Module/ tree and look for the "blob" web application module entry.
  6. Expand the folders and explore their contents.

Running the Application

Start the application either by clicking here or, if you've deployed the web server on a separate machine, by accessing:

http://<web server hostname>:<port>/NASApp/blob/download/list

1. After the Download Servlet List page appears click on the Upload Form link to navigate to the HTML page to upload content to the database

2. Either select the Browse button and choose a file, or enter the file name path directly in the text field.

3. Click on the Upload button

4. If all is successful the file will be uploaded to the database.  Select the Repository contents link to see the file in the repository.

5. You can select the filename link to download the content, or on the delete link to remove the file from the repository.

Troubleshooting

As part of your troubleshooting efforts, ensure that you first review the General Troubleshooting section to learn how to view logs files.

In general if a problem is going to occur then it will be in the interaction with the database.  In general the servlet in question will report the problem directly to the browser.


Compiling and Assembling the Application

To easily 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 sample from scratch, you can simply execute:

build all
From the directory install_dir/ias/ias-samples/database/blob/src/

On UNIX, you might need to modify your PATH to ensure that install_dir/ias/bin is included to pickup the build script.

Copyright (c) 2001 Sun Microsystems, Inc. All rights reserved.