Session Replication Error in clustered environment

Discussions

Web tier: servlets, JSP, Web frameworks: Session Replication Error in clustered environment

  1. In my servlet,I have an object(QUEUERECEIVER) I am storing it in the
    HttpSession using getSession().setAttribute. The object is an instance
    of QueueReceive class ( code attached below).I have also turned on the
    session replication using PersistentStoreType in weblogic.xml.
    Since this is running in a clustered environment with multiple
    servers, the submitted request can go to a different server and it
    will try to do a getAttribute for the QUEUERECEIVER object.

    The session replication is failing with the exception below. Does
    anyone has any ideas to this problem. Please let me know if more
    details are required.
    I am using weblogic 7.0

    Thanks
    Raja

    java.io.NotSerializableException: weblogic.jms.client.JMSConsumer
            at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1143)
            at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
            at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1822)
            at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:475)
            at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1209)
            at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
            at java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1822)
            at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:475)
            at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1209)
            at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:361)
            at java.util.Hashtable.writeObject(Hashtable.java:759)
            at java.lang.reflect.Method.invoke(Native Method)


    --------------------------------X Code of QueueReceive.java
    X-------------------
    import java.io.*;
    import java.util.*;
    import javax.transaction.*;
    import javax.naming.*;
    import javax.jms.*;

    /**
     */
    public class QueueReceive
        implements MessageListener,Serializable {
      /**
       * Defines the JNDI context factory.
       */
      public final static String JNDI_FACTORY =
          "weblogic.jndi.WLInitialContextFactory";

      /**
       * Defines the JMS connection factory for the queue.
       */
      public final static String JMS_FACTORY = "md.bridge.cf";

      /**
       * Defines the queue.
       */
      public final static String QUEUE = "md_receiver_queue";

      private QueueConnectionFactory qconFactory;
      private QueueConnection qcon;
      private QueueSession qsession;
      private QueueReceiver qreceiver;
      private Queue queue;
      private boolean quit = false;

      private boolean done = false;
      private String correlationId = "";
      private boolean background = false;
      private String responseMessage = null;

      /**
       * Message listener interface.
       * @param msg message
       */

      public synchronized boolean isDone() {
        return done;
      }

      public synchronized void setBackground() {
        background = true;
      }

      public synchronized boolean isBackground() {
        return background;
      }

      public synchronized String getResponseStr() {
        return responseMessage;
      }

      // MessageListener interface
      public void onMessage(Message msg) {
        try {
          String msgText;
          if (msg instanceof TextMessage) {
            msgText = ( (TextMessage) msg).getText();
          }
          else {
            msgText = msg.toString();
          }
          this.responseMessage = msgText;

          synchronized (this) {
            done = true;
            if (background == true) {
              qsession.rollback();
              System.out.println("Redirecting to background queue");
            }
            else {
              qsession.commit();
            }
          }
    // this.close();
        }
        catch (JMSException jmse) {
          jmse.printStackTrace();
        }
        finally {
        }
      }
      /**
       *
       * @param ctx Context
       * @param queueName String
       * @throws NamingException
       * @throws JMSException
       */
      public void init(Context ctx, String queueName) throws
    NamingException,
          JMSException {
        qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_FACTORY);
        qcon = qconFactory.createQueueConnection();
        qsession = qcon.createQueueSession(true, -1);
        queue = (Queue) ctx.lookup(queueName);
        String selector = "JMSCorrelationID = '" + correlationId + "'";
        qreceiver = qsession.createReceiver(queue, selector);
        qreceiver.setMessageListener(this);
        qcon.start();
      }

      /**
       * Closes JMS objects.
       * @exception JMSException if JMS fails to close objects due to
    internal error
       */
      public void close() throws JMSException {
        qreceiver.close();
        qsession.close();
        qcon.close();
      }
      public QueueReceive(String correlationId)

      {
        try {
          this.correlationId = correlationId;
          InitialContext ic = getInitialContext("t3://yukon-dev:7003");
          this.init(ic, QUEUE);
        }
        catch (javax.naming.NamingException ne) {
          System.out.println("Naming exception occured");
          ne.printStackTrace();
        }
        catch (javax.jms.JMSException je) {
          System.out.println("JMS exception occured");
          je.printStackTrace();
        }
      }


      private static InitialContext getInitialContext(String url) throws
          NamingException {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
        env.put(Context.PROVIDER_URL, url);
        env.put(Context.SECURITY_PRINCIPAL, "system");
        env.put(Context.SECURITY_CREDENTIALS, "********");

        return new InitialContext(env);
      }


    }

    Threaded Messages (2)

  2. Implement java.io.Serializable[ Go to top ]

    You need to implement java.io.Serializable in your object. That is the java interface for reading and writing the state of an object. Otherwise, java does not know how to transport your class from one JVM to the next.


    You wrote:
    The session replication is failing with the exception below.

    Doesanyone has any ideas to this problem. Please let me know if moredetails are required.I am using weblogic 7.0

    java.io.NotSerializableException:
  3. Oops.[ Go to top ]

    Sorry. I see that you are.....

    Are you sure that all of the contained objects of your class are also implementing Serializable? You might want to check that, because if one of them has a member variable that is not serializable, it will not work.