From 66722afda0ae391f0cd994e64516cc12f3807840 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Oct 2016 17:08:05 +0200 Subject: [PATCH] StompSubProtocolHandler does not insist on SimpMessageHeaderAccessor Issue: SPR-14791 --- .../messaging/StompSubProtocolHandler.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 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 07bbbf991f..3c0408bb96 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 @@ -34,7 +34,6 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; -import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpAttributes; import org.springframework.messaging.simp.SimpAttributesContextHolder; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; @@ -433,18 +432,13 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE } } - private StompHeaderAccessor getStompHeaderAccessor(Message message) { + private StompHeaderAccessor getStompHeaderAccessor(Message message) { MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class); - if (accessor == null) { - // Shouldn't happen (only broker broadcasts directly to clients) - throw new IllegalStateException("No header accessor in " + message); - } - StompHeaderAccessor stompAccessor; if (accessor instanceof StompHeaderAccessor) { - stompAccessor = (StompHeaderAccessor) accessor; + return (StompHeaderAccessor) accessor; } - else if (accessor instanceof SimpMessageHeaderAccessor) { - stompAccessor = StompHeaderAccessor.wrap(message); + else { + StompHeaderAccessor stompAccessor = StompHeaderAccessor.wrap(message); SimpMessageType messageType = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); if (SimpMessageType.CONNECT_ACK.equals(messageType)) { stompAccessor = convertConnectAcktoStompConnected(stompAccessor); @@ -466,13 +460,8 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) { stompAccessor.updateStompCommandAsServerMessage(); } + return stompAccessor; } - else { - // Shouldn't happen (only broker broadcasts directly to clients) - throw new IllegalStateException( - "Unexpected header accessor type: " + accessor.getClass() + " in " + message); - } - return stompAccessor; } /**