diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java index f9973b6c60..247a739ba5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.net.URI; import java.nio.ByteBuffer; import java.time.Duration; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -75,16 +76,13 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif private static final Log logger = LogFactory.getLog(WebSocketStompClient.class); - /** - * The default max size for in&outbound STOMP message. - */ - private static final int DEFAULT_MESSAGE_MAX_SIZE = 64 * 1024; private final WebSocketClient webSocketClient; - private int inboundMessageSizeLimit = DEFAULT_MESSAGE_MAX_SIZE; + private int inboundMessageSizeLimit = 64 * 1024; - private int outboundMessageSizeLimit = DEFAULT_MESSAGE_MAX_SIZE; + @Nullable + private Integer outboundMessageSizeLimit; private boolean autoStartup = true; @@ -131,7 +129,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif * Since a STOMP message can be received in multiple WebSocket messages, * buffering may be required and this property determines the maximum buffer * size per message. - *
By default this is set to 64 * 1024 (64K), see {@link WebSocketStompClient#DEFAULT_MESSAGE_MAX_SIZE}. + *
By default this is set to 64 * 1024 (64K). */ public void setInboundMessageSizeLimit(int inboundMessageSizeLimit) { this.inboundMessageSizeLimit = inboundMessageSizeLimit; @@ -148,10 +146,10 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif * Configure the maximum size allowed for outbound STOMP message. * If STOMP message's size exceeds {@link WebSocketStompClient#outboundMessageSizeLimit}, * STOMP message is split into multiple frames. - *
By default this is set to 64 * 1024 (64K), see {@link WebSocketStompClient#DEFAULT_MESSAGE_MAX_SIZE}. + *
By default this is not set in which case each STOMP message are not split.
* @since 6.2
*/
- public void setOutboundMessageSizeLimit(int outboundMessageSizeLimit) {
+ public void setOutboundMessageSizeLimit(Integer outboundMessageSizeLimit) {
this.outboundMessageSizeLimit = outboundMessageSizeLimit;
}
@@ -159,7 +157,8 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* Get the configured outbound message buffer size in bytes.
* @since 6.2
*/
- public int getOutboundMessageSizeLimit() {
+ @Nullable
+ public Integer getOutboundMessageSizeLimit() {
return this.outboundMessageSizeLimit;
}
@@ -479,8 +478,13 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
try {
WebSocketSession session = this.session;
Assert.state(session != null, "No WebSocketSession available");
- for (WebSocketMessage> webSocketMessage : this.codec.encode(message, session.getClass())) {
- session.sendMessage(webSocketMessage);
+ if (this.codec.hasSplittingEncoder()) {
+ for (WebSocketMessage> outMessage : this.codec.encodeAndSplit(message, session.getClass())) {
+ session.sendMessage(outMessage);
+ }
+ }
+ else {
+ session.sendMessage(this.codec.encode(message, session.getClass()));
}
future.complete(null);
}
@@ -592,11 +596,13 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
private final BufferingStompDecoder bufferingDecoder;
+ @Nullable
private final SplittingStompEncoder splittingEncoder;
- public StompWebSocketMessageCodec(int inboundMessageSizeLimit, int outboundMessageSizeLimit) {
+ public StompWebSocketMessageCodec(int inboundMessageSizeLimit, @Nullable Integer outboundMessageSizeLimit) {
this.bufferingDecoder = new BufferingStompDecoder(DECODER, inboundMessageSizeLimit);
- this.splittingEncoder = new SplittingStompEncoder(ENCODER, outboundMessageSizeLimit);
+ this.splittingEncoder = (outboundMessageSizeLimit != null ?
+ new SplittingStompEncoder(ENCODER, outboundMessageSizeLimit) : null);
}
public List