我目前使用tyrus客户端实现websocket客户端,websockets客户端在OSGI环境之外正常工作 .
问题是websocket不能在apache karaf上运行 . 我已经安装了websocket client的所有依赖项 . 列表是
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>.
这将需要通知我们使用javax.websocket.ContainerProvider服务的aries动态编织包 .
这是在OSGI中运行websockets的正确方法,还是在OSGI中运行websockets还有其他方法吗?任何关于这个问题的见解都会非常有帮助 .
2 回答
bndtools有一个explanation how to use websockets with jetty . 也许这可以帮助 .
Apache Karaf使用Pax-Web作为Web容器中介层 . 因此,最好查看相应的Pax-Web示例和集成测试:
WebSocketIntegrationTest
WebSocketWhiteBoardIntegrationTest
或相应的样本:
KarafWebsocketSample