Spring 中的其他 WebsocketClient 实现是什么?

What are other WebsocketClient implementations in Spring?

我有一个 Spring 应用程序正在连接到 websocket 端点。为此,我使用 Spring StandardWebSocketClient class。

WebSocketClient transport = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(transport);
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
String url = "ws://localhost:8080/asynccontrol";
StompSessionHandler handler = new MySessionHandler();
stompClient.connect(url, handler);

这在 Jetty 中没有任何问题。现在我必须在 Websphere JRE7 环境中部署这个应用程序。由于此 WAS 版本不支持 JSR-356,因此我必须使用其他实现。由此 link WebsocketClient 可以是以下类型:

第一选择不可用(无 JSR-356 运行时),第二选择不可用(需要 JRE8,不受支持 major.minor 版本 52),第三个选择是什么? Spring 的 WebSocketClient 的其他实现是什么?

是否可以在 JRE7 中重新编译 org.eclipse.jetty.websocketclient?

解决方案

我无法使用 jetty9.2,因为它与 JettyWebSocketClient 适配器不兼容。但是,我可以使用没有适配器的 api 和 StandardWebSocketClient.

我安装了 tomcat8,它也适用于 StandardWebSocketClient。在 tomcat7 中,我仍然收到不兼容的 WsContainerProvider 子类型错误,这可能是我特定 tomcat 版本的错误。对于备份计划,我还开发了 TyrusWebSocketClient。谢谢大家。

您可以使用 tyrus-standalone client.

如果您使用的是 Maven,请添加此依赖项:

<dependency>
     <groupId>org.glassfish.tyrus.bundles</groupId>
     <artifactId>tyrus-standalone-client</artifactId>
     <version>1.9</version>
</dependency>

 <dependency>
     <groupId>org.glassfish.tyrus.bundles</groupId>
     <artifactId>websocket-ri-bundle</artifactId>
     <version>1.2.1</version>
 </dependency>

我已经使用了 websocket-ri-bundle(第二个依赖项)它可以工作,但是这两个中的任何一个都可以正常工作。

编辑

如果你看到 StandardWebsocketClient class

public StandardWebSocketClient() {
    this.webSocketContainer = ContainerProvider.getWebSocketContainer();
}

Spring 尝试从客户端实现的 META-INF/services/javax.websocket.ContainerProvider 文件中识别容器提供者。因此,任何正确指出该文件的 websocket 客户端实现都可以工作。