代码之家  ›  专栏  ›  技术社区  ›  cheng81

OSGi容器中的RMI客户端

  •  4
  • cheng81  · 技术社区  · 15 年前

    我该怎么解决?也许用RMI客户机jar作为“系统”包?

    Blipnet OSGi service starting...
    com.blipsystems.blipnet.api.blipserver.BlipServerConnectionException: There was a problem connecting to the server
        at com.blipsystems.blipnet.api.core.blipserver.BlipServerConnectionAdapter.(Unknown Source)
        at com.blipsystems.blipnet.api.core.blipserver.BlipServerConnectionAdapter.(Unknown Source)
        at com.blipsystems.blipnet.api.blipserver.BlipServer.getConnection(Unknown Source)
        at dk.itu.jingling.blipnetosgi.BlipnetConnectionService.setup(BlipnetConnectionService.java:28)
        at dk.itu.jingling.blipnetosgi.BlipnetConnectionService.(BlipnetConnectionService.java:22)
        at dk.itu.jingling.blipnetosgi.Activator.start(Activator.java:32)
        at org.apache.felix.framework.util.SecureAction$Actions.run(SecureAction.java:1235)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:658)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1699)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1621)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:890)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:877)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.start(DirectoryWatcher.java:819)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.start(DirectoryWatcher.java:805)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:798)
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:299)
    Caused by: java.lang.ClassCastException: com.blipsystems.blipnet.blipserver.cms.NewApiHandler_Stub cannot be cast to com.blipsystems.blipnet.api.core.blipserver.RemoteBlipServerConnection
    
    2 回复  |  直到 15 年前
        1
  •  5
  •   SteveD    15 年前

    由于类可见性问题,标准的Java序列化和OSGi不能很好地混合,而且由于RMI是建立在序列化之上的。。。

    我还没有坐下来研究RMI和OSGi的特殊问题,但我确实解决了使用Spring的 HTTPInvoker

    问题归结为一个类: ObjectInputStream

    这是负责反序列化的人-要反序列化一个需要其类可见性的对象。如果您有一个现代的IDE,您可以查看这个类的继承层次结构,并看到它有许多扩展,包括一些特定于RMI的类。

    我的解决方案是使用Spring的可扩展实现 然后从我的包中插入类加载器,这样反序列化就可以访问可以看到我的类的类加载器。

    您可以随意使用系统包,但这确实是一个技巧,我不建议长期使用它。

    不幸的是,OSGi仍然有一些令人讨厌的地方,需要你深入挖掘抽象层来发现问题并解决它-RMI就是其中之一。

    Paremus 男人们声称他们的服务结构服务器产品(一个基于OSGi的服务器)中有一个RMI的解决方案,可以配置为与Felix一起工作(我认为Eclipse的Equinox是默认的)。

        2
  •  0
  •   Pavel_K    7 年前

    我也有同样的问题,我很惊讶它是如此容易解决。我有三包:bundleA,bundleB,bundleC。bundleA—一组对bundleB和bundleC一无所知的抽象类。BundleB使用bundleA和bundleC。bundleB使用bundleC。

    所以, bundleA <-- bundleB --> bundleC .

    ClassLoader threadClassLoader= Thread.currentThread().getContextClassLoader();
    try {
        Class bundleCSomeClass = someVariablePassedFromBundleB.getMyClass();
        Thread.currentThread().setContextClassLoader(bundleCSomeClass.getClassLoader());
        //here we are calling RMI service
    } catch (RemoteException ex) {
    
    }finally{
        Thread.currentThread().setContextClassLoader(threadClassLoader);
    }