2016-08-15 18 views
1

私は、Springの仕様とspring-portafolioの例を考慮して、このSpringのStompとSockjsを使用してWebsocketクライアントとしてスタンドアロンのJavaアプリケーションを作成しようとしています。 Javaクライアント側での私のコードがあるWebsocket java client Spring + Stomp:Transportエラー:ConnectionLostException

15:18:01.342 [main] DEBUG com.example.client.WebSocketClientTest - Connecting to : ws://localhost:8080/socket/hello 
15:18:01.541 [WebSocketClient-AsyncIO-1] ERROR com.example.client.MyStompSessionHandler - Transport error 
org.springframework.messaging.simp.stomp.ConnectionLostException: Connection closed 
at org.springframework.messaging.simp.stomp.DefaultStompSession.afterConnectionClosed(DefaultStompSession.java:483) [spring-messaging-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.web.socket.messaging.WebSocketStompClient$WebSocketTcpConnectionHandlerAdapter.afterConnectionClosed(WebSocketStompClient.java:354) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.web.socket.sockjs.client.AbstractClientSockJsSession.afterTransportClosed(AbstractClientSockJsSession.java:321) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.web.socket.sockjs.client.WebSocketTransport$ClientSockJsWebSocketHandler.afterConnectionClosed(WebSocketTransport.java:172) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE] 
at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.onClose(StandardWebSocketHandlerAdapter.java:141) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]... 

を:私はこのエラーを取得してい

StandardWebSocketClient webSocketClient = new StandardWebSocketClient(); 
List<Transport> transports = new ArrayList<>(); 
transports.add(new WebSocketTransport(webSocketClient)); 
SockJsClient sockJsClient = new SockJsClient(transports); 
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); 
taskScheduler.afterPropertiesSet(); 
String stompUrl = "ws://localhost:8080/socket/hello"; 
WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); 
stompClient.setMessageConverter(new StringMessageConverter()); 
stompClient.setTaskScheduler(taskScheduler); 
stompClient.setDefaultHeartbeat(new long[] {0, 0}); 

StompSessionHandler sessionHandler = new MyStompSessionHandler(); 
stompClient.connect(stompUrl, sessionHandler); 
stompClient.setTaskScheduler(taskScheduler); 

とサーバ側はストンプとSockJsと春MVCを使用して作られた、サーバがで完璧に動作しますjavascriptクライアントでは、これは私は使用しました:

public void configureMessageBroker(MessageBrokerRegistry config) { 
    config.enableSimpleBroker("/topic"); 
    config.setApplicationDestinationPrefixes("/app"); 
} 
public void registerStompEndpoints(StompEndpointRegistry registry) { 
    registry.addEndpoint("/hello") 
      .setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy())) 
      .withSockJS(); 
} 

私は間違っていますか?誰か私にそれを修正する方法のアイデアを与えることができますか、またはJavaクライアントを作成してspring websocketサーバーに接続する方法を教えてください。

ありがとうございます。

答えて

1

私は同じ問題がありました。原因は、デフォルトのSTOMP Spring/Tomcat WSクライアントが処理できない大きすぎるメッセージを受信して​​いたためです。部分的なメッセージングができませんThis StackOverflow answerは(私はMAX_TEXT_MESSAGE_BUFFER_SIZE=20*1024*1024に設定されています)私の仕事:inboundMessageSizeLimitの設定

WebSocketContainer container = ContainerProvider.getWebSocketContainer(); 
container.setDefaultMaxTextMessageBufferSize(MAX_TEXT_MESSAGE_BUFFER_SIZE); 
WebSocketClient wsClient = new StandardWebSocketClient(container); 

は効果がありませんでした:

WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); 
stompClient.setInboundMessageSizeLimit(Integer.MAX_VALUE); 
関連する問題