2016-07-12 8 views
3

SockJS Javaクライアントを使用して、私はSpring sockjsサーバーに接続しようとしていますが、ヘッダーなしのメッセージが〜20Kbのエラー1009が発生しています。 Javascriptライブラリは正常に動作します。Java SockJS Springクライアントとメッセージサイズ

Transport closed with CloseStatus[code=1009, reason=The decoded text message was too big 
for the output buffer and the endpoint does not support partial messages] in WebSocketClientSockJsSession 
[id='9fa30eb453e14a8c8612e1064640646a, url=ws://127.0.0.1:8083/user] 

私は、サーバー上のconfigクラスのカップル(私はこれらの事に必要以上の時間を設定していた場合、私は現時点では分からない)があります。

@Configuration 
@EnableWebSocket 
public class WebSocketTransportConfig implements WebSocketConfigurer { 
    // Important web socket setup. If big message is coming through, it may overflow the buffer and this will lead in disconnect. 
    // All messages that are coming through normally (including snapshots) must be order of magnitude smaller, or connection will be broken 
    // sometimes 
    // There is also MaxBinaryMessageSize that we do not employ as we use Stomp, but for completeness it is also set to same values. 
    // Javadoc http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/socket/adapter/jetty/JettyWebSocketSession.html#setTextMessageSizeLimit-int- 

    public static final int MAX_TEXT_MESSAGE_SIZE = 2048000; // 2 Megabytes. 
    public static final int BUFFER_SIZE = MAX_TEXT_MESSAGE_SIZE * 5; 


    private static final Logger LOGGER = LogManager.getLogger(WebSocketTransportConfig.class); 

    @Override 
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 

    } 

    @Bean 
    public DefaultHandshakeHandler handshakeHandler() { 
     LOGGER.info("Websocket buffer size: " + BUFFER_SIZE + " bytes."); 
     WebSocketPolicy policy = new WebSocketPolicy(WebSocketBehavior.SERVER); 
     policy.setMaxTextMessageBufferSize(BUFFER_SIZE); 
     policy.setMaxTextMessageSize(MAX_TEXT_MESSAGE_SIZE); 
     policy.setMaxBinaryMessageBufferSize(BUFFER_SIZE); 
     policy.setMaxBinaryMessageSize(MAX_TEXT_MESSAGE_SIZE); 
     policy.setInputBufferSize(BUFFER_SIZE); 
     policy.setIdleTimeout(600000); 

     return new DefaultHandshakeHandler(
       new JettyRequestUpgradeStrategy(new WebSocketServerFactory(policy))); 
    } 
} 

@Configuration 
@EnableWebSocketMessageBroker 
@EnableScheduling 
public class WebSocketBrokerConfig extends WebSocketMessageBrokerConfigurationSupport implements WebSocketMessageBrokerConfigurer { 


    @Override 
    public void configureWebSocketTransport(WebSocketTransportRegistration registry) { 
     // Increase buffers. 
     // Too little buffers may result in fatal errros when transmitting relatively large messages. 
     registry.setMessageSizeLimit(WebSocketTransportConfig.MAX_TEXT_MESSAGE_SIZE); 
     registry.setSendBufferSizeLimit(WebSocketTransportConfig.BUFFER_SIZE); 
     super.configureWebSocketTransport(registry); 
    } 
} 

Stomp spring web socket message exceeds size limitによると、Java Spring SockJSクライアントを接続するときには、エラー1009(大きすぎるメッセージ)が表示されます。

従って私は私は2つの課題の一つがあり疑う:

  1. のJava SockJSクライアントにも大きなメッセージを受信するように設定する必要があります。
  2. または、私はまだサーバー上で誤って構成されています。

Java SockJS Springクライアントでバッファサイズを増やすにはどうすればよいですか?

+0

解決しましたか? – gstackoverflow

答えて

2

私は同じ問題でつまずきました。それはすべて、サーバーではなくクライアントの構成に関するものです。 WebSocketContainerインスタンスを作成して構成できます。

WebSocketContainer container = ContainerProvider.getWebSocketContainer(); 
container.setDefaultMaxBinaryMessageBufferSize(your_size); 
container.setDefaultMaxTextMessageBufferSize(your_size); 
WebSocketClient transport = new StandardWebSocketClient(container); 
WebSocketStompClient stompClient = new WebSocketStompClient(transport); 

your_size - バイト単位のサイズです。

0

あなたはこのようにそれをやっている場合:

SockJsClient sockJsClient = new SockJsClient(transports); 
    WebSocketStompClient stompClient = new WebSocketStompClient(sockJsClient); 

試してみてください。

stompClient.setInboundMessageSizeLimit(your_message_size_limit); 
+0

これは役に立たない – gstackoverflow

関連する問題