2016-10-07 64 views
0

我有2個Java應用程序使用Spring websockets進行通信。我使用ActiveMQ版本5.12.3。我在TomEE服務器上運行應用程序。這是我的配置在tomee.xml使用ActiveMQ的:Spring Websockets/Stomp升級到安全websocket

<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); 

我可以成功連接使用下列代理網址:WS://本地主機:61614

我想要做的是使用安全的websockets進行連接。當我在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 

有誰知道一個簡單的方法來實現安全的WebSockets?我是否需要在我的代碼中添加額外的傳輸或將某些內容添加到我的服務器配置中?

回答

0

ActiveMQ是不是通過標準的協議,而只能通過碼頭配套的WebSocket(見https://github.com/apache/activemq/blob/master/activemq-http/src/main/java/org/apache/activemq/transport/ws/WSTransportServer.java

你有幾個選項有:

  • 嘗試添加碼頭罐子(注意不要添加衝突的)tomee/lib
  • 配置一個外部代理(獨立的activemq)並讓它連接它
+0

我已經有了所需的Jetty工程,並且可以在我使用ws:// broker url時進行連接。但我想連接使用安全的websockets使用wss:// – rurounisuikoden