This example demonstrates HTTP Session state replication using the HTTP Cluster Servlet to route requests for a JSP. By running this example you will learn how to set up a cluster, how to set up a proxy server outside the cluster, how to use the configuration wizard, how to use the Administration Console to install your applications, and how to set up the HTTP Cluster Servlet. When you are done, you will be able to bring down a server in your cluster and still maintain the session you had started in a JSP.

Note: You'll need a cluster license in order to run this example in a cluster environment. Contact your sales rep for more information.

These three sections cover what to do:

  1. Create the servers
  2. Set up the HTTP Cluster Servlet
  3. Build the example
  4. Start the Servers
  5. Install the Example
  6. Run the example

Create the servers (the cluster and the proxy)

  1. First you will have to set up a cluster. The cluster must consist of one Administration Server and two or more Managed Servers. For instructions on how to set up a basic cluster, see our Examples Clustering Guide.

  2. The HTTP Cluster Servlet acts as a proxy that forwards requests to the cluster. You must set up another server outside of the cluster to act as a proxy to host the HTTP Cluster Servlet. To configure a new server, start your Administration Server. Go to your bea_home/user_domains/myClusterDomain directory. The directory myClusterDomain was the domain that was created for your servers if you followed the steps in the Examples Clustering Guide. All the below instructions assume you followed those steps, if you are using a cluster of your own, use the values for your own particular setup.

  3. Type: startWeblogic

  4. This boots the Administration Server in the domain. Once your server is running, open the Administration Console with a browser. You must use the ip address and port number that you defined for the Administration Server. For example, you may enter the following URL:

    http://127.0.0.1:7001/console

  5. If prompted, fill in your username/password. Then select the 'Servers' folder in the left hand pane of the console. Select 'Configure a New Server.' Let's name this new server httpProxy. In the listen address field fill in the ip address of your machine. Make sure you enter a unique port number. Then click 'Create.' You should now have four servers (two managed, one administration, and this new httpProxy server) each on a separate port. Do not shut down your servers or console, we will need them for the following steps.

Set up the HTTP Cluster Servlet

The Http Cluster Servlet is included with your WebLogic Server installation. In order for it to function however, you will have to deploy it on the proxy server you just created and make it the default web application for that server. Follow the steps below; note that we have used the names that we selected above for our domain, if you used different names, substitute those for the myProxyDomain:

  1. Create a directory. Let's call it, 'defaultProxyApp'. Within this directory create another called WEB-INF.

  2. Create a file called web.xml in this WEB-INF directory and open it with an editor.

  3. The following is an example of how the web.xml file may look. You can just paste the text below into the file, however, you will want to modify the values in blue to match the server names and ports of the managed servers you specified when you created your cluster. Although that will be all you need to modify, what follows is an explanation of what this file does.

    The first stanza of this file maps to a DTD which is used by WebLogic to make sure you have used the proper syntax. The second stanza specifies the location of the actual servlet class you will be using. This file is located in the weblogic.jar in your WL_HOME /server/lib directory. There is no need to give the full location in the web.xml file because the weblogic.jar is put automatically in the CLASSPATH when you start WebLogic. The following stanza gives the server name and port number of the cluster members. If you were using SSL, each server would have a second port (ie ms1:7011:7012|ms2:7021:7022). The next two stanzas turn on debugging info which can be helpful in diagnosing errors. The last stanzas tell the HTTP Cluster Servlet which URLs to forward to the cluster. In this case, it will forward any requests ending in: '/', 'htm', 'html', or 'jsp'.

    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.
    //DTD Web Application 2.2//EN" 
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> 
    
    <web-app>
    
    <servlet>    
    <servlet-name>HttpClusterServlet</servlet-name>         
    <servlet-class>weblogic.servlet.internal.HttpClusterServlet</servlet-class> 
       
       <init-param>        
        <param-name>defaultServers</param-name>        
        <param-value>ms1:7011|ms2:7021</param-value>     
        </init-param>
        
        <init-param>
          <param-name>verbose</param-name> 
          <param-value>true</param-value> 
      </init-param>
      
        <init-param>        
        <param-name>DebugConfigInfo</param-name>        
        <param-value>ON</param-value>     
        </init-param>
    </servlet>
    
    <servlet-mapping>    
    <servlet-name>HttpClusterServlet</servlet-name>    
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>    
    <servlet-name>HttpClusterServlet</servlet-name>     
    <url-pattern>*.jsp</url-pattern> 
    </servlet-mapping>
    
    <servlet-mapping>    
    <servlet-name>HttpClusterServlet</servlet-name>     
    <url-pattern>*.htm</url-pattern> 
    </servlet-mapping>
    
    <servlet-mapping>    
    <servlet-name>HttpClusterServlet</servlet-name>     
    <url-pattern>*.html</url-pattern> 
    </servlet-mapping>
    
    </web-app>
    

  4. In your Administration Console home, select 'Web Applications' under 'Your Deployed Resources.' Select 'Configure a New Web Application.' At the bottom of the screen, navigate until you find the defaultProxyApp directory you created earlier. Click on the 'Select' button next to defaultProxyApp.

  5. Target the httpProxy server. Click 'Configure and Deploy.' Deployment will fail, since we haven't started the server yet, but the HTTP Proxy servlet will be deployed once you start the proxy server.

  6. It is necessary that the proxy server is explicitly told that the web application we have created for the HTTP Cluster Servlet is the default Web Appplication. In the left hand pane of the Administration Console, open the Servers directory and select the httpProxy node. Go to the 'Connections' tab and then select the 'HTTP' tab. Select 'defaultProxyApp' as your Default Web Application and click 'apply.'

    At this point you have an Administration Server, Managed Servers in a cluster, and one Managed Server outside the cluster that will use the HTTP cluster servlet to proxy requests to the cluster. Now we must build the example, start our servers and install the example so that it can be deployed to the cluster.

Build the Example

  1. Open a new command shell to build the example JSP.

  2. Set up your development shell as described in the examples Basic Steps.

  3. Move to the directory: prompt> cd %WL_HOME%\samples\server\src\examples\cluster\sessionrep\inmemrep

  4. Use the build script to compile the example. This will build both the JSP and descriptors and package them in a .war file called InMemRepClient.war. To compile, in the above directory, type: ant

Start the servers

Start all four of your servers, or whichever ones you do not currently have booted. Open four command shells in the directory bea_home/user_domains/myClusterDomain. To start the Administration Server, type:

startWebLogic

The syntax to start a managed server is: startManagedWebLogic managedserver_name ip_address:port (of Administration Server). So in the remaining shells, you would type:

startManagedWeblogic ms1 172.17.14.79:7001

startManagedWeblogic ms2 172.17.14.79:7001

startManagedWeblogic httpProxy 172.17.14.79:7001

You will likely want to stagger the starting of the servers so your machine is not swamped with trying to boot all four at once.

Install the Example

  1. Start you Administration Server and install the InMemRepClient.war that was created when you built the example. To do so, click the Application link at the Administration Console's home page. Click 'Configure a New Application.'

  2. Use the links at the bottom of the page to navigate to your WL_HOME\samples\server\src\examples\cluster\sessionrep\inmemrep\build directory. Select the InMemRepClient.war. Select the cluster that was previously created (mycluster) as your target for deployment. Select the 'Configure and Deploy' button.

Run the example

  1. Open a separate browser window in which you will run the client.

  2. Run the example by using syntax like, http://ip_address_of_proxy_server:port_of_proxy_server/InMemRepClient/Session.jsp. For example:

    http://127.0.0.1:7031/InMemRepClient/Session.jsp

    Add some values. Now bring down the server that you just requested the JSP from. Refresh the browser to demonstrate session persistence.

There's More...

Troubleshooting:

You can test the HTTP Cluster Servlet by using the following URL, substituting the correct ip address and port of the proxy server:

http://127.0.0.1:7051/foo.jsp?__WebLogicBridgeConfig

If you are having problems try rebooting all your servers, some of hte changes you made while configuring your setup may not have been persisted. Also, use the Administration Console of your Admin Server. The console is a powerful tool to spot mistaken ip addresses, undeployed applications, and misconfigured servers.

Documentation

Read more about: