org.springframework.messaging.simp.stomp.StompEncoder Java Examples
The following examples show how to use
org.springframework.messaging.simp.stomp.StompEncoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestTemplateXhrTransportTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void connectReceiveAndCloseWithStompFrame() throws Exception { StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND); accessor.setDestination("/destination"); MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers); byte[] bytes = new StompEncoder().encode(message); TextMessage textMessage = new TextMessage(bytes); SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload()); String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleMessage(any(), eq(textMessage)); verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!"))); verifyNoMoreInteractions(this.webSocketHandler); }
Example #2
Source File: RestTemplateXhrTransportTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void connectReceiveAndCloseWithStompFrame() throws Exception { StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND); accessor.setDestination("/destination"); MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(StandardCharsets.UTF_8), headers); byte[] bytes = new StompEncoder().encode(message); TextMessage textMessage = new TextMessage(bytes); SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload()); String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleMessage(any(), eq(textMessage)); verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!"))); verifyNoMoreInteractions(this.webSocketHandler); }
Example #3
Source File: RestTemplateXhrTransportTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void connectReceiveAndCloseWithStompFrame() throws Exception { StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.SEND); accessor.setDestination("/destination"); MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message = MessageBuilder.createMessage("body".getBytes(Charset.forName("UTF-8")), headers); byte[] bytes = new StompEncoder().encode(message); TextMessage textMessage = new TextMessage(bytes); SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), textMessage.getPayload()); String body = "o\n" + frame.getContent() + "\n" + "c[3000,\"Go away!\"]"; ClientHttpResponse response = response(HttpStatus.OK, body); connect(response); verify(this.webSocketHandler).afterConnectionEstablished(any()); verify(this.webSocketHandler).handleMessage(any(), eq(textMessage)); verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!"))); verifyNoMoreInteractions(this.webSocketHandler); }
Example #4
Source File: WeEventStompCommand.java From WeEvent with Apache License 2.0 | 5 votes |
public String encodeRaw(StompHeaderAccessor accessor, byte[] payload) { log.debug("encode STOMP command: {}", accessor.getCommand()); MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message = MessageBuilder.createMessage(payload != null ? payload : "".getBytes(StandardCharsets.UTF_8), headers); return new String((new StompEncoder()).encode(message), StandardCharsets.UTF_8); }
Example #5
Source File: BrokerStomp.java From WeEvent with Apache License 2.0 | 5 votes |
private void sendSimpleMessage(WebSocketSession session, StompHeaderAccessor accessor) { MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message1 = MessageBuilder.createMessage("".getBytes(StandardCharsets.UTF_8), headers); byte[] bytes = new StompEncoder().encode(message1); TextMessage textMessage = new TextMessage(bytes); send2Remote(session, textMessage); }
Example #6
Source File: BrokerStomp.java From WeEvent with Apache License 2.0 | 5 votes |
private void handleOnEvent(String headerIdStr, String subscriptionId, WeEvent event, WebSocketSession session) { StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.MESSAGE); // package the return frame accessor.setSubscriptionId(headerIdStr); accessor.setNativeHeader("subscription-id", subscriptionId); accessor.setMessageId(headerIdStr); accessor.setDestination(event.getTopic()); accessor.setContentType(new MimeType("text", "plain", StandardCharsets.UTF_8)); // set custom properties in header for (Map.Entry<String, String> custom : event.getExtensions().entrySet()) { accessor.setNativeHeader(custom.getKey(), custom.getValue()); } // set eventId in header accessor.setNativeHeader(WeEventConstants.EXTENSIONS_EVENT_ID, event.getEventId()); // payload == content MessageHeaders headers = accessor.getMessageHeaders(); Message<byte[]> message = MessageBuilder.createMessage(event.getContent(), headers); byte[] bytes = new StompEncoder().encode(message); // send to remote send2Remote(session, new TextMessage(bytes)); }
Example #7
Source File: StompSubProtocolHandler.java From spring-analysis-note with MIT License | 2 votes |
/** * Configure a {@link StompEncoder} for encoding STOMP frames. * @since 4.3.5 */ public void setEncoder(StompEncoder encoder) { this.stompEncoder = encoder; }
Example #8
Source File: StompSubProtocolHandler.java From java-technology-stack with MIT License | 2 votes |
/** * Configure a {@link StompEncoder} for encoding STOMP frames. * @since 4.3.5 */ public void setEncoder(StompEncoder encoder) { this.stompEncoder = encoder; }