Hi,

Jay SenSharma

Jay SenSharma

Sometime we find Session Replication related Issues while using the Clustering Features of Weblogic. like: <BEA-000126> <All session objects should be serializable to replicate. Check the objects in your session. Failed to replicate non-serializable object.>

USEFUL Debuging techinques:

Enable the Debug Flags to track Session Replication Failures:

You could enable the flags DebugCluster, DebugClusterAnnouncements, DebugFailOver, DebugReplication, DebugReplicationDetails.

To Enable: You can use the weblogic.Admin command line utility to dynamically turn the debug options on and off.

For example, to turn on DebugCluster on all administration instances of ServerDebug Mbean (i.e., Admin Server or al Managed Server):

java weblogic.Admin -url t3://localhost:7001 -username system -password weblogic SET -type ServerDebug -property DebugCluster true

***Symptoms***:

1). After Logging into the Application which is deployed on WebLogic Cluster… Users suddenly finds themself to be redirected to Login page again even if they haven’t clicked on Logout Button.

2). In these cases There may be many reasons behind this…There may be Multicast Issues(Network Issues) in the Network where the WebLogic Clusters are running. Means Managed Servers which is part of the Cluster are not able to send Heartbeat messages to eachother. In these kind of scenario first of all we need to Apply the Multicast Test Utility provided as part of WebLogic. For more Informations you can refer to “http://download-llnw.oracle.com/docs/cd/E13222_01/wls/docs81/admin_ref/utils25.html” Multicast Util Informations.

3). Getting java.io.NotSerializableException” in Server Logs

4). May be the Default Session Cookie Name is different in “weblogic.xml” and It’s not same as the Web Proxy Default Cookie Name.

Parameter Default Description Applicable to
CookieName JSESSIONID If you change the name of the WebLogic Server session cookie in the WebLogic Server Web application, you need to change the CookieName parameter in the plug-in to the same value. The name of the WebLogic session cookie is set in the WebLogic-specific deployment descriptor, in the <session-descriptor>element.Note: The CookieName parameter has been renamed as WLCookieName. A warning message is issued if you continue to use the old parameter name. NSAPI, ISAPI, and Apache plug-in, HttpClusterServlet, and HttpProxyServlet

In most of the Cases i have observed that Users get Logged off from our applications which is targeted to a Cluster .is because of the Application. If an application is storing some NonSerializable Data Objects inside the HttpSession as an attribute then the WebLogic Cluster is not able to replicate these Non-Serializable data to the replicated HttpSession on another Secondary Managed Servers. For a Large scale applications it is not an easy task for developers to check the complete code again…sothat they can identify that all the HttpSession Attributes are implementing the java.io.Serializable interface or not.

Here is a simple JSP page which is able to display all the HttpSession attributes in a tabular format along with the report that Which Session Attribute is Not Serializable. We need to Just bundle this JSP inside our existing application which is causing the issue. Then we need to login to our application we need to access this additional page “SerializationTest.jsp” sothat if any HttpSession attribute is already stored inside the HttpSession then it can display it’s complete information.

***NOTE:
Here i am providing a complete TestCase for this JSP…to demonstrate How actually it works..But you need to add only the “SerializationTest.jsp” page inside your application which is causing the issue

SerializationTest.jsp
—————————-

<%@ page import=”java.util.*” %>
<table border=10%>
<TR><TH>Session Attribute Name</TH><TH>Session Attribute Value</TH><TH>STATUS</TH></TR>
<%
Enumeration en=session.getAttributeNames();
while(en.hasMoreElements())
{
String attrName=(String)en.nextElement();
if(session.getAttribute(attrName) instanceof java.io.Serializable)
out.println(“<TR><TD>”+attrName+”</TD><TD>”+session.getAttribute(attrName)+”</TD><TD><font color=green> SERIALIZABLE</font></TD></TR>”);
else
out.println(“<TR><TD>”+attrName+”</TD><TD>”+session.getAttribute(attrName)+”</TD><TD><font color=red><b>NOT SERIALIZABLE</b></font></TD></TR>”);
}

%>
</table>
—————————-

*********Complete TestCase Below:**********

Just to know how it actually works Just develop a Sample Web Application with the following details

Step1). Develop a classes “Emp.java” here Emp class should NOT implement the “java.io.Serializable” interface.

package pack;
public class Emp
{
String name=”Default Name”;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name=name;
}
}
Step2). Develop a classes “Salesman.java” here Emp class should implement the “java.io.Serializable” interface.

package pack;
public class Salesman implements java.io.Serializable
{
String name=”Default Salesman Name”;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name=name;
}
}

Step3). Compile the above two classes and place them inside your WebApplications “WEB-INF/classes” directory

D:DELETESessionTestWEB-INFclasses> javac -d . Emp.java
D:DELETESessionTestWEB-INFclasses> javac -d . Salesman.java

Step4). Now provide the “index.jsp” Page as below:
index.jsp
————————
<%
session.setAttribute(“EmpAttribute”,new pack.Emp());
session.setAttribute(“SalesmanAttribute”,new pack.Salesman());
%>
<center>
<h2> Session Object Created with the Following Attributes: </h2><BR>
</center>

<h4>
<BR>
session.setAttribute(“EmpAttribute”,new pack.Emp());
<BR>
session.setAttribute(“SalesmanAttribute”,new pack.Salesman());

<BR><BR><BR>

<center>
<a href=”SerializationTest.jsp”> Click Here To Check Which one is Serializable</a>
</center>
————————

Step5). Now provide the Sample “web.xml” we don’t need to enter much information in this file …as it is just a TestCase.

<web-app xmlns=”http://java.sun.com/xml/ns/j2ee“>
</web-app>

Step6). Now If you want to enable Session Replication for your WebApplication then provide the “weblogic.xml” file like below…(In our TestCase at present this is not required…as we are just going to test The HttpSession attribute is Serializable or Not. it can be tested in a NonClustered Managed Server as well)

<?xml version=”1.0″ encoding=”UTF-8″?>
<weblogic-web-app xmlns=”http://www.bea.com/ns/weblogic/90“>
<session-descriptor>
<persistent-store-type>replicated</persistent-store-type>
</session-descriptor>
</weblogic-web-app>
Step7). Now Deploy your Application in WebLogic Server…

Step 8). Access the “index.jsp” page of your application then you will find the following output

NOTE:

The HttpSession replication happens Only when WebLogic creates a New HttpSession or Container encounters “session.setAttribute(obj,obj)” method…It means the Data is replicated to the Secondary JVM HttpSession only when application calls the setAttribute method of HttpSession. And in this case only the modified part of data is replicated NOT the complete HttpSession data.

So i think u can try adding a Simple temporary attribute in the HttpSession like
session.setAttribute(“dummyData”,””+new java.util.Date());

Now make sure that the above code is placed in each and every page of your application…sothat whenever a client will request the because of setAttribute() the Session modified data (dummyData) will be replicated…and if there are more setAttribute() on that page then all the those also will be replicated…

Example:

Map map = new HashMap();
session.setAttribute(“map”, map); ——-> Here Session data Will be replicated to Node-2 (bcoz of setAttribute())
map.put(“one”, “aaa”); No Replication (Means No Session data Refresh…bcoz setAttribute is not called…) then from page1.jsp I go to page2.jsp and I do this:
Map map = (Map)session.getAttribute(“map”);
map.put(“two”, “bbb”); No Replication (Means No Session data Refresh…bcoz setAttribute is not called…)
and then from page2.jsp I go to page3.jsp and I do this:
Map map = (Map)session.getAttribute(“map”);
map.put(“three”, “ccc”); No Replication (Means No Session data Refresh…bcoz setAttribute is not called…)

.

.

Thanks

Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.