Have you noted that it complained about bundle m3 not being able to load javax.naming.Name and not javax.naming.Context?

Sahoo

On Thursday 02 June 2011 08:58 AM, Thiago Souza wrote:
Hi,

Moreover, that's exactly what your exceptions are telling. m3 should see javax.naming and m2 should see javax.sql also, since A2 extends from A1 which see javax.sql.

Cheers

On Thu, Jun 2, 2011 at 00:25, Thiago Souza <[email protected] <mailto:[email protected]>> wrote:

    Hello,

           As far as I could understand, you iterate between two CL.
    The one from module 2 (p2.A2.class.getClassLoader()) imports
    javax.naming, but the one from the activator's class
    (getClass().getClassLoader()) from module 3 does NOT imports
    javax.naming, so if you try to proxy using this last classloader
    it won't be possible since p2.A2 interface extends from
    javax.naming.Context.
           If this is the problem, to fix it module 3 must import
    javax.naming

           Hope this helps.

    Cheers

    On Wed, Jun 1, 2011 at 17:11, Sahoo <[email protected]
    <mailto:[email protected]>> wrote:

        Hi,

        I am having a strange problem using dynamic proxies. I am
        being forced to import more classes than required. I have
        reduced it to a simple scenario as shown below:

        module 1:
        package p1;
        public interface A1 extends javax.sql.PooledConnection {
        }

        Export-Package: p1
        Import-Package: javax.sql

        module 2:
        package p2;
        public interface A2 extends javax.naming.Context, p1.A1 {
        }

        Export-Package: p2
        Import-Package: javax.naming, p1

        module 3:
        Bundle-Activator: p3.Activator
        Import-Package: p2, org.osgi.framework

        public class Activator implements BundleActivator {
         public void start(BundleContext ctx) throws Exception {
          for (ClassLoader cl : new
        ClassLoader[]{getClass().getClassLoader(),
        p2.A2.class.getClassLoader()}) {
           try {
            System.out.println(cl);
            Object obj = Proxy.newProxyInstance(cl, new
        Class[]{p2.A2.class},
                       new InvocationHandler() {
                           public Object invoke(Object proxy, Method
        method, Object[] args) throws Throwable {return null;}
                       });
            System.out.println(obj);
           } catch(Throwable e) {
            e.printStackTrace();
           }
          } // for
         }
         public void stop(BundleContext ctx) throws Exception {}
        }

        It fails like this:

        3.0
        java.lang.NoClassDefFoundError: javax.naming.Name
        <http://javax.naming.Name> not found by m3 [3]
           at $Proxy0.<clinit>(Unknown Source)
           at
        sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
        Method)
           at
        
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
           at
        
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
           at
        java.lang.reflect.Constructor.newInstance(Constructor.java:513)
           at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
           at p3.Activator.start(Activator.java:11)
           at
        
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
           at
        org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
           at
        org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
           at
        org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1143)
           at
        org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
           at java.lang.Thread.run(Thread.java:619)
        2.0
        java.lang.NoClassDefFoundError:
        javax.sql.StatementEventListener not found by m2 [2]
           at $Proxy1.<clinit>(Unknown Source)
           at
        sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
        Method)
           at
        
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
           at
        
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
           at
        java.lang.reflect.Constructor.newInstance(Constructor.java:513)
           at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
           at p3.Activator.start(Activator.java:11)
           at
        
org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
           at
        org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
           at
        org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
           at
        org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1143)
           at
        org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
           at java.lang.Thread.run(Thread.java:619)

        It seems to me that JVM is assuming that the defining loader
        of the proxy class can load every class that appear in the
        signature of methods that can be invoked using the proxy
        class. Anybody interested to debug can use the attached
        sample. Just unzip and run run.sh after editing path to Felix.

        Thanks,
        Sahoo



        ---------------------------------------------------------------------
        To unsubscribe, e-mail: [email protected]
        <mailto:[email protected]>
        For additional commands, e-mail: [email protected]
        <mailto:[email protected]>




Reply via email to