1 Reply Latest reply: May 9, 2012 10:12 AM by ermag RSS

    classloading issue in fragment bundle

    ermag Community Member

      I've implemented a custom Persistence Manager that uses Gigaspaces XAP as the backing datastore.

       

      I've succeeded in getting CQ5.5 to try to use it by packaging the Persistence Manager and related classes as a fragment bundle with Fragment-Host: com.day.crx.sling.server. StartLevel is 15.

       

      However, I get an exception on startup that seems to be related to classloading, OSGi and/or security managers:

       

       

      INFO: exception occurred during unicast discovery to localhost:64499 with constraints InvocationConstraints[reqs: {}, prefs: {}]
      java.lang.ClassNotFoundException: com.sun.jini.reggie.RegistrarProxy (no security manager: RMI class loader disabled)
          at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:375)
          at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:165)
          at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:620)
          at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:247)
          at net.jini.loader.ClassLoading.loadClass(ClassLoading.java:149)
          at net.jini.io.MarshalInputStream.resolveClass(MarshalInputStream.java:296)
          at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1574)
          at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
          at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
          at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
          at com.sun.jini.discovery.DiscoveryV1.doUnicastDiscovery(DiscoveryV1.java:440)
          at net.jini.discovery.LookupDiscovery.doUnicastDiscovery(LookupDiscovery.java:3323)
          at net.jini.discovery.LookupDiscovery.doUnicastDiscovery(LookupDiscovery.java:3339)
          at net.jini.discovery.LookupDiscovery.access$3600(LookupDiscovery.java:695)
          at net.jini.discovery.LookupDiscovery$UnicastDiscoveryTask.run(LookupDiscovery.java:1748)
          at com.sun.jini.thread.TaskManager$TaskThread.run(TaskManager.java:408)
      2012-maj-04 10:13:09 net.jini.discovery.LookupDiscovery$UnicastDiscoveryTask run
      

       

      The class com.sun.jini.reggie.RegistrarProxy, despite being in the com.sun namespace, is found in the Gigaspaces-jar gs-runtime.jar which is included in the Bundle Classpath of my fragment bundle.

       

      Any ideas?

        • 1. Re: classloading issue in fragment bundle
          ermag Community Member

          It turns out that Gigaspaces does some classloader magic that makes it behave differently in an OSGi environment. I was able to resolve this using the "Setting and resetting TCCL" trick described in OSGi in Action like so:

           

           

          ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader();
          
          try {
               Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
          
               //do Gigaspaces stuff
          
          } catch (Throwable t) {
               logger.error("Error while accessing gigaspace proxy", t);
          } finally {
               Thread.currentThread().setContextClassLoader(oldTCCL);
          }