Refine condition to send WebSocket binary messages
The following two refinements have been added: 1) SockJS doesn't support binary messages so don't even try 2) don't bother if payload.length == 0 Issue: SPR-12475
This commit is contained in:
@@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.ApplicationEventPublisherAware;
|
||||
@@ -52,7 +51,6 @@ 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.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.web.socket.BinaryMessage;
|
||||
import org.springframework.web.socket.CloseStatus;
|
||||
@@ -356,8 +354,13 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE
|
||||
}
|
||||
}
|
||||
try {
|
||||
byte[] bytes = this.stompEncoder.encode(stompAccessor.getMessageHeaders(), (byte[]) message.getPayload());
|
||||
if (MimeTypeUtils.APPLICATION_OCTET_STREAM.isCompatibleWith(stompAccessor.getContentType())) {
|
||||
byte[] payload = (byte[]) message.getPayload();
|
||||
byte[] bytes = this.stompEncoder.encode(stompAccessor.getMessageHeaders(), payload);
|
||||
|
||||
boolean useBinary = (payload.length > 0 && !(session instanceof SockJsSession) &&
|
||||
MimeTypeUtils.APPLICATION_OCTET_STREAM.isCompatibleWith(stompAccessor.getContentType()));
|
||||
|
||||
if (useBinary) {
|
||||
session.sendMessage(new BinaryMessage(bytes));
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user