[英]Spring Websockets/Stomp upgrade to secure websockets
我有2个Java应用程序,它们使用Spring websockets进行通信。 我使用ActiveMQ版本5.12.3。 我在TomEE服务器上运行这些应用程序。 这是我在tomee.xml中为ActiveMQ使用的配置:
<Resource id="MyAppMessageBus" type="ActiveMQResourceAdapter">
BrokerXmlConfig = broker:(tcp://localhost:61616,ws://0.0.0.0:61614,stomp://0.0.0.0:61613)
ServerUrl = tcp://localhost:61616
</Resource>
这是我用于连接的Java代码:
if (brokerUrl.startsWith("ws")) {
WebSocketClient transport = new StandardWebSocketClient();
stompClient = new WebSocketStompClient(transport);
}
stompClient.setMessageConverter(new MappingJackson2MessageConverter());
stompClient.setTaskScheduler(taskScheduler);
stompClient.setDefaultHeartbeat(heartbeat);
stompClient.connect(brokerUrl, handler);
我可以使用以下代理URL成功连接:ws:// localhost:61614
我想做的是使用安全的网络套接字进行连接。 当我将tomee.xml中的URL更改为使用wss://并更新代码中的brokerURL时,出现以下异常:
javax.websocket.DeploymentException: The HTTP request to initiate the WebSocket connection failed
at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:434) ~[tomcat7-websocket.jar:7.0.68]
at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:152) ~[spring-websocket-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.web.socket.client.standard.StandardWebSocketClient$1.call(StandardWebSocketClient.java:149) ~[spring-websocket-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) ~[na:1.7.0_80]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_80]
Caused by: java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused
at sun.nio.ch.PendingFuture.get(PendingFuture.java:202) ~[na:1.7.0_80]
at org.apache.tomcat.websocket.WsWebSocketContainer.connectToServer(WsWebSocketContainer.java:376) ~[tomcat7-websocket.jar:7.0.68]
... 4 common frames omitted
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method) ~[na:1.7.0_80]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:252) ~[na:1.7.0_80]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:198) ~[na:1.7.0_80]
at sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:213) ~[na:1.7.0_80]
at sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:293) ~[na:1.7.0_80]
... 1 common frames omitted
有谁知道启用安全网络套接字的简单方法? 我是否需要在代码中添加其他传输方式或向服务器配置中添加内容?
在代理配置中,服务器端需要一个“ wss:// ...”传输连接器。
activemq不通过标准协议支持websocket,而仅通过码头支持(请参阅https://github.com/apache/activemq/blob/master/activemq-http/src/main/java/org/apache/activemq/transport/ws /WSTransportServer.java )
您在那里有几个选择:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.