Skip to content

Commit 6978d04

Browse files
committed
spring-projectsGH-8681: Websocket: Expose send buffer overflow strategy in XML config
1 parent be53593 commit 6978d04

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/ClientWebSocketContainerParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
* the {@code <websocket:client-container/>} element.
3434
*
3535
* @author Artem Bilan
36+
* @author Julian Koch
3637
* @since 4.1
3738
*/
3839
public class ClientWebSocketContainerParser extends AbstractSingleBeanDefinitionParser {
@@ -55,6 +56,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
5556

5657
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
5758
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
59+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-overflow-strategy");
5860
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "origin");
5961
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
6062
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/config/ServerWebSocketContainerParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@
3636
* the {@code <websocket:server-container/>} element.
3737
*
3838
* @author Artem Bilan
39+
* @author Julian Koch
3940
* @since 4.1
4041
*/
4142
public class ServerWebSocketContainerParser extends AbstractSingleBeanDefinitionParser {
@@ -104,6 +105,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
104105
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "handshake-handler");
105106
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
106107
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
108+
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-overflow-strategy");
107109
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "allowed-origins");
108110
}
109111

spring-integration-websocket/src/main/resources/org/springframework/integration/websocket/config/spring-integration-websocket.xsd

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@
9494
<xsd:union memberTypes="xsd:int xsd:string"/>
9595
</xsd:simpleType>
9696
</xsd:attribute>
97+
<xsd:attribute name="send-buffer-overflow-strategy">
98+
<xsd:annotation>
99+
<xsd:documentation>
100+
The WebSocket session's outbound message buffer overflow strategy.
101+
102+
Concurrently generated outbound messages are buffered if sending is slow.
103+
This strategy determines the behavior when the buffer has reached the limit
104+
configured with &lt;send-buffer-size-limit&gt;.
105+
</xsd:documentation>
106+
</xsd:annotation>
107+
<xsd:simpleType>
108+
<xsd:union memberTypes="overflowStrategyEnumeration xsd:string"/>
109+
</xsd:simpleType>
110+
</xsd:attribute>
97111
<xsd:attributeGroup ref="integration:smartLifeCycleAttributeGroup"/>
98112
</xsd:complexType>
99113
</xsd:element>
@@ -320,6 +334,20 @@
320334
<xsd:union memberTypes="xsd:int xsd:string"/>
321335
</xsd:simpleType>
322336
</xsd:attribute>
337+
<xsd:attribute name="send-buffer-overflow-strategy">
338+
<xsd:annotation>
339+
<xsd:documentation>
340+
The WebSocket session's outbound message buffer overflow strategy.
341+
342+
Concurrently generated outbound messages are buffered if sending is slow.
343+
This strategy determines the behavior when the buffer has reached the limit
344+
configured with &lt;send-buffer-size-limit&gt;.
345+
</xsd:documentation>
346+
</xsd:annotation>
347+
<xsd:simpleType>
348+
<xsd:union memberTypes="overflowStrategyEnumeration xsd:string"/>
349+
</xsd:simpleType>
350+
</xsd:attribute>
323351
<xsd:attribute name="allowed-origins" type="xsd:string">
324352
<xsd:annotation>
325353
<xsd:documentation>
@@ -505,4 +533,11 @@
505533
<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>
506534
</xsd:complexType>
507535

536+
<xsd:simpleType name="overflowStrategyEnumeration">
537+
<xsd:restriction base="xsd:token">
538+
<xsd:enumeration value="TERMINATE"/>
539+
<xsd:enumeration value="DROP"/>
540+
</xsd:restriction>
541+
</xsd:simpleType>
542+
508543
</xsd:schema>

spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests-context.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
path="/ws"
1818
send-buffer-size-limit="100000"
1919
send-time-limit="100"
20+
send-buffer-overflow-strategy="DROP"
2021
handshake-handler="handshakeHandler"
2122
handshake-interceptors="handshakeInterceptor"
2223
decorator-factories="decoratorFactory"
@@ -66,6 +67,7 @@
6667
uri-variables="ws,user"
6768
send-buffer-size-limit="1000"
6869
send-time-limit="100"
70+
send-buffer-overflow-strategy="DROP"
6971
origin="FOO"
7072
phase="100">
7173
<int-websocket:http-headers>

spring-integration-websocket/src/test/java/org/springframework/integration/websocket/config/WebSocketParserTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@
4747
import org.springframework.web.socket.WebSocketHandler;
4848
import org.springframework.web.socket.WebSocketHttpHeaders;
4949
import org.springframework.web.socket.client.WebSocketClient;
50+
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
5051
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
5152
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
5253
import org.springframework.web.socket.server.HandshakeHandler;
@@ -60,6 +61,7 @@
6061

6162
/**
6263
* @author Artem Bilan
64+
* @author Julian Koch
6365
*
6466
* @since 4.1
6567
*/
@@ -155,6 +157,8 @@ public void testDefaultInboundChannelAdapterAndServerContainer() {
155157
assertThat(interceptors[0]).isSameAs(this.handshakeInterceptor);
156158
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
157159
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(100000);
160+
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferOverflowStrategy"))
161+
.isEqualTo(ConcurrentWebSocketSessionDecorator.OverflowStrategy.DROP);
158162
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class))
159163
.isEqualTo(new String[] {"https://foo.com"});
160164

@@ -244,6 +248,8 @@ public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntax
244248
.isSameAs(this.customInboundAdapter);
245249
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
246250
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(1000);
251+
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferOverflowStrategy"))
252+
.isEqualTo(ConcurrentWebSocketSessionDecorator.OverflowStrategy.DROP);
247253
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.uri", URI.class))
248254
.isEqualTo(new URI("ws://foo.bar/ws?service=user"));
249255
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.client"))
@@ -258,6 +264,8 @@ public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntax
258264
.isEqualTo(10 * 1000);
259265
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"))
260266
.isEqualTo(512 * 1024);
267+
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferOverflowStrategy"))
268+
.isNull();
261269
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class))
262270
.isEqualTo(new URI("ws://foo.bar"));
263271
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"))

0 commit comments

Comments
 (0)