Browse Source

Allow binary messages in StompSubProtocolHandler

Issue: SPR-12301
pull/661/head
Rossen Stoyanchev 10 years ago
parent
commit
4a29e164a8
  1. 14
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

14
spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java

@ -49,6 +49,7 @@ import org.springframework.messaging.support.MessageBuilder; @@ -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 @@ -186,9 +187,16 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
List<Message<byte[]>> 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) {

Loading…
Cancel
Save