public StompCommand updateStompCommandAsClientMessage() { SimpMessageType messageType = getMessageType(); if (messageType != SimpMessageType.MESSAGE) { throw new IllegalStateException("Unexpected message type " + messageType); } StompCommand command = getCommand(); if (command == null) { command = StompCommand.SEND; setHeader(COMMAND_HEADER, command); } else if (!command.equals(StompCommand.SEND)) { throw new IllegalStateException("Unexpected STOMP command " + command); } return command; }
/** * A constructor for creating message headers from a parsed STOMP frame. */ StompHeaderAccessor(StompCommand command, @Nullable Map<String, List<String>> externalSourceHeaders) { super(command.getMessageType(), externalSourceHeaders); setHeader(COMMAND_HEADER, command); updateSimpMessageHeadersFromStompHeaders(); }
@Override public String getDetailedLogMessage(@Nullable Object payload) { if (isHeartbeat()) { String sessionId = getSessionId(); return "heart-beat" + (sessionId != null ? " in session " + sessionId : ""); } StompCommand command = getCommand(); if (command == null) { return super.getDetailedLogMessage(payload); } StringBuilder sb = new StringBuilder(); sb.append(command.name()).append(" "); Map<String, List<String>> nativeHeaders = getNativeHeaders(); if (nativeHeaders != null) { sb.append(nativeHeaders); } sb.append(appendSession()); if (getUser() != null) { sb.append(", user=").append(getUser().getName()); } if (payload != null && command.isBodyAllowed()) { sb.append(appendPayload(payload)); } return sb.toString(); }
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) { continue; if (StompCommand.CONNECT.equals(command) && StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) { values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers)); if (command.requiresContentLength()) { int contentLength = payload.length; output.write("content-length:".getBytes(StandardCharsets.UTF_8));
@Test public void requiresContentLength() throws Exception { for (StompCommand stompCommand : StompCommand.values()) { assertEquals(contentLengthRequired.contains(stompCommand), stompCommand.requiresContentLength()); } }
@Test public void isBodyAllowed() throws Exception { for (StompCommand stompCommand : StompCommand.values()) { assertEquals(bodyAllowed.contains(stompCommand), stompCommand.isBodyAllowed()); } }
if (command != null && command.requiresDestination() && !checkDestinationPrefix(destination)) { return; if (StompCommand.CONNECT.equals(command)) { if (logger.isDebugEnabled()) { logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD)); this.tcpClient.connect(handler); else if (StompCommand.DISCONNECT.equals(command)) { StompConnectionHandler handler = this.connectionHandlers.get(sessionId); if (handler == null) {
byte[] payload = null; if (byteBuffer.remaining() > 0) { StompCommand stompCommand = StompCommand.valueOf(command); headerAccessor = StompHeaderAccessor.create(stompCommand); initHeaders(headerAccessor); if (payload.length > 0) { StompCommand stompCommand = headerAccessor.getCommand(); if (stompCommand != null && !stompCommand.isBodyAllowed()) { throw new StompConversionException(stompCommand + " shouldn't have a payload: length=" + payload.length + ", headers=" + headers);
output.write(command.toString().getBytes(StandardCharsets.UTF_8)); output.write(LF); writeHeaders(command, headers, payload, output);
@Test public void getMessageType() throws Exception { for (StompCommand stompCommand : StompCommand.values()) { SimpMessageType simp = messageTypes.get(stompCommand); if (simp == null) { simp = SimpMessageType.OTHER; } assertSame(simp, stompCommand.getMessageType()); } }
public TextMessage build() { StringBuilder sb = new StringBuilder(this.command.name()).append("\n"); for (String line : this.headerLines) { sb.append(line).append("\n"); } sb.append("\n"); if (this.body != null) { sb.append(this.body); } sb.append("\u0000"); return new TextMessage(sb.toString()); }
@Test public void requiresDestination() throws Exception { for (StompCommand stompCommand : StompCommand.values()) { assertEquals(destinationRequired.contains(stompCommand), stompCommand.requiresDestination()); } }
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) { continue; if (StompCommand.CONNECT.equals(command) && StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) { values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers)); if (command.requiresContentLength()) { int contentLength = payload.length; output.write("content-length:".getBytes(StandardCharsets.UTF_8));
if (command != null && command.requiresDestination() && !checkDestinationPrefix(destination)) { return; if (StompCommand.CONNECT.equals(command)) { if (logger.isDebugEnabled()) { logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD)); this.tcpClient.connect(handler); else if (StompCommand.DISCONNECT.equals(command)) { StompConnectionHandler handler = this.connectionHandlers.get(sessionId); if (handler == null) {
byte[] payload = null; if (byteBuffer.remaining() > 0) { StompCommand stompCommand = StompCommand.valueOf(command); headerAccessor = StompHeaderAccessor.create(stompCommand); initHeaders(headerAccessor); if (payload.length > 0) { StompCommand stompCommand = headerAccessor.getCommand(); if (stompCommand != null && !stompCommand.isBodyAllowed()) { throw new StompConversionException(stompCommand + " shouldn't have a payload: length=" + payload.length + ", headers=" + headers);
output.write(command.toString().getBytes(StandardCharsets.UTF_8)); output.write(LF); writeHeaders(command, headers, payload, output);
@Test public void sendMessageToController() throws Exception { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT); this.webSocketOutputChannel.send(MessageBuilder.withPayload(new byte[0]).setHeaders(headers).build()); Message<?> receive = this.webSocketEvents.receive(20000); assertNotNull(receive); Object event = receive.getPayload(); assertThat(event, instanceOf(SessionConnectedEvent.class)); Message<?> connectedMessage = ((SessionConnectedEvent) event).getMessage(); headers = StompHeaderAccessor.wrap(connectedMessage); assertEquals(StompCommand.CONNECTED, headers.getCommand()); headers = StompHeaderAccessor.create(StompCommand.SEND); headers.setSubscriptionId("sub1"); headers.setDestination("/app/simple"); Message<String> message = MessageBuilder.withPayload("foo").setHeaders(headers).build(); this.webSocketOutputChannel.send(message); SimpleController controller = this.serverContext.getBean(SimpleController.class); assertTrue(controller.latch.await(20, TimeUnit.SECONDS)); assertEquals(StompCommand.SEND.name(), controller.stompCommand); }
public void updateStompCommandAsServerMessage() { SimpMessageType messageType = getMessageType(); if (messageType != SimpMessageType.MESSAGE) { throw new IllegalStateException("Unexpected message type " + messageType); } StompCommand command = getCommand(); if ((command == null) || StompCommand.SEND.equals(command)) { setHeader(COMMAND_HEADER, StompCommand.MESSAGE); } else if (!StompCommand.MESSAGE.equals(command)) { throw new IllegalStateException("Unexpected STOMP command " + command); } trySetStompHeaderForSubscriptionId(); if (getMessageId() == null) { String messageId = getSessionId() + '-' + messageIdCounter.getAndIncrement(); setNativeHeader(STOMP_MESSAGE_ID_HEADER, messageId); } }
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) { continue; if (StompCommand.CONNECT.equals(command) && StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) { values = Collections.singletonList(StompHeaderAccessor.getPasscode(headers)); if (command.requiresContentLength()) { int contentLength = payload.length; output.write("content-length:".getBytes(StandardCharsets.UTF_8));
if (command != null && command.requiresDestination() && !checkDestinationPrefix(destination)) { return; if (StompCommand.CONNECT.equals(command)) { if (logger.isDebugEnabled()) { logger.debug(stompAccessor.getShortLogMessage(EMPTY_PAYLOAD)); this.tcpClient.connect(handler); else if (StompCommand.DISCONNECT.equals(command)) { StompConnectionHandler handler = this.connectionHandlers.get(sessionId); if (handler == null) {