Hi there,

I have a bundle which exports an object via RMI. In another OSGi runtime B, I
have another bundle which uses this remote object using the code below:

if (System.getSecurityManager() == null)
 System.setSecurityManager ( new RMISecurityManager() );
Registry registry = LocateRegistry.getRegistry(remoteHostAddress);

RemoteServiceInterface rmiProxy = (RemoteServiceInterface)
registry.lookup("remoteObjectKey");

This all works fine and I am able to invoke the methods on the remote object.

However, when I pass my obtained rmiProxy object to any other bundle in the same
frameowrk instance B, that bundle is unable to cast the rmiProxy object to the
RemoteServiceInterface. The following is the stack trace:

Client exception: java.lang.ClassCastException: $Proxy0
java.lang.ClassCastException: $Proxy0
        at importer4rmi.Activator.start(Activator.java:44)
        at
org.eclipse.osgi.framework.internal.core.BundleContextImpl$2.run(BundleContextImpl.java:999)
        at java.security.AccessController.doPrivileged(Native Method)
        at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:993)
        at
org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:974)
        at
org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:346)
        at
org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:350)
        at
org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1118)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:634)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:508)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:282)
        at
org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:468)
        at
org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:195)
        at
org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:297)


In general, I noticed that the bundle who obtains the rmiProxy object via the
Registry.lookup(name) method, is the only one who can correctly cast the
returned object to one of the implemented interfaces.

Any idea why this behaviour??. I suspect it is a class loader issue because the
two bundles will have different class loaders. Note that I am using jdk1.5 and
have enabled the new feature of dynamic proxy generation to avoid the need to
run the rmic tool.

best regards
_______________________________________________
OSGi Developer Mail List
[email protected]
http://www2.osgi.org/mailman/listinfo/osgi-dev

Reply via email to