We've been using Restlet and OSGi, and recently we've begin using
Spring DM (Dynamic Modules) in our stack, which is a way to integrate
Spring's dependency injection and other tools with an OSGi server
environment.

We maintain our own build of Restlet, based on the trunk, with local
changes to fix show-stopper bugs, and one change we had to make in
order to work with Spring DM is in Engine.getClassLoader().  I figured
I should mention it here.  :-)

Engine.getClassLoader() is used by the Engine class's constructor to
find helper classes, like external connector implementations.   It's
implementation checks first for the Thread context classloader, which
it will use in preference to it's own Engine.class.getClassLoader().
The problem with this is that if any other library happens to use the
Thread context classloader, even if that use is intended to be
independent of Restlet, then the wrong classloader is searched for
Restlet helper connectors.  This is the case with Spring DM, which
sets the thread classloader to be the one used in configuring it's
bean contexts.  Since this classloader doesn't know anything at all
about the location of restlet connector extension libraries, Restlet
is unable to load any ext connectors.

The change we made locally was to remove this usage of the
ContextClassLoader.  We also removed the usage of the System
classloader, since that code is basically unreachable (only executes
if Engine.class.getClassLoader() returns null, which is impossible).

Now, it's possible that some people are relying on the existing
behavior of checking the thread context classloader first.  (My guess
is that anyone relying on this probably wishes they didn't have to).
If it's important to maintain the current behavior, then I suggest
that the helper/extension finding code be changed to look in
_multiple_ classloaders for potential helper classes, and not just the
first one that happens to be found.  This would not disrupt people
relying on the current code, and would enable much better behavior for
osgi and other environments which don't have one big central
classloader.

-Dave Fogel

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2335380

Reply via email to