diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-17 22:51:06 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-17 22:51:06 +0000 |
commit | c3f91c976547412d0a0aae5b4351c310a44064d0 (patch) | |
tree | cfd8a78ce3fd6d419fec1a066d44876ddbb17815 /java/sca/modules/binding-rmi-runtime/src | |
parent | 955e4941bc911f92daea288a335765fc37236da4 (diff) |
Fix classloading issue under OSGi
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@755435 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-rmi-runtime/src')
-rw-r--r-- | java/sca/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/java/sca/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java b/java/sca/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java index 2efb470d33..25d43445ec 100644 --- a/java/sca/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java +++ b/java/sca/modules/binding-rmi-runtime/src/main/java/org/apache/tuscany/sca/binding/rmi/provider/RMIServiceBindingProvider.java @@ -136,10 +136,35 @@ public class RMIServiceBindingProvider implements ServiceBindingProvider { }); Class<?> targetJavaInterface = getTargetJavaClass(serviceInterface); targetJavaInterface = RemoteInterfaceGenerator.generate(targetJavaInterface); - enhancer.setClassLoader(targetJavaInterface.getClassLoader()); + /* + * In OSGi, the classloader for the interface cannot access the classes for the CGLIB + */ + enhancer.setClassLoader(new MixedClassLoader(targetJavaInterface.getClassLoader(), getClass().getClassLoader())); enhancer.setInterfaces(new Class[] {targetJavaInterface}); return (Remote)enhancer.create(); } + + private static class MixedClassLoader extends ClassLoader { + private ClassLoader runtime; + + public MixedClassLoader(ClassLoader parent, ClassLoader runtime) { + super(parent); + this.runtime = runtime; + } + + @Override + protected Class<?> findClass(String name) throws ClassNotFoundException { + try { + return super.findClass(name); + } catch (ClassNotFoundException e) { + if (runtime != null && runtime != getParent()) { + return runtime.loadClass(name); + } else { + throw e; + } + } + } + } private Object invokeTarget(Operation op, Object[] args) throws InvocationTargetException { return wire.invoke(op, args); |