PDA

View Full Version : Help with classloader issues in osgi


mebigfatguy
Apr 29th, 2008, 08:40 PM
Howdy, I am trying to get cxf working under osgi activated by spring-dm.

When not using osgi, cxf loads a SpringBusFactory to gather factories for various url namespaces which works fine. Under osgi it fails to do this and instead loads the default CXFBusFactory. The reason for the difference is that the cxf code attempts to load a file from the cxf jar file and fails. It uses this code, in cxf's

BusFactory.getBusFactoryClass

specifically:


String serviceId = "META-INF/services/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;
InputStream is = null;

if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}

if (classLoader == null) {
is = ClassLoader.getSystemResourceAsStream(serviceId);
} else {
is = classLoader.getResourceAsStream(serviceId);
}
if (is != null) {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
busFactoryClass = rd.readLine();
busFactoryCondition = rd.readLine();
rd.close();
}


and is is null. In both cases it uses the code path using

getResourceAsStream

I tried adding META-INF.services to the Export-Packages but that did nothing. Is there anything i can do here?

Costin Leau
May 3rd, 2008, 05:33 AM
There are several things that you could do here:
- export and import META-INF/services. This is not very nicely though.
- set the TCCL to that of the client (the bundle which exports META-INF/services). While the latter might be hard to achieve I think it's clearer and better.