[Jboss-cvs] JBossAS SVN: r56554 - branches/Branch_3_2/system/src/main/org/jboss/system/pm

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 5 07:44:48 EDT 2006


Author: dimitris at jboss.org
Date: 2006-09-05 07:44:45 -0400 (Tue, 05 Sep 2006)
New Revision: 56554

Modified:
   branches/Branch_3_2/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
Log:
JBAS-3463, use the correct classloader when deserializing persisted custom mbean attributes

Modified: branches/Branch_3_2/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
===================================================================
--- branches/Branch_3_2/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java	2006-09-05 11:43:36 UTC (rev 56553)
+++ branches/Branch_3_2/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java	2006-09-05 11:44:45 UTC (rev 56554)
@@ -33,6 +33,7 @@
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.net.URL;
@@ -57,6 +58,7 @@
 import org.jboss.logging.Logger;
 import org.jboss.mx.persistence.AttributePersistenceManager;
 import org.jboss.system.server.ServerConfigLocator;
+import org.jboss.util.Classes;
 import org.jboss.util.file.Files;
 import org.w3c.dom.Comment;
 import org.w3c.dom.Document;
@@ -70,7 +72,7 @@
  * 
  * @author <a href="mailto:dimitris at jboss.org">Dimitris Andreadis</a>
  * @version $Revision$
-**/
+ */
 public class XMLAttributePersistenceManager
    implements AttributePersistenceManager
 {
@@ -730,19 +732,23 @@
       }
       
       Serializable retn = null;
-      
-      try {
+      try
+      {
+         // Use ObjectInputStreamExt that will utilise the
+         // ThreadContextClassLoader to deserialize objects
          ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-         ObjectInputStream ois = new ObjectInputStream(bais);
-         
+         ObjectInputStream ois = new ObjectInputStreamExt(bais);           
          retn = (Serializable)ois.readObject();
+         ois.close();
       }
-      catch (IOException e) {
-         log.warn("Cannot deserialize object", e);      }
-      catch (ClassNotFoundException e) {
+      catch (ClassNotFoundException e)
+      {
          log.warn("Cannot deserialize object", e);
+      }      
+      catch (IOException e)
+      {
+         log.warn("Cought IOException", e);
       }
-      
       return retn;
    }
    
@@ -947,4 +953,22 @@
          return Files.decodeFileName(file);
       }
    }
+   
+   /**
+    * Default implementation ObjectInputStream uses the System
+    * classloader to deserialize classes, by we need to use the
+    * ThreadContextClassLoader, instead.
+    */
+   private class ObjectInputStreamExt extends ObjectInputStream
+   {
+      ObjectInputStreamExt(InputStream is) throws IOException
+      {
+         super(is);
+      }
+
+      protected Class resolveClass(ObjectStreamClass v) throws IOException, ClassNotFoundException
+      {
+         return Classes.loadClass(v.getName());
+      }
+   }   
 }    




More information about the jboss-cvs-commits mailing list