[jboss-cvs] JBoss Messaging SVN: r2552 - in branches/Branch_1_2_0_SP: tests/src/org/jboss/test/messaging/jms/message and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 16 12:14:45 EDT 2007
Author: clebert.suconic at jboss.com
Date: 2007-03-16 12:14:45 -0400 (Fri, 16 Mar 2007)
New Revision: 2552
Added:
branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/SomeObject.java
Modified:
branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/StreamUtils.java
branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-924 - fix
Added: branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
===================================================================
--- branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java (rev 0)
+++ branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java 2007-03-16 16:14:45 UTC (rev 2552)
@@ -0,0 +1,86 @@
+/*
+ * 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.messaging.util;
+
+import java.io.ObjectInputStream;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ObjectStreamClass;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class ObjectInputStreamWithClassLoader extends ObjectInputStream
+{
+
+ // Constants ------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public ObjectInputStreamWithClassLoader(InputStream in)
+ throws IOException
+ {
+ super(in);
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
+ {
+ String name = desc.getName();
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Class clazz = loader.loadClass(name);
+ // sanity check only.. if a classLoader can't find a clazz, it will throw an exception
+ if (clazz == null)
+ {
+ return super.resolveClass(desc);
+ }
+ else
+ {
+ return clazz;
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ return super.resolveClass(desc);
+ }
+ }
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
+}
Property changes on: branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
Modified: branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/StreamUtils.java
===================================================================
--- branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/StreamUtils.java 2007-03-16 15:33:06 UTC (rev 2551)
+++ branches/Branch_1_2_0_SP/src/main/org/jboss/messaging/util/StreamUtils.java 2007-03-16 16:14:45 UTC (rev 2552)
@@ -162,14 +162,14 @@
ObjectInputStream ois;
if (useJBossSerialization)
{
- ois = new JBossObjectInputStream(in);
+ ois = new JBossObjectInputStream(in, Thread.currentThread().getContextClassLoader());
}
else
{
- ois = new ObjectInputStream(in);
+ ois = new ObjectInputStreamWithClassLoader(in);
}
- value = (Serializable)ois.readObject();
+ value = ois.readObject();
break;
}
default :
Modified: branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageTest.java
===================================================================
--- branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageTest.java 2007-03-16 15:33:06 UTC (rev 2551)
+++ branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/ObjectMessageTest.java 2007-03-16 16:14:45 UTC (rev 2552)
@@ -24,13 +24,20 @@
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;
+import javax.jms.DeliveryMode;
import org.jboss.test.messaging.jms.message.base.MessageTestBase;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.StringTokenizer;
/**
* A test that sends/receives object messages to the JMS provider and verifies their integrity.
*
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
* @version <tt>$Revision$</tt>
*
* $Id$
@@ -64,6 +71,46 @@
super.tearDown();
}
+
+ public void testClassLoaderIsolation() throws Exception
+ {
+
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ queueProd.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ ObjectMessage om = (ObjectMessage) message;
+
+ SomeObject testObject = new SomeObject(3, 7);
+
+ ClassLoader testClassLoader = newClassLoader(testObject.getClass());
+
+ om.setObject(testObject);
+
+ queueProd.send(message);
+
+ Thread.currentThread().setContextClassLoader(testClassLoader);
+
+ ObjectMessage r = (ObjectMessage) queueCons.receive();
+
+ Object testObject2 = r.getObject();
+
+ assertEquals("org.jboss.test.messaging.jms.message.SomeObject", testObject2.getClass().getName());
+ assertNotSame(testObject, testObject2);
+ assertNotSame(testObject.getClass(), testObject2.getClass());
+ assertNotSame(testObject.getClass().getClassLoader(),
+ testObject2.getClass().getClassLoader());
+ assertSame(testClassLoader,
+ testObject2.getClass().getClassLoader());
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+
+ }
+
// Protected -----------------------------------------------------
protected void prepareMessage(Message m) throws JMSException
@@ -82,4 +129,37 @@
ObjectMessage om = (ObjectMessage)m;
assertEquals("this is the serializable object", om.getObject());
}
+
+ protected static ClassLoader newClassLoader(Class anyUserClass) throws Exception
+ {
+ URL classLocation = anyUserClass.getProtectionDomain().getCodeSource().getLocation();
+ StringTokenizer tokenString = new StringTokenizer(System.getProperty("java.class.path"), File.pathSeparator);
+ String pathIgnore = System.getProperty("java.home");
+ if (pathIgnore == null)
+ {
+ pathIgnore = classLocation.toString();
+ }
+
+ ArrayList urls = new ArrayList();
+ while (tokenString.hasMoreElements())
+ {
+ String value = tokenString.nextToken();
+ URL itemLocation = new File(value).toURL();
+ if (!itemLocation.equals(classLocation) && itemLocation.toString().indexOf(pathIgnore) >= 0)
+ {
+ //System.out.println("Location:" + itemLocation);
+ urls.add(itemLocation);
+ }
+ }
+
+ URL[] urlArray = (URL[]) urls.toArray(new URL[urls.size()]);
+
+ ClassLoader masterClassLoader = URLClassLoader.newInstance(urlArray, null);
+
+
+ ClassLoader appClassLoader = URLClassLoader.newInstance(new URL[]{classLocation}, masterClassLoader);
+
+ return appClassLoader;
+ }
+
}
Added: branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/SomeObject.java
===================================================================
--- branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/SomeObject.java (rev 0)
+++ branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/SomeObject.java 2007-03-16 16:14:45 UTC (rev 2552)
@@ -0,0 +1,85 @@
+/*
+ * 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.messaging.jms.message;
+
+import java.io.Serializable;
+
+/**
+ * ObjectMessageTest needed a simple class to test ClassLoadingIsolations
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ *
+ * $Id$
+ */
+public class SomeObject implements Serializable
+{
+
+ // Constants ------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ int i;
+ int j;
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public SomeObject(int i, int j)
+ {
+ this.i=i;
+ this.j=j;
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ SomeObject that = (SomeObject) o;
+
+ if (i != that.i) return false;
+ if (j != that.j) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = i;
+ result = 31 * result + j;
+ return result;
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
+}
Property changes on: branches/Branch_1_2_0_SP/tests/src/org/jboss/test/messaging/jms/message/SomeObject.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
More information about the jboss-cvs-commits
mailing list