[jboss-cvs] JBossAS SVN: r57376 - in branches/JBoss_4_0_4_GA_CP: system/src/main/org/jboss/system/pm testsuite/imports/sections testsuite/src/main/org/jboss/test/jmx/test testsuite/src/main/org/jboss/test/jmx/xmbean testsuite/src/resources/jmx/xmbean testsuite/src/resources/jmx/xmbean/custom-attr-pers

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Oct 2 23:01:22 EDT 2006


Author: ryan.campbell at jboss.com
Date: 2006-10-02 23:01:20 -0400 (Mon, 02 Oct 2006)
New Revision: 57376

Added:
   branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/xmbean/ServiceUsingCustomAttribute.java
   branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/
   branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml
   branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml
Removed:
   branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml
   branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml
Modified:
   branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
   branches/JBoss_4_0_4_GA_CP/testsuite/imports/sections/jmx.xml
   branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java
Log:
ASPATCH-51: JBAS-3623: Backport JBAS-3463 to 4.0.4.GA

Modified: branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java	2006-10-03 02:46:09 UTC (rev 57375)
+++ branches/JBoss_4_0_4_GA_CP/system/src/main/org/jboss/system/pm/XMLAttributePersistenceManager.java	2006-10-03 03:01:20 UTC (rev 57376)
@@ -1,24 +1,24 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.system.pm;
 
 import java.beans.PropertyEditor;
@@ -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());
+      }
+   }   
 }    

Modified: branches/JBoss_4_0_4_GA_CP/testsuite/imports/sections/jmx.xml
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/imports/sections/jmx.xml	2006-10-03 02:46:09 UTC (rev 57375)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/imports/sections/jmx.xml	2006-10-03 03:01:20 UTC (rev 57376)
@@ -647,6 +647,18 @@
          </fileset>
       </jar>
       
+      <!-- Test xmbean persistence with a custom attribute -->
+      <jar destfile="${build.lib}/xmbean-custom-attr-pers.sar">
+         <metainf dir="${build.resources}/jmx/xmbean/custom-attr-pers">
+            <include name="jboss-service.xml"/>
+            <include name="jboss-xmbean.xml"/>
+         </metainf>
+         <fileset dir="${build.classes}">
+            <include name="org/jboss/test/jmx/xmbean/CustomType.class"/>
+             <include name="org/jboss/test/jmx/xmbean/ServiceUsingCustomAttribute.class"/>
+         </fileset>    	
+      </jar>
+   	
       <!-- Test xmbean descriptor importing an external xml entity -->
       <jar destfile="${build.lib}/xmbean-entity-import.sar">
          <metainf dir="${build.resources}/jmx/xmbean/xmbean-entity-import">

Modified: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java
===================================================================
--- branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java	2006-10-03 02:46:09 UTC (rev 57375)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/test/XMLAttributePersistenceManagerUnitTestCase.java	2006-10-03 03:01:20 UTC (rev 57376)
@@ -1,24 +1,24 @@
 /*
-* JBoss, Home of Professional Open Source
-* Copyright 2005, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.test.jmx.test;
 
 import javax.management.Attribute;
@@ -28,6 +28,7 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.test.JBossTestCase;
+import org.jboss.test.jmx.xmbean.CustomType;
 
 /**
  * Tests for XMLAttributePersistenceManager
@@ -43,7 +44,53 @@
    }
 
    /**
-    * [JBAS-1988], test we can write/read to a directory that contains spaces in its name. 
+    * JBAS-3463, persist custom mbean attributes using the default setup
+    * of the AttributePersistenceService / XMLAttributePersistenceManager.
+    */
+   public void testPersistCustomMBeanAttributes() throws Exception
+   {
+      Logger log = getLog();
+      log.info("+++ testPersistCustomMBeanAttributes");
+      
+      String testService = "xmbean-custom-attr-pers.sar";
+      String customMBean = "jboss.test:service=ServiceUsingCustomAttribute";
+      
+      MBeanServerConnection server = super.getServer();
+      // This works when AttributePersistenceService is setup by default
+      ObjectName aps = new ObjectName("jboss:service=AttributePersistenceService");
+      // Cleanup persisted image
+      server.invoke(aps, "apmRemove", new Object[] { customMBean }, new String[] { "java.lang.String" });
+      try
+      {
+         deploy(testService);
+         ObjectName target = new ObjectName(customMBean);
+         CustomType ct = new CustomType(777, 888);
+         // Attribute must be set and persisted
+         server.setAttribute(target, new Attribute("Attr", ct));
+         // redeploy
+         undeploy(testService);
+         // this fails if deserialization of the custom attribute fails
+         deploy(testService);
+         // otherwise we should be aple to read back the persisted attribute
+         ct = (CustomType)server.getAttribute(target, "Attr");
+         assertTrue("CustomType.x == 777", ct.getX() == 777);
+         assertTrue("CustomType.y == 888", ct.getY() == 888);
+         // Cleanup persisted image
+         server.invoke(aps, "apmRemove", new Object[] { customMBean }, new String[] { "java.lang.String" });          
+      }
+      catch (Exception e)
+      {
+         getLog().warn("Caught exception", e);
+         fail("Unexcepted Exception, see the Log file");
+      }      
+      finally
+      {
+         undeploy(testService);
+      }    
+   }
+   
+   /**
+    * JBAS-1988, test we can write/read to a directory that contains spaces in its name. 
     * 
     * @see org.jboss.test.jmx.xmbean.XMLAttributePersistenceManagerTestService
     */

Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/main/org/jboss/test/jmx/xmbean/ServiceUsingCustomAttribute.java (from rev 57375, branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/main/org/jboss/test/jmx/xmbean/ServiceUsingCustomAttribute.java)

Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers (from rev 57375, branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/resources/jmx/xmbean/custom-attr-pers)

Deleted: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml
===================================================================
--- branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml	2006-10-03 02:46:09 UTC (rev 57375)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml	2006-10-03 03:01:20 UTC (rev 57376)
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE server
-    PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
-    "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
-
-<server>
-
-   <mbean code="org.jboss.test.jmx.xmbean.ServiceUsingCustomAttribute"
-      name="jboss.test:service=ServiceUsingCustomAttribute"
-      xmbean-dd="META-INF/jboss-xmbean.xml" />
-
-</server>

Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml (from rev 57375, branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-service.xml)

Deleted: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml
===================================================================
--- branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml	2006-10-03 02:46:09 UTC (rev 57375)
+++ branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml	2006-10-03 03:01:20 UTC (rev 57376)
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mbean PUBLIC
-   "-//JBoss//DTD JBOSS XMBEAN 1.2//EN"
-   "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_2.dtd">
-
-<mbean>
-   <description>Test of ServiceUsingCustomAttribute</description>
-   <descriptors>
-      <persistence persistPolicy="OnUpdate"/>
-      <persistence-manager value="org.jboss.mx.persistence.DelegatingPersistenceManager"/>
-   </descriptors>          
-   <class>org.jboss.test.jmx.xmbean.ServiceUsingCustomAttribute</class>
-
-   <!-- Attributes -->
-   <attribute access="read-write" getMethod="getAttr" setMethod="setAttr">
-      <description>A custom attribute</description>
-      <name>Attr</name>
-      <type>org.jboss.test.jmx.xmbean.CustomType</type>
-   </attribute>
-   
-   <!-- Operations -->
-   <operation>
-     <description>Set the custom attribute through the MBeanServer</description>
-     <name>selfTest</name>
-   </operation>
-      
-   <operation>
-     <description>Print out the stored custom attribute</description>
-     <name>show</name>
-     <return-type>java.lang.String</return-type>
-   </operation>
-</mbean>
\ No newline at end of file

Copied: branches/JBoss_4_0_4_GA_CP/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml (from rev 57375, branches/JBoss_4_0_4_GA_JBAS-3623/testsuite/src/resources/jmx/xmbean/custom-attr-pers/jboss-xmbean.xml)




More information about the jboss-cvs-commits mailing list