[jboss-cvs] JBoss Messaging SVN: r3551 - trunk/src/main/org/jboss/jms/message.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 9 03:42:36 EST 2008


Author: jmesnil
Date: 2008-01-09 03:42:36 -0500 (Wed, 09 Jan 2008)
New Revision: 3551

Modified:
   trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
Log:
* lazy deserialized the object the first time the client requests it
* used StreamUtils.readObject() to ensure the object is deserizalized using the current thread's context class loader

Modified: trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java	2008-01-09 06:49:58 UTC (rev 3550)
+++ trunk/src/main/org/jboss/jms/message/JBossObjectMessage.java	2008-01-09 08:42:36 UTC (rev 3551)
@@ -21,10 +21,9 @@
   */
 package org.jboss.jms.message;
 
+import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
 import java.io.Serializable;
 
 import javax.jms.JMSException;
@@ -93,7 +92,6 @@
    
    public void doBeforeReceive() throws Exception
    {
-      beforeReceive();
    }
    
    
@@ -106,11 +104,32 @@
       this.object = object;
    }
 
+   // lazy deserialize the Object the first time the client requests it
    public Serializable getObject() throws JMSException
    {
-      return object;
+      if (object != null)
+      {
+         return object;
+      }
+      else if (message.getPayload() != null)
+      {
+         DataInputStream dais = new DataInputStream(new ByteArrayInputStream(message.getPayload()));
+         try
+         {
+            readPayload(dais);
+         }
+         catch (Exception e)
+         {
+            RuntimeException e2 = new RuntimeException(e.getMessage());
+            e2.setStackTrace(e.getStackTrace());
+            throw e2;
+         }         
+         return object;
+      } else {
+         return null;
+      }
    }
-   
+
    public void clearBody() throws JMSException
    {
       super.clearBody();
@@ -124,15 +143,12 @@
    
    protected void writePayload(DataOutputStream daos) throws Exception
    {
-      ObjectOutputStream oos = new ObjectOutputStream(daos);               
-      oos.writeObject(object);
-      oos.flush();
+      StreamUtils.writeObject(daos, object, false, true);
    }
    
    protected void readPayload(DataInputStream dais) throws Exception
    {
-      ObjectInputStream ois = new ObjectInputStream(dais);
-      object = (Serializable)ois.readObject();
+      object = (Serializable)StreamUtils.readObject(dais, true);
    }
 
    // Private -------------------------------------------------------




More information about the jboss-cvs-commits mailing list