【问题标题】:Websocket Client in OSGIOSGI 中的 Websocket 客户端
【发布时间】:2017-03-03 12:33:12
【问题描述】:

我目前使用 tyrus 客户端实现了 websocket 客户端,并且 websockets 客户端在 OSGI 环境之外可以正常工作。

问题是 websocket 不能在 apache karaf 上运行。 我已经安装了 websocket 客户端的所有依赖项。列表是

 ID | State     | Lvl | Version        | Name
------------------------------------------------------------------------------------
 52 | Active    |  80 | 4.3.0          | Apache Felix Dependency Manager
 96 | Active    |  80 | 1.0            | WebSocket server API
 97 | Active    |  80 | 1.1.0          | Tyrus Server
 98 | Active    |  80 | 1.1.0          | Tyrus Core
 99 | Active    |  80 | 1.1.0          | Tyrus Container SPI
100 | Active    |  80 | 1.1.0          | Tyrus WebSocket Core
102 | Active    |  80 | 1.1.0          | Tyrus Grizzly Container
103 | Active    |  80 | 2.3.3          | grizzly-framework
104 | Active    |  80 | 2.3.3          | grizzly-http
105 | Active    |  80 | 2.3.3          | grizzly-http-server
106 | Active    |  80 | 2.3.3          | grizzly-rcm
118 | Active    |  80 | 1.0.8          | Apache Aries SPI Fly Dynamic Weaving Bundle
134 | Active    |  80 | 1.1.0          | Tyrus Client
135 | Installed |  80 | 1.0.0.SNAPSHOT | rna-websocket-client

tyrus 客户端通过 ServiceLoader 提供实现。 所以我使用 Apache Aries SPI Fly Dynamic Weaving Bundle 来实现。但我仍然收到 Could not find an implementation class. 错误。

调查发现tyrus客户端没有添加

Provide-Capability: osgi.serviceloader; osgi.serviceloader="javax.websocket.ContainerProvider"

到需要通知处理包有关正在提供的服务的清单。 在我的 rna-websocket-client 包中,我添加了

<Require-Capability>osgi.serviceloader; filter:="(osgi.serviceloader=javax.websocket.ContainerProvider)";cardinality:=multiple,osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)"</Require-Capability>.

这需要通知 aries 动态编织包我们使用 javax.websocket.ContainerProvider 服务。

这是在 OSGI 中运行 websockets 的正确方法还是在 OSGI 中运行 websockets 的任何其他方法? 对这个问题的任何见解都会非常有帮助。

【问题讨论】:

    标签: java websocket osgi apache-karaf tyrus


    【解决方案1】:

    bndtools 上有一个explanation how to use websockets with jetty。 也许这会有所帮助。

    【讨论】:

    • websocket 客户端与链接中提到的客户端示例一起工作,稍作修改。谢谢。
    【解决方案2】:

    Apache Karaf 使用 Pax-Web 作为 Web 容器中介层。 因此最好看一下相应的 Pax-Web 示例和集成测试:
    WebSocketIntegrationTest
    WebSocketWhiteBoardIntegrationTest

    或相应的样本:
    KarafWebsocketSample

    【讨论】:

    • 有道理。这应该更容易在 karaf 中应用。
    • 已经用jetty实现了websocket客户端。一旦我有时间也会检查这个。
    猜你喜欢
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多