簡體   English   中英

Spring Websockets / Stomp升級到安全的Websocket

[英]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:// ...”傳輸連接器。

請參閱: http//activemq.apache.org/websockets.html

activemq不通過標准協議支持websocket,而僅通過碼頭支持(請參閱https://github.com/apache/activemq/blob/master/activemq-http/src/main/java/org/apache/activemq/transport/ws /WSTransportServer.java

您在那里有幾個選擇:

  • 嘗試在tomee / lib中添加碼頭罐(注意不要添加沖突罐)
  • 配置一個外部代理(獨立activemq),並讓其連接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM