Skip Headers

Oracle Application Server 10g Migrating from WebLogic
10g (9.0.4)

Part Number B10425-01
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

3
Migrating Java Servlets

This chapter provides the information you need to migrate Java servlets from WebLogic Server to Oracle Application Server. It covers the migration of simple servlets, WAR files, and exploded web applications.

This chapter contains these topics:

Introduction

Migrating Java servlets from WebLogic Server to Oracle Application Server is straightforward, requiring little or no code changes to the servlets migrated.

Both application servers are fully compliant with Sun Microsystem's J2EE Servlet specification, version 2.3. All servlets written to the standard specification will work correctly and require minimal migration effort.

The primary tasks involved in migrating servlets to a new environment are configuration and deployment. The use of proprietary extensions, such as htmlKona, will require additional tasks and complicate the migration effort.

The tasks involved in migrating servlets also depend on how the servlets have been packaged and deployed. Servlets can be deployed as a simple servlet, as a web application packaged with other resources in a standard directory structure, or as a web archive (WAR) file.

Differences Between WebLogic Server and Oracle Application Server Servlet Implementations

Oracle Application Server and WebLogic Server both support the Servlet 2.3 specification. Hence, migrating a servlet from WebLogic Server to Oracle Application Server is straightforward.

OC4J Key Servlet Container Features

One of the key distinguishing features of OC4J is the seamless integration with Single Sign-On (SSO) and Oracle Internet Directory (OID). This is achieved through Oracle's implementation of the Java Authentication and Authorization Service (JAAS) standard - JAAS provider is integrated with OC4J.

Migrating a Simple Servlet

Simple servlets are easily configured and deployed in OC4J. The manual process used to deploy a servlet is the same in both WebLogic Server and OC4J.


Note:

The recommended and preferred way to deploy a servlet is by packaging it in a WAR or EAR file and using Oracle Enterprise Manager Application Server Control or the dcmctl command line utility. The manual processes described in this chapter of editing XML files and starting OC4J at the command line using the java command should be used for development purposes only and is for discussion purposes only.


A servlet must be registered and configured as part of a web application. To register and configure a servlet, several entries must be added to the web application deployment descriptor.

The overall steps to deploy a simple servlet are as follows (detailed steps are in Table 3-1):

  1. Update the web application deployment descriptor (web.xml) with the name of the servlet class and the URL pattern used to resolve requests for the servlet.

  2. Copy the servlet class file to the WEB-INF/classes/ directory. If the servlet class file contains a package statement, create additional subdirectories for each level of the package statement. The servlet class file must then be placed in the lowest subdirectory created for that package.

  3. Invoke the servlet from your browser by entering its URL.

To determine the effort involved in migrating servlets, we selected and migrated example servlets provided with WebLogic Server. We chose examples that did not use proprietary extensions.

Table 3-1 presents the manual process for migrating a simple servlet, HelloWorld, from WebLogic Server to Oracle Application Server OC4J.

Table 3-1 Migrating a Simple Servlet  
Step Description Process

1

Modify the web application deployment descriptor

Add the descriptor information below to the web.xml file located in the following directory in your Oracle Application Server installation:

For UNIX, web.xml can be found in:

<ORACLE_HOME>/j2ee/home/default-web-app/WEB-INF/

For Windows, web.xml can be found in:

<ORACLE_HOME>\j2ee\home\default-web-app\WEB-INF\

The descriptor information to be entered is:

<servlet>
  <servlet-name>
   HelloWorldServlet
  </servlet-name>
  <servlet-class>
   examples.servlets.HelloWorldServlet
  </servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>
   HelloWorldServlet
  </servlet-name>
  <url-pattern>
   /HelloWorldMigrate/*
  </url-pattern>
</servlet-mapping>

2

Copy the servlet class file to the appropriate directory

After running the samples that came with WebLogic, copy HelloWorldServlet.class from a directory in your WebLogic Server installation to the appropriate directory in Oracle Application Server as follows:

In UNIX, from:

<BEA_HOME>/weblogic700/samples/server/config/
examples/applications/examplesWebApp/WEB-INF/
classes/examples/servlets/

to:

<ORACLE_HOME>/j2ee/home/default-web-app/WEB-INF/
classes/examples/servlets/

In Windows, from:

<BEA_HOME>\weblogic700\samples\server\config\
examples\applications\examplesWebApp\WEB-INF\
classes\examples\servlets\

to:

<ORACLE_HOME>\j2ee\home\default-web-app\WEB-INF\
classes\examples\servlets\

NOTE:
This servlet provided with the WebLogic Server installation belongs to a package called examples.servlets. When copying its class file to Oracle Application Server, you need to create the corresponding package subdirectories (for example, examples/servlets/).

3

Restart the home OC4J instance, or start it if it is not currently running

Use the Oracle Enterprise Manager Application Server Control administration web pages or the following dcmctl command:

dcmctl start|restart -i <appsvr_instance_name> -ct oc4j 
-co home

where <appsvr_instance_name> is the name of your Oracle Application Server instance

4

Run the servlet from your web browser

Access the servlet from your web browser using the URL

http://localhost:7777/j2ee/HelloWorldMigrate

(Substitute "localhost" with your OC4J instance's host name if using the browser from another machine.)

See Also:

Oracle Application Server Containers for J2EE Servlet Developer's Guide for detailed information on configuring and deploying servlets.

Migrating a WAR File

A web application can be configured and deployed as a WAR file. This is easily accomplished in OC4J by using the Application Server Control administration GUI or manually copying the WAR file to the appropriate directory. This is also true for WebLogic Server. We will illustrate the process using Application Server Control to deploy an example WAR file from WebLogic Server.


Note:

Manually copying a WAR file to the appropriate directory to deploy it should only be done in a development environment where OC4J is in standalone mode (not a component of an Oracle Application Server instance).


Production web applications are typically deployed using WAR or EAR files through Application Server Control or the dcmctl utility. During the development of a web application, it may be faster to deploy and test edited code using an exploded directory format.

Table 3-3 presents the typical process for migrating a WAR file from WebLogic Server to OC4J.

Table 3-2 Migrating a WAR File  
Step Description Process

1

Create the WAR file for the sample application.

If you have not run all the WebLogic Server samples that came with that product, build the cookie sample web application in the following WebLogic Server directory (UNIX is shown but Windows has an equivalent):

<BEA_HOME>/weblogic700/samples/server/src/
examples/webapp/cookie

In this directory, build the application by typing ant

When built, a WAR file for this application is created in the following directory:

<BEA_HOME>/samples/server/config/examples/
applications/

2

Deploy the sample application.

  1. On the machine where the cookie.war file is located, open a browser and go to the Application Server Control URL. For example:

    http://<hostname>:1810
    
    
  2. Enter your administrator username and password if prompted. Click the name of the Oracle Application Server instance you want to deploy your application to.

  3. Click the home OC4J component, which brings up its settings page.

  4. Click "Applications". In the applications page of the home OC4J instance, click "Deploy WAR file". The "Deploy Web Application" page appears.

  5. Click the "Browse" button and enter the location of the cookie.war file.

  6. In the "Application Name" and "Map to URL" text boxes, enter "cookie" and "/cookie" respectively. Click "Deploy".

  7. The cookie application should appear in the list of deployed applications.

3

Test the deployed application.

In a browser, enter the following URL:

http://<hostname>:7777/cookie

where <hostname> is the Oracle Application Server host where you deployed the cookie sample application.

Table 3-3 Migrating a WAR File  

See Also:

Oracle Application Server Containers for J2EE Servlet Developer's Guide and Oracle Application Server Containers for J2EE User's Guide for detailed information on deploying WAR and EAR files.

Migrating an Exploded Web Application

Web applications can also be configured and deployed as a collection of files stored in a standard directory structure or exploded directory format. This can be accomplished in OC4J by manually copying the contents of the standard directory structure to the appropriate directory in the OC4J installation. The same method can also be used for WebLogic Server. In this section, we will describe the manual process for deploying an exploded web application.

See Also:

Oracle Application Server 10g Administrator's Guide for detailed information on using the Oracle Enterprise Manager administration GUI.

Deploying a web application in exploded directory format is used primarily during the development of a web application. It provides a fast and easy way to deploy and test changes. When deploying a production web application, package the web application in a WAR file and deploy the WAR file using Application Server Control.

To manually deploy an exploded web application in WebLogic Server, copy the top-level directory containing the exploded web application files into the following directories of your WebLogic Server installation:

(UNIX) <BEA_HOME>/config/<domain_name>/applications
(Windows) <BEA_HOME>\config\<domain_name>\applications

Once the top-level directory is copied to the appropriate directory, create an empty file with the name "REDEPLOY" within the top-level directory. WebLogic Server detects this file and deploys the web application. (WebLogic Server reads the timestamp of this file every few minutes to determine if the application needs redeploying. Hence, whenever an application file is updated, the REDEPLOY file's timestamp has to be updated to redeploy the file. In UNIX, this can be done by using the touch command.)

Manually deploying an exploded web application in OC4J varies slightly. Copy the top-level directory containing the exploded web application into the following directory of your OC4J installation:

(UNIX) <ORACLE_HOME>/j2ee/home/applications
(Windows) <ORACLE_HOME>\j2ee\home\applications

Then, modify the following application deployment descriptor to include the web application:

(UNIX) <ORACLE_HOME>/config/application.xml
(Windows) <ORACLE_HOME>\config\application.xml

Bind the web application to your website by adding an entry in the following website XML file (or the corresponding XML file if a non-default website is used):

(UNIX) <ORACLE_HOME>/config/default-web-site.xml
(Windows) <ORACLE_HOME>\config\default-web-site.xml

Finally, register the new application by adding a new <application> tag entry in the following files:

(UNIX) <ORACLE_HOME>/config/server.xml
(Windows) <ORACLE_HOME>\config\server.xml

When you modify server.xml and save it, OC4J detects the timestamp change of this file and deploys the application automatically. OC4J need not be restarted.

Migrating Configuration and Deployment Descriptors

Since WebLogic Server and Oracle Application Server fully support J2EE 1.3, there is a standard set of XML configuration files supported by both application servers. These are:

In addition to the standard files, each application server has specific files used only by their respective environments. These are:

Oracle Application Server

WebLogic Server

Migrating Cluster Aware Applications

Oracle Application Server provides more comprehensive clustering features than WebLogic Server.

WebLogic Server provides two primary cluster services, HTTP session state clustering and object clustering. The focus of this section is on HTTP session state clustering or web application clustering.

WebLogic Server supports clustering for servlets and JSP pages by replicating the HTTP session state of clients accessing clustered servlets and JSP pages. To benefit from HTTP session state clustering, you must ensure that the HTTP session state is persistent by configuring either in-memory replication, filesystem persistence, or JDBC persistence.

Oracle Application Server provides clustering support similar to that of WebLogic Server. In addition, Oracle Application Server provides:

Each OracleAS Farm consists of multiple OC4J islands and each island can consist of multiple applications. The sharing of session state for failover is within a particular island.

For instructions on how to set up OracleAS Clusters and OC4J islands, refer to the Oracle Application Server 10g High Availability Guide.


Go to previous page Go to next page
Oracle
Copyright © 2003 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index