-
1. Re: Classloading issues with EJBs; messages in EJB classload
genman Mar 16, 2007 4:00 AM (in response to genman)Analysis:
Seems that ObjectInputStream takes the classloader of the calling method. This is the scoped classloader used in JBoss Messaging. Perhaps something like this would be in order. The classloader used should belong to the context classloader.
http://docs.jboss.com/jbossas/javadoc/4.0.4/iiop/org/jboss/util/stream/CustomObjectInputStreamWithClassloader.html -
2. Re: Classloading issues with EJBs; messages in EJB classload
genman Mar 16, 2007 4:01 AM (in response to genman)Also see this:
http://fisheye.labs.jboss.com/browse/JBoss/jbossmq/src/main/org/jboss/mq/SpyObjectMessage.java?r=1.13.2.4
I'm filing an issue... -
3. Re: Classloading issues with EJBs; messages in EJB classload
clebert.suconic Mar 16, 2007 11:07 AM (in response to genman)StreamUtils should be using something like ObjectInputStreamWithClassLoader.
case SERIALIZABLE: { ObjectInputStream ois; if (useJBossSerialization) { ois = new JBossObjectInputStream(in); } else { ois = new ObjectInputStream(in); } value = (Serializable)ois.readObject(); break; }
-
4. Re: Classloading issues with EJBs; messages in EJB classload
timfox Mar 16, 2007 11:10 AM (in response to genman)Clebert is right. Good catch :)
-
5. Re: Classloading issues with EJBs; messages in EJB classload
timfox Mar 16, 2007 11:11 AM (in response to genman)We already use the ObjectInputStreamWithClassLoader for remoting internal serialization stuff but seem to have omitted it for object messages
-
6. Re: Classloading issues with EJBs; messages in EJB classload
clebert.suconic Mar 16, 2007 11:13 AM (in response to genman)I'm wondering how could we create a testcase for this, playing with classLoaders?
-
7. Re: Classloading issues with EJBs; messages in EJB classload
timfox Mar 16, 2007 11:25 AM (in response to genman)Might be quite fiddly.
You could create your own classloader that loads it classes from a different place to the classpath used to run the servicecontainer. Allow it only access to the class used to set the object message.
Then set the context classloader before running the test and verify the test passes (the test should try sending an object message with the body being the class that is only accessible by the special classloader)
Unset the classloader and the test should fail. -
8. Re: Classloading issues with EJBs; messages in EJB classload
timfox Mar 16, 2007 11:29 AM (in response to genman)Also I have made a kind-of related change where, as suggested by Bill Burke, we don't use Class.forName() to load classes in the code since they won't pick up classes that are scoped.
Also getResource() and getResourceAsStream().
I am just testing this now then will commit. -
9. Re: Classloading issues with EJBs; messages in EJB classload
clebert.suconic Mar 16, 2007 11:30 AM (in response to genman)I thought about something like that.. but we will need to create another sourceTree to have just those classes.
I thought also about defining a ClassLoader... send an ObjectMessage... read the ObjectMessage and assert:
assertSame(TCL, objectRead.getClass().getClassLoader()); -
10. Re: Classloading issues with EJBs; messages in EJB classload
timfox Mar 16, 2007 11:40 AM (in response to genman)"clebert.suconic@jboss.com" wrote:
I thought about something like that.. but we will need to create another sourceTree to have just those classes.
Well you would only need one class - and it could be a trivial class.
I thought also about defining a ClassLoader... send an ObjectMessage... read the ObjectMessage and assert:
assertSame(TCL, objectRead.getClass().getClassLoader());
Yes that should work. Just need to make sure that the TCL and the "normal" classloader are different so you can distinguish them. -
11. Re: Classloading issues with EJBs; messages in EJB classload
clebert.suconic Mar 16, 2007 12:17 PM (in response to genman)I have created ObjectMessageTest::testClassLoaderIsolation
I have removed the fix to validate if the test would fail and it worked. I have then fixed this into http://anonsvn.jboss.org/repos/messaging/branches/Branch_1_2_0_SP/
Just a FYI, the issue genman raised was http://jira.jboss.org/jira/browse/JBMESSAGING-924