ObjectWeb Consortium
Search ObjectWeb Mail Archive: 

Advanced Search - Powered by Google

Mail Archive Home | oscar List | March 2005 Index

<--  Date Index  --> <--  Thread Index  -->

Re: [oscar] Re:need info - servlet, RMI, SOAP...

I have tried everything I could think of, and either ended with "class not found" or "class cast exception". I was able to do rmi calls but only without the rmi class loading : putting the stubs into bundles and loading the stub classes through the osgi class loader.

In case you really need to use rmi you could always use the stub via reflection. As an afterthought, the solution to be able to use arbitrary remotely loaded stubs with already locally loaded interfaces seems to be to create yet another proxy. The java.lang.reflect.Proxy class springs to mind. As a general solution try the following:

public class RMItoLocalStubConverterFactory
    public static Object convertStubToInterface(final Object stub,
        final Class targetInterface)
        return Proxy.newProxyInstance(targetInterface.getClassLoader(),
new Class[] { targetInterface }, new ConvertionHandler(stub));

private static final class ConvertionHandler implements InvocationHandler

        private final Object m_stub;

        ConvertionHandler(final Object stub)
            m_stub = stub;

        public Object invoke(final Object proxy, final Method method,
            final Object[] args) throws Throwable
            return m_stub.getClass().getMethod(method.getName(),
                method.getParameterTypes()).invoke(m_stub, args);


The RMItoLocalStubConverterFactory is used like this:

Object getTheStub() = 0; // returns the stub loaded remotely by means of rmi String getTargetName() = 0; // returns the name of the interface to be used as a String

RMItoLocalStubConverterFactory. convertStubToInterface(getTheStub(),

=> for Example for the Interface Hello:

Hello myRemoteHelloThatCanBeUsedLocally =
(Hello) RMItoLocalStubConverterFactory. convertStubToInterface(getTheStub(),

Please note that this is a somewhat awkward workaround since it basically wraps something that is already a Proxy in yet another Proxy. More specific, since reflection is slow in java you just decreased the performance of your program by another degree. However, this solution should work and since you are trying to do ipc anyway this shouldn't be to painful.

Finally, please note that I'm unable to test the given solution at the moment, so in case it doesn't work: nevermind :-)

Hope that helps and regards,


Karl Pauls

<--  Date Index  --> <--  Thread Index  -->

Reply via email to:

Powered by MHonArc.

Copyright © 1999-2005, ObjectWeb Consortium | contact | webmaster.