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:
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.
startWeblogic
http://127.0.0.1:7001/console
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.
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:
web.xml in this WEB-INF directory and open it with an editor.
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>
defaultProxyApp directory you created earlier.
Click on the 'Select' button next to defaultProxyApp.
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.
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.
prompt> cd %WL_HOME%\samples\server\src\examples\cluster\sessionrep\inmemrep
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 ms2 172.17.14.79:7001
startManagedWeblogic httpProxy 172.17.14.79:7001
startManagedWeblogic ms1 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.
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.'
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.
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.
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.
Read more about: