Skip to content

GH-8681: Websocket: Expose send buffer overflow strategy in XML config #8682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2023 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.
Expand Down Expand Up @@ -33,6 +33,7 @@
* the {@code <websocket:client-container/>} element.
*
* @author Artem Bilan
* @author Julian Koch
* @since 4.1
*/
public class ClientWebSocketContainerParser extends AbstractSingleBeanDefinitionParser {
Expand All @@ -55,6 +56,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit

IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-overflow-strategy");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "origin");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2023 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.
Expand Down Expand Up @@ -36,6 +36,7 @@
* the {@code <websocket:server-container/>} element.
*
* @author Artem Bilan
* @author Julian Koch
* @since 4.1
*/
public class ServerWebSocketContainerParser extends AbstractSingleBeanDefinitionParser {
Expand Down Expand Up @@ -104,6 +105,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "handshake-handler");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-overflow-strategy");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "allowed-origins");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@
<xsd:union memberTypes="xsd:int xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="send-buffer-overflow-strategy">
<xsd:annotation>
<xsd:documentation>
The WebSocket session's outbound message buffer overflow strategy.

Concurrently generated outbound messages are buffered if sending is slow.
This strategy determines the behavior when the buffer has reached the limit
configured with &lt;send-buffer-size-limit&gt;.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="overflowStrategyEnumeration xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attributeGroup ref="integration:smartLifeCycleAttributeGroup"/>
</xsd:complexType>
</xsd:element>
Expand Down Expand Up @@ -320,6 +334,20 @@
<xsd:union memberTypes="xsd:int xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="send-buffer-overflow-strategy">
<xsd:annotation>
<xsd:documentation>
The WebSocket session's outbound message buffer overflow strategy.

Concurrently generated outbound messages are buffered if sending is slow.
This strategy determines the behavior when the buffer has reached the limit
configured with &lt;send-buffer-size-limit&gt;.
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:union memberTypes="overflowStrategyEnumeration xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="allowed-origins" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Expand Down Expand Up @@ -505,4 +533,11 @@
<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>
</xsd:complexType>

<xsd:simpleType name="overflowStrategyEnumeration">
<xsd:restriction base="xsd:token">
<xsd:enumeration value="TERMINATE"/>
<xsd:enumeration value="DROP"/>
</xsd:restriction>
</xsd:simpleType>

</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
path="/ws"
send-buffer-size-limit="100000"
send-time-limit="100"
send-buffer-overflow-strategy="DROP"
handshake-handler="handshakeHandler"
handshake-interceptors="handshakeInterceptor"
decorator-factories="decoratorFactory"
Expand Down Expand Up @@ -66,6 +67,7 @@
uri-variables="ws,user"
send-buffer-size-limit="1000"
send-time-limit="100"
send-buffer-overflow-strategy="DROP"
origin="FOO"
phase="100">
<int-websocket:http-headers>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2023 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.
Expand Down Expand Up @@ -47,6 +47,7 @@
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketHttpHeaders;
import org.springframework.web.socket.client.WebSocketClient;
import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator;
import org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
import org.springframework.web.socket.server.HandshakeHandler;
Expand All @@ -60,6 +61,7 @@

/**
* @author Artem Bilan
* @author Julian Koch
*
* @since 4.1
*/
Expand Down Expand Up @@ -155,6 +157,8 @@ public void testDefaultInboundChannelAdapterAndServerContainer() {
assertThat(interceptors[0]).isSameAs(this.handshakeInterceptor);
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(100000);
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferOverflowStrategy"))
.isEqualTo(ConcurrentWebSocketSessionDecorator.OverflowStrategy.DROP);
assertThat(TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class))
.isEqualTo(new String[] {"https://foo.com"});

Expand Down Expand Up @@ -244,6 +248,8 @@ public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntax
.isSameAs(this.customInboundAdapter);
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendTimeLimit")).isEqualTo(100);
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferSizeLimit")).isEqualTo(1000);
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferOverflowStrategy"))
.isEqualTo(ConcurrentWebSocketSessionDecorator.OverflowStrategy.DROP);
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.uri", URI.class))
.isEqualTo(new URI("ws://foo.bar/ws?service=user"));
assertThat(TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.client"))
Expand All @@ -258,6 +264,8 @@ public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntax
.isEqualTo(10 * 1000);
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"))
.isEqualTo(512 * 1024);
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferOverflowStrategy"))
.isNull();
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class))
.isEqualTo(new URI("ws://foo.bar"));
assertThat(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"))
Expand Down