Search in sources :

Example 1 with Jackson2SockJsMessageCodec

use of org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec in project spring-framework by spring-projects.

the class RestTemplateXhrTransportTests method connectReceiveAndCloseWithStompFrame.

@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);
}
Also used : Jackson2SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec) StompEncoder(org.springframework.messaging.simp.stomp.StompEncoder) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) MessageHeaders(org.springframework.messaging.MessageHeaders) CloseStatus(org.springframework.web.socket.CloseStatus) SockJsFrame(org.springframework.web.socket.sockjs.frame.SockJsFrame) ClientHttpResponse(org.springframework.http.client.ClientHttpResponse) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.jupiter.api.Test)

Example 2 with Jackson2SockJsMessageCodec

use of org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec in project fastjson by alibaba.

the class FastjsonSockJsMessageCodecTest_encode method test_encode.

public void test_encode() throws Exception {
    FastjsonSockJsMessageCodec fastjsonCodec = new FastjsonSockJsMessageCodec();
    Jackson2SockJsMessageCodec jacksonCodec = new Jackson2SockJsMessageCodec();
    String v0 = "a0\"\0", v1 = "a1";
    String fastjsonResult = fastjsonCodec.encode(v0, v1);
    String jacksonResult = jacksonCodec.encode(v0, v1);
    Assert.assertEquals(jacksonResult, fastjsonResult);
}
Also used : Jackson2SockJsMessageCodec(org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec) FastjsonSockJsMessageCodec(com.alibaba.fastjson.support.spring.FastjsonSockJsMessageCodec)

Aggregations

Jackson2SockJsMessageCodec (org.springframework.web.socket.sockjs.frame.Jackson2SockJsMessageCodec)2 FastjsonSockJsMessageCodec (com.alibaba.fastjson.support.spring.FastjsonSockJsMessageCodec)1 Test (org.junit.jupiter.api.Test)1 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1 StompEncoder (org.springframework.messaging.simp.stomp.StompEncoder)1 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)1 CloseStatus (org.springframework.web.socket.CloseStatus)1 TextMessage (org.springframework.web.socket.TextMessage)1 SockJsFrame (org.springframework.web.socket.sockjs.frame.SockJsFrame)1