Skip to content
Advertisement

tomcat session replication – not serialized exception

I am currently working on one messy web application. In this application, there is a class that holds all the data sources. And whenever the need to connect to a specific data source, the method in the instance of the class is called with a parameter to select the data source.And class is like follows

   public class MyConnection implements Runnable,DbConnection, Serializable
   { 
       private static final long serialVersionUID=2007L;
       public static transient DataSource FirstDatasource;
       public static transient DataSource SecondDatasource;
           BaseDbConnection _bidc;
           ....

And on each page, this object is to get and set to the session(I don’t know why like this). And it works fine with the current setup. (clustering, load balancing etc..)

But my work is to implement fail-over, and when I enable session replication(in memory – simple TCP), writing the session is failing and its throwing the following exception

 org.apache.catalina.ha.session.DeltaManager requestCompleted
 SEVERE: Unable to serialize delta request for sessionid [FE02AF01C76F41D042FE04692462D983.tomcat1]
 java.io.NotSerializableException: org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
 at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
 .....

Since there are more than “I can count” no of pages, it’s not easy to replace the code which sets the connection object in session from each and every page. And the complete app is based on this connection object(Datasources also play an important role).

Is there a way I can change this class so that it can be persisted in session?

Advertisement

Answer

If I understood correctly, I would say that replicating a DataSource is not correct, it can not work.

What need to be done is, after deserialing, to get a new (local) DataSource that corresponds to the need, and set it in the field. It is possible that this happens already in your code, look for a readResolve method.

If some parameters are needed to know which DataSource, they can be serialized themselves (because they are no DataSource, they could be just Strings for example).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement