From 4a29e164a8ca222fd8b0d2043e1d44494e84544e Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 10 Oct 2014 14:31:39 -0400 Subject: [PATCH] Allow binary messages in StompSubProtocolHandler Issue: SPR-12301 --- .../socket/messaging/StompSubProtocolHandler.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java index e50637e0f0..d903287153 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java @@ -49,6 +49,7 @@ import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageHeaderAccessor; import org.springframework.messaging.support.MessageHeaderInitializer; import org.springframework.util.Assert; +import org.springframework.web.socket.BinaryMessage; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketMessage; @@ -186,9 +187,16 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE List> messages; try { - Assert.isInstanceOf(TextMessage.class, webSocketMessage); - TextMessage textMessage = (TextMessage) webSocketMessage; - ByteBuffer byteBuffer = ByteBuffer.wrap(textMessage.asBytes()); + ByteBuffer byteBuffer; + if (webSocketMessage instanceof TextMessage) { + byteBuffer = ByteBuffer.wrap(((TextMessage) webSocketMessage).asBytes()); + } + else if (webSocketMessage instanceof BinaryMessage) { + byteBuffer = ((BinaryMessage) webSocketMessage).getPayload(); + } + else { + throw new IllegalArgumentException("Unexpected WebSocket message type: " + webSocketMessage); + } BufferingStompDecoder decoder = this.decoders.get(session.getId()); if (decoder == null) {