【问题标题】:Distributed OSGi - Consuming the service分布式 OSGi - 使用服务
【发布时间】:2016-08-19 10:27:12
【问题描述】:

我必须编写一个可以远程访问的服务。 我正在使用 cxf-dosgi-ri-singlebundle-distribution-1.4.0 。 所以我用这些属性创建了 API,然后是实现:

Dictionary<String, String> restProps = new Hashtable<String, String>();

restProps.put("service.exported.interfaces", "*");
restProps.put("service.exported.configs", "org.apache.cxf.ws");
restProps.put("org.apache.cxf.ws.address", "http://192.168.0.3:9090/preview");
bundleContext.registerService(Preview.class.getName(), new PreviewService(),restProps);

如果我部署捆绑包,(在部署 api 和 d-osgi jar 之后)我可以在浏览器中看到 WSDL,甚至可以从远程计算机上看到。 “http://192.168.0.3:9090/preview?wsdl”这样的。

但随之而来的是消费者。客户端 jar 中有 OSGI-INF/remote-service/remote-services.xml:

<endpoint-descriptions xmlns="http://www.osgi.org/xmlns/rsa/v1.0.0">
<endpoint-description>
<property name="objectClass">
    <array>
      <value>com.liferay.preview.api</value>
    </array>
</property>
<property name="endpoint.id">http://192.168.0.3:9090/preview</property>
<property name="service.imported.configs">org.apache.cxf.ws</property>
</endpoint-description>
</endpoint-descriptions>

我可以部署包(在部署 d-osgi 包和 API 之后),但我总是返回空引用。 教程总是使用这样的代码

 st = new ServiceTracker(bundleContext, MyService.class.getName(), null) {
  @Override
  public Object addingService(ServiceReference reference) {
    Object svc = bundleContext.getService(reference);
    if (svc instanceof MyService) {
      printServiceInfo((MyService) svc);
    }

    return super.addingService(reference);
  } 
};
st.open();

但我使用的是 Liferay 7,但我不能使用它(没有 ServiceTracker 的构造函数 - 我只能从 Registry 实例中获取 ServiceTracker 实例)

OSGi 容器是 Felix。

我在某处读过它,如果我可以访问上面看到的 WSDL 描述, 比方说,我的 API 中有一个方法 hello(),然后是 "http://192.168.0.3:9090/preview/hello" 调用应该可以工作......但它没有。 我什至不知道,如何调试这个。 (没有远程的东西,在本地,在同一个容器中,方法调用是有效的)

任何帮助都会很好!谢谢!

【问题讨论】:

    标签: java web-services wsdl osgi dosgi


    【解决方案1】:

    您应该使用基于 Apache CXF 的 Liferay SOAP Extender。您将在 Liferay 开发者网络中找到一个示例。

    【讨论】:

      【解决方案2】:

      Riena Communication 发布和绑定远程服务的复杂性较低。它使用 hessian 作为通信协议。与soap相比,它真的很快,因为它是基于二进制的协议(不是xml)

      我希望这会有所帮助。

      【讨论】:

      • 您是否尝试为此编写一个自己的示例?这个教程有点简短,因为没有源代码:(
      【解决方案3】:

      更简单的解决方案是使用基于 zookeeper 的发现。服务器节点会将其导出的服务发布到 zookeeper,消费者节点将在捆绑请求此类服务时立即为这些服务创建准备好使用的 OSGi 服务。

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-16
      • 2013-06-14
      • 2023-03-13
      • 2012-10-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      相关资源
      最近更新 更多