Add configuration for message buffer size limit

BufferingStompDecoder message buffer size limit can now be configured
with JavaConfig MessageBrokerRegistry.setMessageBufferSizeLimit() or
with XML <websocket:message-brocker message-buffer-size="">.

Issue: SPR-11527
This commit is contained in:
Sebastien Deleuze
2014-03-24 09:28:33 +01:00
committed by Rossen Stoyanchev
parent ebffd67b5e
commit bbdb72d808
14 changed files with 103 additions and 20 deletions

View File

@@ -124,8 +124,11 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
beanName = registerBeanDef(beanDef, parserCxt, source);
RuntimeBeanReference userSessionRegistry = new RuntimeBeanReference(beanName);
String frameBufferSizeAttribute = element.getAttribute("message-buffer-size");
Integer messageBufferSizeLimit = frameBufferSizeAttribute.isEmpty() ? null : Integer.parseInt(frameBufferSizeAttribute);
RuntimeBeanReference subProtocolWsHandler = registerSubProtocolWebSocketHandler(
clientInChannel, clientOutChannel, userSessionRegistry, parserCxt, source);
clientInChannel, clientOutChannel, userSessionRegistry, messageBufferSizeLimit, parserCxt, source);
for(Element stompEndpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
@@ -228,10 +231,14 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
private RuntimeBeanReference registerSubProtocolWebSocketHandler(
RuntimeBeanReference clientInChannel, RuntimeBeanReference clientOutChannel,
RuntimeBeanReference userSessionRegistry, ParserContext parserCxt, Object source) {
RuntimeBeanReference userSessionRegistry, Integer messageBufferSizeLimit,
ParserContext parserCxt, Object source) {
RootBeanDefinition stompHandlerDef = new RootBeanDefinition(StompSubProtocolHandler.class);
stompHandlerDef.getPropertyValues().add("userSessionRegistry", userSessionRegistry);
if(messageBufferSizeLimit != null) {
stompHandlerDef.getPropertyValues().add("messageBufferSizeLimit", messageBufferSizeLimit);
}
registerBeanDef(stompHandlerDef, parserCxt, source);
ConstructorArgumentValues cavs = new ConstructorArgumentValues();

View File

@@ -21,6 +21,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.messaging.simp.user.UserSessionRegistry;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
@@ -57,7 +58,8 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
public WebMvcStompEndpointRegistry(WebSocketHandler webSocketHandler,
UserSessionRegistry userSessionRegistry, TaskScheduler defaultSockJsTaskScheduler) {
UserSessionRegistry userSessionRegistry, TaskScheduler defaultSockJsTaskScheduler,
MessageBrokerRegistry brokerRegistry) {
Assert.notNull(webSocketHandler);
Assert.notNull(userSessionRegistry);
@@ -67,6 +69,9 @@ public class WebMvcStompEndpointRegistry implements StompEndpointRegistry {
this.stompHandler = new StompSubProtocolHandler();
this.stompHandler.setUserSessionRegistry(userSessionRegistry);
this.sockJsScheduler = defaultSockJsTaskScheduler;
if(brokerRegistry.getMessageBufferSizeLimit() != null) {
this.stompHandler.setMessageBufferSizeLimit(brokerRegistry.getMessageBufferSizeLimit());
}
}
private static SubProtocolWebSocketHandler unwrapSubProtocolWebSocketHandler(WebSocketHandler webSocketHandler) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,8 @@ public abstract class WebSocketMessageBrokerConfigurationSupport extends Abstrac
@Bean
public HandlerMapping stompWebSocketHandlerMapping() {
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(
subProtocolWebSocketHandler(), userSessionRegistry(), messageBrokerSockJsTaskScheduler());
subProtocolWebSocketHandler(), userSessionRegistry(),
messageBrokerSockJsTaskScheduler(), getBrokerRegistry());
registerStompEndpoints(registry);
return registry.getHandlerMapping();
}

View File

@@ -79,16 +79,16 @@ public class StompSubProtocolHandler implements SubProtocolHandler {
/**
* TODO
* @param messageBufferSizeLimit
* Set the message buffer size limit in bytes.
* @since 4.0.3
*/
public void setMessageBufferSizeLimit(int messageBufferSizeLimit) {
this.messageBufferSizeLimit = messageBufferSizeLimit;
}
/**
* TODO
* @return
* Get the message buffer size limit in bytes.
* @since 4.0.3
*/
public int getMessageBufferSizeLimit() {
return this.messageBufferSizeLimit;

View File

@@ -575,6 +575,13 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="message-buffer-size" type="xsd:int">
<xsd:annotation>
<xsd:documentation><![CDATA[
The message buffer size limit in bytes for simple messaging protocols like STOMP.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:token">
<xsd:annotation>
<xsd:documentation><![CDATA[