gpt4 book ai didi

org.springframework.web.socket.WebSocketHandler.handleMessage()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 19:55:05 26 4
gpt4 key购买 nike

本文整理了Java中org.springframework.web.socket.WebSocketHandler.handleMessage()方法的一些代码示例,展示了WebSocketHandler.handleMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocketHandler.handleMessage()方法的具体详情如下:
包路径:org.springframework.web.socket.WebSocketHandler
类名称:WebSocketHandler
方法名:handleMessage

WebSocketHandler.handleMessage介绍

[英]Invoked when a new WebSocket message arrives.
[中]当新WebSocket消息到达时调用。

代码示例

代码示例来源:origin: spring-projects/spring-framework

@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
  this.delegate.handleMessage(session, message);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
  getHandler(session).handleMessage(session, message);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) {
  try {
    getDelegate().handleMessage(session, message);
  }
  catch (Throwable ex) {
    tryCloseWithError(session, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

private void handleBinaryMessage(javax.websocket.Session session, ByteBuffer payload, boolean isLast) {
  BinaryMessage binaryMessage = new BinaryMessage(payload, isLast);
  try {
    this.handler.handleMessage(this.wsSession, binaryMessage);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

private void handleTextMessage(javax.websocket.Session session, String payload, boolean isLast) {
  TextMessage textMessage = new TextMessage(payload, isLast);
  try {
    this.handler.handleMessage(this.wsSession, textMessage);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

private void handlePongMessage(javax.websocket.Session session, ByteBuffer payload) {
  PongMessage pongMessage = new PongMessage(payload);
  try {
    this.handler.handleMessage(this.wsSession, pongMessage);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@OnWebSocketMessage
public void onWebSocketBinary(byte[] payload, int offset, int length) {
  BinaryMessage message = new BinaryMessage(payload, offset, length, true);
  try {
    this.webSocketHandler.handleMessage(this.wsSession, message);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@OnWebSocketMessage
public void onWebSocketText(String payload) {
  TextMessage message = new TextMessage(payload);
  try {
    this.webSocketHandler.handleMessage(this.wsSession, message);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void handleWebSocketMessagePong() throws Exception {
  connect().handleMessage(this.webSocketSession, new PongMessage());
  verifyNoMoreInteractions(this.stompSession);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void handleMessage() throws Exception {
  TextMessage message = new TextMessage("[\"x\"]");
  this.session.handleMessage(message, this.webSocketSession);
  verify(this.webSocketHandler).handleMessage(this.session, new TextMessage("x"));
  verifyNoMoreInteractions(this.webSocketHandler);
}

代码示例来源:origin: spring-projects/spring-framework

@OnWebSocketFrame
public void onWebSocketFrame(Frame frame) {
  if (OpCode.PONG == frame.getOpCode()) {
    ByteBuffer payload = frame.getPayload() != null ? frame.getPayload() : EMPTY_PAYLOAD;
    PongMessage message = new PongMessage(payload);
    try {
      this.webSocketHandler.handleMessage(this.wsSession, message);
    }
    catch (Throwable ex) {
      ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void delegateMessages() throws Exception {
  String msg1 = "message 1";
  String msg2 = "message 2";
  this.session.delegateMessages(msg1, msg2);
  verify(this.webSocketHandler).handleMessage(this.session, new TextMessage(msg1));
  verify(this.webSocketHandler).handleMessage(this.session, new TextMessage(msg2));
  verifyNoMoreInteractions(this.webSocketHandler);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleWebSocketMessageBinary() throws Exception {
  String text = "SEND\na:alpha\n\nMessage payload\0";
  connect().handleMessage(this.webSocketSession, new BinaryMessage(text.getBytes(StandardCharsets.UTF_8)));
  ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
  verify(this.stompSession).handleMessage(captor.capture());
  Message<byte[]> message = captor.getValue();
  assertNotNull(message);
  StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
  StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
  assertEquals(StompCommand.SEND, accessor.getCommand());
  assertEquals("alpha", headers.getFirst("a"));
  assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void handleWebSocketMessage() throws Exception {
  String text = "SEND\na:alpha\n\nMessage payload\0";
  connect().handleMessage(this.webSocketSession, new TextMessage(text));
  ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
  verify(this.stompSession).handleMessage(captor.capture());
  Message<byte[]> message = captor.getValue();
  assertNotNull(message);
  StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
  StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
  assertEquals(StompCommand.SEND, accessor.getCommand());
  assertEquals("alpha", headers.getFirst("a"));
  assertEquals("Message payload", new String(message.getPayload(), StandardCharsets.UTF_8));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void handleFrameMessageWithWebSocketHandlerException() throws Exception {
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  willThrow(new IllegalStateException("Fake error")).given(this.handler)
      .handleMessage(this.session, new TextMessage("foo"));
  willThrow(new IllegalStateException("Fake error")).given(this.handler)
      .handleMessage(this.session, new TextMessage("bar"));
  this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
  assertThat(this.session.isOpen(), equalTo(true));
  verify(this.handler).afterConnectionEstablished(this.session);
  verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
  verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
  verifyNoMoreInteractions(this.handler);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void handleMessage() throws Exception {
  TextMessage message = new TextMessage("payload");
  willThrow(new IllegalStateException("error"))
    .given(this.delegate).handleMessage(this.session, message);
  this.decorator.handleMessage(this.session, message);
  assertEquals(CloseStatus.SERVER_ERROR, this.session.getCloseStatus());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void handleFrameMessage() throws Exception {
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent());
  verify(this.handler).afterConnectionEstablished(this.session);
  verify(this.handler).handleMessage(this.session, new TextMessage("foo"));
  verify(this.handler).handleMessage(this.session, new TextMessage("bar"));
  verifyNoMoreInteractions(this.handler);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void connectReceiveAndCloseWithPrelude() throws Exception {
  StringBuilder sb = new StringBuilder(2048);
  for (int i = 0; i < 2048; i++) {
    sb.append('h');
  }
  String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
  ClientHttpResponse response = response(HttpStatus.OK, body);
  connect(response);
  verify(this.webSocketHandler).afterConnectionEstablished(any());
  verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
  verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
  verifyNoMoreInteractions(this.webSocketHandler);
}

代码示例来源:origin: spring-projects/spring-framework

private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception {
  WebSocketHandler wsHandler = mock(WebSocketHandler.class);
  AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null);
  transportHandler.initialize(new StubSockJsServiceConfig());
  transportHandler.handleRequest(this.request, this.response, wsHandler, session);
  assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString());
  verify(wsHandler).handleMessage(session, new TextMessage("x"));
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void connectReceiveAndClose() throws Exception {
  String body = "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";
  ClientHttpResponse response = response(HttpStatus.OK, body);
  connect(response);
  verify(this.webSocketHandler).afterConnectionEstablished(any());
  verify(this.webSocketHandler).handleMessage(any(), eq(new TextMessage("foo")));
  verify(this.webSocketHandler).afterConnectionClosed(any(), eq(new CloseStatus(3000, "Go away!")));
  verifyNoMoreInteractions(this.webSocketHandler);
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com