Oracle WebLogic Server 12c: Managing HTTP Sessions in a Cluster

<Do not delete this text because it is a placeholder for the generated list of "main" topics when run in a browser>

Purpose

This tutorial shows you how to configure and test the HTTP session replication features of an Oracle WebLogic Server 12c cluster. You test both in-memory and JDBC (database) replication. An active JDBC data source is necessary to use JDBC replication.

Time to Complete

Approximately 45 minutes

Overview

When in-memory replication is enabled for a web application, WebLogic Server copies session state from one server in the cluster (primary) to one other server in the same cluster (secondary). The replica on the secondary server is kept up-to-date so that it may be used if the primary server fails.

When a client attaches to a server in the cluster and creates the primary session state, the server hosting the primary state ranks the other servers in the cluster to determine which server should host the secondary state. Server ranks are assigned using a combination of:

If the primary server fails, another server will take on its clients to become the new primary server. That server contacts the secondary server and receives the session data, and a new secondary server is chosen.

With persistent JDBC replication, a database is configured for the storage of session objects. After it is configured, each of the server instances in a cluster uses a JDBC data source to share access to the database. This technique does not need primary and secondary servers, since the data is stored in a database that is accessible to all servers. There is, however, a significant performance reduction with JDBC replication compared to in-memory replication.

Cluster replication settings are configured individually for each application that is deployed to the cluster. Modify these settings by either updating the application's XML deployment descriptor file directly, or by creating a deployment plan.

Software Requirements

The following is a list of software requirements:

Prerequisites

Before starting this tutorial, you should have completed the Oracle by Example tutorials titled:

Assigning Preferred Replication Boundaries

To configure custom cluster replication group settings, perform the following steps:

.

If the administration server of the domain is not already running, it needs to be started. To start it, in a Terminal window, navigate to the domain directory, and enter the command:

./startWebLogic.sh

When prompted for a username and password, enter the credentials of the domain administrator.

 

.

If any of the servers in your WebLogic cluster (dizzy1, dizzy2, or dizzy3) are running, stop them.

Replication group changes do not take effect on a running server.

 

.

Open a web browser and enter the URL of the domain's administration console. In this tutorial, that is: http://host01.example.com:8001/console

Note: Use the host name and port of the administration server of your domain.

On the Welcome screen, log in using the username and password entered to start the servers.

 

.

In the Change Center, click the Lock & Edit button.

 

.

Under Domain Structure, expand Environment and click Servers.

 

.

Click the dizzy1 server.

 

.

Click the Configuration tab, and then the Cluster subtab.

 

.

Enter the following values:

Field Value
Replication Group dizzyRepGroup1
Preferred Secondary Group dizzyRepGroup2

 

Then click Save.

 

.

Repeat the previous steps, but select the dizzy2 server.

Configure the same Replication Group and Preferred Secondary Group values.

 

.

Select the dizzy3 server.

Repeat the previous steps again, but this time configure the opposite Replication Group and Preferred Secondary Group values:

Field Value
Replication Group dizzyRepGroup2
Preferred Secondary Group dizzyRepGroup1

 

.

In the Change Center, click the Activate Changes button.

 

.

Restart all of the servers in your WebLogic cluster (dizzy1, dizzy2, and dizzy3).

If you have previously configured and started the Node Manager, as described in the Oracle WebLogic Server 12c: Configuring and Using Node Manager tutorial, you can start these managed servers by using the administration console. Otherwise, start each server from the command line. For example:

./startManagedWebLogic.sh dizzy1 host01.example.com:8001

 

Configuring and Deploying a Sample Application for In-Memory Replication

To configure a web application for in-memory replication and deploy it to a cluster, perform the following steps:

.

Download the shoppingcart.war web application. Place it in a location that is accessible to your WebLogic domain. For this tutorial, the file is saved to /u01/app/oracle/Middleware/user_projects/applications.

 

.

Use an archive utility such as jar or unzip to extract the application archive to a folder named shoppingcart.

mkdir shoppingcart

unzip -d shoppingcart shoppingcart.war

 

.

Edit the shoppingcart/WEB-INF/weblogic.xml file.

Locate the comment line Insert session descriptor element here.

 

.

Directly below this line, add the following new lines:

<session-descriptor>

   <persistent-store-type>replicated_if_clustered</persistent-store-type>

</session-descriptor>

Save your changes.

 

.

Use an archive utility such as jar or zip to re-create the application archive shoppingcart.war.

rm shoppingcart.war

cd shoppingcart

zip -r ../shoppingcart.war *

 

.

Return to the WebLogic Server administration console.

 

.

In the Change Center, click the Lock & Edit button.

 

.

Under Domain Structure, click Deployments.

 

.

On the right, under Deployments, click the Install button.

 

.

Find the Current Location field. Use the links to browse to the location in which you placed the downloaded shoppingcart.war file. There you will see shoppingcart.war with a radio button next to it. Select that radio button. The console then fills in the Path field for you.

Alternatively, you can type in the path and file name in the Path field yourself.

Click Next.

 

.

On the next screen, ensure that the option Install this deployment as an application is selected. Then click Next.

 

.

On the next screen, select the cluster dizzycluster. Then click Next.

 

.

On the next screen, keep all the default values and click Finish.

 

.

In the Change Center, click the Activate Changes button.

 

.

In the Deployments table, select the check box to the left of the shoppingcart application. Then use the Start drop-down list to select the option Servicing all requests.

 

When prompted, click Yes to continue.

 

Testing In-Memory Replication

To validate your session replication settings, perform the following steps:

.

Open a Terminal window and change directories to: <WEBTIER_HOME>/instances/instance1/bin

In this tutorial, <WEBTIER_HOME> is /u01/app/oracle/Middleware/Oracle_WT1.

 

.

Execute the following command:

./opmnctl status

 

.

From the output of the command, verify that the HTTP Server process ohs1 is running ("Alive").

 

If it is not running, start it by using the following command:

./opmnctl startall

 

.

Direct a browser to the shoppingcart application, but via the HTTP Server proxy. The default port is 7777:

http://<host>:7777/shoppingcart

For example:

http://host01.example.com:7777/shoppingcart

 

.

Click the Go Shopping link. Then use the Add to shopping cart links to add an item to your cart.

 

.

Click the Back to Home Page link. Then repeat the previous step to add a second item to your cart.

When finished, click the View Shopping Cart link.

 

.

Locate the Terminal windows from which you started the servers in your WebLogic cluster. Use the output messages of the application to determine to which server the user's session is pinned (the primary server). For example:

added new element: package of 5 legal pads

Your shopping cart includes:

   Item: box of 12 pens (black) price: 4.99

   Item: package of 5 legal pads price: 15.99"

If you started these servers with Node Manager instead of from the command line, you will need to view the output log files (<server_name>.out).

 

.

Kill the primary server that is hosting your session. Use Ctrl + C or the Linux kill command.

 

.

Return to your web browser, click Back to Home Page, and then click View Shopping Cart again. Confirm that the shopping cart contents are still the same.

 

.

Once again use the server output messages to determine which server is now processing the requests.

 

.

Restart the server that was killed. Close your web browser.

 

Initializing a Database to Support JDBC Replication

To create the necessary tables in your database for JDBC replication, perform the following steps:

.

Download the jdbc_replication_oracle.sql SQL script to the machine running your Oracle database.

 

.

Invoke SQL Plus as the sysdba role:

$ $ORACLE_HOME/bin/sqlplus / as sysdba

 

.

Run the SQL script by using the following command:

SQL> @jdbc_replication_oracle.sql

SQL> commit;

If the SQL file is not located in the current directory, provide the full path in the command. For example:
@/mypath/jdbc_replication_oracle.sql

 

.

Verify the presense of a new table named WL_SERVLET_SESSIONS:

SQL> select count(*) from WL_SERVLET_SESSIONS;

 

.

Leave the SQL Plus session open.

 

Targeting a JDBC Data Source to a Cluster

To retarget the existing data source (from a previous tutorial) to the entire cluster, perform the following steps:

.

Return to the administration console and click Lock & Edit in the Change Center.

Then, in the Domain Structure panel, expand Services and click Data Sources.

 

.

Select the existing dizzyworldDS data source.

 

.

Click the Targets tab.

 

.

In the Clusters section, select the option All servers in the cluster. Then click Save.

 

.

In the Change Center, click the Activate Changes button.

 

Configuring a Web Application for JDBC Replication

To configure the application to use JDBC session replication, perform the following steps:

.

Edit the shoppingcart/WEB-INF/weblogic.xml file again.

 

.

Modify the existing <session-descriptor> element as follows:

<session-descriptor>

   <persistent-store-type>jdbc</persistent-store-type>

   <persistent-store-pool>dizzyworldDS</persistent-store-pool>

   <persistent-store-table>WL_SERVLET_SESSIONS</persistent-store-table>

</session-descriptor>

Save your changes.

 

.

Re-create shoppingcart.war again.

rm shoppingcart.war

cd shoppingcart

zip -r ../shoppingcart.war *

 

.

Return to the administration console and click Lock & Edit in the Change Center.

 

.

In the Domain Structure panel, click Deployments.

 

.

Select the check box for the shoppingcart application. Then click Update.

 

.

Click Finish.

In the Change Center, click Activate Changes.

 

Testing JDBC Replication

To validate your session replication settings, perform the following steps:

.

Direct a browser to the shoppingcart application again. Add several items to your shopping cart.

 

.

Return to SQL Plus and inspect the latest contents of the WL_SERVLET_SESSIONS table.

SQL> select * from WL_SERVLET_SESSIONS;

A row should exist and the value of the WL_CONTEXT_PATH column should be shoppingcart.war.

 

.

Use server output to determine which server is currently hosting the session. Kill this server.

 

.

Use the application to view your shopping cart again, and confirm that its contents are still the same.

 

Summary

In this tutorial, you learned how to:

Resources

Credits

Hardware and Software Engineered to Work Together Copyright © 2012, Oracle and/or its affiliates. All rights reserved