This exercise describes how to cache session information for Web application instances that are deployed across WebLogic Server instances. It highlights the use of managed servers, which allows you to use Coherence data caches and seamlessly incorporate Coherence*Web for session management.
If you do not already have the current WebLogic Server release, you can get it at the following URL:
http://www.oracle.com/technology/software/products/middleware/index.html
This chapter has the following sections:
WebLogic Server includes features that enable deployed applications to use Coherence data caches and seamlessly incorporate Coherence*Web for session management and TopLink Grid as an object-to-relational persistence framework. Collectively, these features are referred to as Coherence container.
Coherence container is employed by applications running on WebLogic Server and provides replicated and distributed caching services that make an application's data available to all servers in a Coherence data cluster. Applications can obtain direct access to data caches either through resource injection or component-based JNDI lookup. You can display, monitor, create, and configure Coherence clusters using the WebLogic Server Administration Console and WLST.
Using Coherence container with WebLogic Server instances enables you to create a data tier dedicated to caching application data and storing replicated session state. This is separate from the application tier, where the WebLogic Server instances are dedicated to running the application.
Using Coherence*Web with Coherence container enables you to provide Coherence-based HTTP session state persistence to applications. Coherence*Web enables HTTP session sharing and management across different Web applications, domains, and heterogeneous application servers. Session data can be stored in data caches outside of the application server, thus freeing application server heap space and enabling server restarts without losing session data.
Coherence and Coherence*Web are included in the default installation of WebLogic Server. The Coherence and Coherence*Web libraries (coherence.jar
and coherence-web.jar
) are included in the system classpath of WebLogic Server. These libraries will load application classes with the appropriate classloader in WebLogic Server. This means that you do not have to include the coherence.jar
or coherence-web.jar
files in the web application's classpath.
For more information on the integration of Oracle WebLogic Server, Coherence, and Coherence*Web, see Oracle Fusion Middleware Administering HTTP Session Management with Oracle Coherence*Web. For more information on Coherence container, see Oracle Fusion Middleware Developing Oracle Coherence Applications for Oracle WebLogic Server.
Coherence clusters are different than WebLogic Server clusters. They use different clustering protocols and are configured separately. Multiple WebLogic Server clusters can be associated with a Coherence cluster and a WebLogic Server domain can contain only a single Coherence cluster. Managed servers that are configured as Coherence cluster members are referred to as managed Coherence servers.Managed Coherence servers can be explicitly associated with a Coherence cluster or they can be associated with a WebLogic Server cluster that is associated with a Coherence cluster. Managed Coherence servers are typically setup in tiers based on their type: a data tier for storing data, an application tier for hosting applications, and a proxy tier for allowing access to external clients.
For more information on Coherence clusters in a WebLogic server environment, see "Configuring and Managing Coherence Clusters" in Administering Clusters for Oracle WebLogic Server.
The following example demonstrates how Coherence container and Coherence*Web caches session information for Web application instances that are deployed across WebLogic Server instances. To do this, you will create a Web application and deploy it to two WebLogic Server instances that belong to a Coherence cluster. The application is a simple counter that stores the current count as a session attribute. Coherence*Web automatically serializes and replicates the attribute across both server instances. A browser is used to access each application instance to demonstrate that the same session attribute is used among the instances.
The following instructions assume that you have installed WebLogic Server in the default location: C:\Oracle\Middleware\Oracle_Home
.
To configure and start WebLogic Server:
Run the Oracle WebLogic Configuration Wizard to create a new WebLogic Server domain.
In the Create Domain page, select the Create a new expanded domain option. In the Domain location field, enter C:\Oracle\Middleware\Oracle_Home\user_projects\domains\test_domain
as the domain name and loacation.
In the Templates page, ensurea that the default Basic WebLogic Server Domain is selected.
In the Administrator Account page, enter a password for the domain.
In the Domain Mode and JDK and the Optional Configuration pages, accept the defaults.
In the Configuration Summary page click Create.
In the final Configuration Success page, select the Start Admin Server check box and click Done. The Configuration Wizard automatically starts the Administration Server.
Start the WebLogic Server Administration Console.
From the browser, log in to the Oracle WebLogic Server Administration Console using the following URL:http://
hostname
:7001/console
. The Console starts and the domain home page displays.
To create a Machine on which to host WebLogic Server instances:
From the Domain Structure window, select Environment and then Machines. Click New. The Create a New Machine page displays. Enter a name for the Machine (in this case, Test) and click Next. Click Finish on the following page. Figure 12-1 illustrates the Create a New Machine page.
The Summary of Machines page should look similar to Figure 12-2.
Create two WebLogic server instances associated with the machine. One will be Coherence*Web storage-enabled, the other will be Coherence*Web storage-disabled. The application will be deployed to these servers in a later step.
To create server instances:
Click the name of the Machine in the Summary of Machines page to open the Settings for machine page. Click the Servers tab and then click Add to create a server.
Select Create a new server and associate it with this machine in the Add a Server to Machine page, and click Next.
Provide details about the server in the Create a New Server page.
Enter ServerA
as the Server Name and 8081
as the Server Listen Port. Ensure that No, this is a stand-alone server is selected, as illustrated in Figure 12-3. Click Finish.
When you are returned to the Settings for machine page, click Add, and repeat the previous step to create a second server.
Enter ServerB
as the Server Name and 8082
as the Server Listen Port. Ensure that No, this is a stand-alone server is selected. Click Finish.
The Summary of Servers page displays and is similar to Figure 12-4.
A Coherence cluster is a group of Coherence nodes that share a group address which allows them to communicate. Coherence clusters consist of nodes formed by applications, modules, or application servers (WebLogic Server instances or cache servers). In this step you create a Coherence cluster and assign the two WebLogic Server instances to it.
To create a Coherence cluster:
Click Environment in the domain Structure Window and then click Coherence Clusters. In the Summary of Coherence Clusters page, click New. In the Coherence Cluster Properties page of the Create Coherence Cluster Configuration wizard, enter CoherenceCluster
in the Name field, then click Next.
Figure 12-5 illustrates the Create Coherence Cluster Configuration page.
Enter a value such as 8085
, in the Unicast Listen Port field. Do not change any of the other values and click Next.
Figure 12-6 Specifying a Unicast Listen Port for a Coherence Cluster
In the Coherence Cluster Targets page of the Create Coherence Cluster Configuration wizard, select ServerA and ServerB as the targets. Click Finish.
Figure 12-7 Choosing Coherence Cluster Targets
The Summary of Coherence Clusters page looks similar to Figure 12-8.
Figure 12-8 Summary of Coherence Clusters
One of the WebLogic servers must be enabled for Coherence*Web local storage. In this step, Coherence*Web local storage will be enabled for ServerB
.
Click Servers in the Domain Structure tree to open the Summary of Servers.
Click ServerB.
In Settings for ServerB, click the Configuration tab, then the Coherence tab.
Select the Coherence*Web Local Storage Enabled checkbox, as illustrated in Figure 12-9.
Click Save.
Figure 12-9 Enabling a Server for Coherence*Web Local Storage
The Counter web application is a simple counter implemented as a JSP. The counter is stored as an HTTP session attribute and increments each time the page is accessed.
To create the Counter web application:
Create a standard web application folder as follows:
/ /WEB-INF
Copy the following code to a text file and save it as a file named web.xml
in the /WEB-INF
folder.
<?xml version = '1.0' encoding = 'windows-1252'?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <description>Empty web.xml file for Web Application</description> </web-app>
Create a weblogic.xml
file in the /WEB-INF
folder.
Reference coherence-web
as the persistent store type for the session descriptor.
Reference the Coherence cluster in a coherence-cluster-ref
stanza.
Example 12-1 illustrates a sample weblogic.xml
file.
Create a lib
subfolder in the WEB-INF
folder. Leave it empty.
Copy the following code for the counter
JSP to a text file and save the file as counter.jsp
in the root of the Web application folder.
<html> <body> <h3> Counter : <% Integer counter = new Integer(1); HttpSession httpsession = request.getSession(true); if (httpsession.isNew()) { httpsession.setAttribute("count", counter); out.println(counter); } else { int count = ((Integer) httpsession.getAttribute("count")).intValue(); httpsession.setAttribute("count", new Integer(++count)); out.println(count); } %> </h3> </body> </html>
Create a MANIFEST.MF
file in the META-INF
folder. Example 12-2 illustrates a sample MANIFEST.MF
file.
The structure of the web application folder should appears as follows:
/ /counter.jsp /META-INF/MANIFEST.MF /WEB-INF/lib/ /WEB-INF/web.xml /WEB-INF/weblogic.xml
ZIP or JAR the Web application folder and save the file as counter.war
.
Start the managed WebLogic Servers ServerA
and ServerB
. Because of the tight integration between WebLogic and Coherence, the cache server will start with the managed servers. The managed servers can be started from the command line or from the WebLogic Server Administration Console.
The following instructions are for starting the servers from the command line.
Open a command prompt from the domain's bin
folder. This example assumes that the bin
folder is located in c:\Oracle\user_projects\domains\base_domain\bin
.
Enter the following command to start ServerA
:
startManagedWebLogic.cmd ServerA
Enter the server's user name and password when prompted.
Open a second command prompt from the domain's bin
folder.
Enter the following command to start ServerB
:
startManagedWebLogic.cmd ServerB
Enter the server's user name and password when prompted.
When the servers are running, you should see the response similar to Figure 12-10 in the Summary of Servers page in the WebLogic Server Administration Console.
Figure 12-10 Starting the Managed WebLogic Servers
Start the Node Manager, then start the WebLogic Server instances from the WebLogic Server Administration Console. The Node Manager is a Java utility that runs as a separate process from Oracle WebLogic Server, and enables you to perform common operations for a Managed Server, regardless of its location with respect to its Administration Server.
To start the Node Manager, go to Start, then All Programs, then Oracle, then WebLogic Server 12c, then Tools, and then Node Manager.
In the WebLogic Server Administration Console, click Environment then Servers in the domain Structure Window. From the Summary of Servers page in the WebLogic Server Administration Console, click the Control tab and start ServerA
and ServerB
.
When the servers are running, you should see the response similar to Figure 12-10 in the Summary of Servers page in the WebLogic Server Administration Console.
Deploy the counter.war
application to the running managed servers.
To deploy the counter.war
application:
Open the Summary of Deployments page by clicking Deployments in the Domain Structure menu in the Oracle WebLogic Server Administration Console.
Click Install. The Install Application Assistant wizard opens.
Navigate to the location of the counter.war
file, as illustrated in Figure 12-11. Click Next.
Figure 12-11 Locating the Deployable Application
Select Install this deployment as an application as illustrated in Figure 12-12. Click Next.
Figure 12-12 Installing the Deployment as an Application
Target the deployment to ServerA
and ServerB
, as illustrated in Figure 12-13.
In the Optional Settings page, accept the defaults, as illustrated in Figure 12-14. Click Finish.
Figure 12-14 Optional Settings Page of the Installation Assistant
The counter.war
file appears in the table in the Summary of Deployments page. The table indicates that the application is active and running (since the servers are running) on ServerA
and ServerB
, as illustrated in Figure 12-15.
Figure 12-15 Deployments Window Showing the Deployed Application
To verify the example:
Open a browser and access the ServerA
counter instance using the following URL:
http://
host
:8081/counter/counter.jsp
The counter page displays and the counter is set to 1 as illustrated in Figure 12-16.
Figure 12-16 Counter Page with Counter Set to 1
In a new browser (or new browser tab), access the ServerB
counter instance using the following URL:
http://
host
:8082/counter/counter.jsp
The counter page displays and the counter increments to 2 based on the session data as illustrated in Figure 12-17.
Figure 12-17 Counter Page with Counter Set to 2
If you refresh the page, the counter increments to 3. Return to the original browser (or browser tab), refresh the instance, and the counter displays 4.
If you want to use a custom session cache configuration file, you must package it with your application. It must also be stored in a Grid Archive (GAR) file and deployed to the WebLogic Server cluster that is to act as the storage-enabled Coherence cluster members. A detailed discussion of working with custom session cache configuration files is beyond the scope of this document. For more information on creating and deploying a custom session cache configuration file, see "Using a Custom Session Cache Configuration File" in Oracle Fusion Middleware Administering HTTP Session Management with Oracle Coherence*Web.