We tried to configure a Directory instance to serve out static
resources from a particular classloader (in our case we must do this
to access the resource files stored inside an OSGi bundle, each bundle
has it's own classloader).

We set the directory's root reference to be something like
"clap://class/path/to/resource", following the instructions in the
Restlet docs.

Additionally, we made sure to set the custom class loader Request
attribtue, also as documented:

      request.getAttributes().put("org.restlet.clap.classloader",
bundleClassLoader);

However the Directory failed to serve out resources from the custom
classloader, and instead served resources from the classloader which
was providing the restlet classes.

In looking at the code, it seems that the
org.restlet.engine.local.DirectoryResource class is the culprit.  It
ignores everything in the incoming Request object except for the
target URI of the resource, and passes that URI to a call to
getClientDispatcher.get(targetURI).  Therefor the request attribute
for "org.restlet.clap.classloader" is ignored, and the
ClapClientHelper code never sees it.

As a work-around, we created a Directory subclass which uses the
"clap://thread/path/to/resource" strategy, and, on each request,
stores the current Thread's context class loader, replaces it with the
bundleClassLoader, and calls super.handle(), and then finally replaces
the original context class loader.

any thoughts?
  -Dave Fogel

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

Reply via email to