gpt4 book ai didi

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

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

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

WebSocketHandler.afterConnectionEstablished介绍

[英]Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use.
[中]在WebSocket协商成功且WebSocket连接打开并准备好使用后调用。

代码示例

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

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
  WebSocketHandler handler = this.provider.getHandler();
  this.handlers.put(session, handler);
  handler.afterConnectionEstablished(session);
}

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

@Override
public void afterConnectionEstablished(WebSocketSession session) {
  try {
    getDelegate().afterConnectionEstablished(session);
  }
  catch (Throwable ex) {
    tryCloseWithError(session, ex, logger);
  }
}

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

@SuppressWarnings("unchecked")
private TcpConnection<byte[]> getTcpConnection() throws Exception {
  WebSocketHandler webSocketHandler = connect();
  webSocketHandler.afterConnectionEstablished(this.webSocketSession);
  return (TcpConnection<byte[]>) webSocketHandler;
}

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

@OnWebSocketConnect
public void onWebSocketConnect(Session session) {
  try {
    this.wsSession.initializeNativeSession(session);
    this.webSocketHandler.afterConnectionEstablished(this.wsSession);
  }
  catch (Throwable ex) {
    ExceptionWebSocketHandlerDecorator.tryCloseWithError(this.wsSession, ex, logger);
  }
}

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

@Test
public void afterSessionInitialized() throws Exception {
  this.session.initializeDelegateSession(this.webSocketSession);
  assertEquals(Collections.singletonList(new TextMessage("o")), this.webSocketSession.getSentMessages());
  assertEquals(Arrays.asList("schedule"), this.session.heartbeatSchedulingEvents);
  verify(this.webSocketHandler).afterConnectionEstablished(this.session);
  verifyNoMoreInteractions(this.taskScheduler, this.webSocketHandler);
}

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

@Test
public void webSocketConnectionEstablished() throws Exception {
  connect().afterConnectionEstablished(this.webSocketSession);
  verify(this.stompSession).afterConnected(notNull());
}

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

@Test
public void onOpen() throws Throwable {
  this.adapter.onWebSocketConnect(this.session);
  verify(this.webSocketHandler).afterConnectionEstablished(this.webSocketSession);
}

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

@Test
public void webSocketHandlerDecorator() throws Exception {
  ApplicationContext config = createConfig(WebSocketHandlerDecoratorConfig.class);
  WebSocketHandler handler = config.getBean(SubProtocolWebSocketHandler.class);
  assertNotNull(handler);
  SimpleUrlHandlerMapping mapping = (SimpleUrlHandlerMapping) config.getBean("stompWebSocketHandlerMapping");
  WebSocketHttpRequestHandler httpHandler = (WebSocketHttpRequestHandler) mapping.getHandlerMap().get("/test");
  handler = httpHandler.getWebSocketHandler();
  WebSocketSession session = new TestWebSocketSession("id");
  handler.afterConnectionEstablished(session);
  assertEquals(true, session.getAttributes().get("decorated"));
}

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

@Test
public void handleInitialRequest() throws Exception {
  this.session.handleInitialRequest(this.request, this.response, this.frameFormat);
  assertEquals("hhh\no", this.servletResponse.getContentAsString());
  assertTrue(this.servletRequest.isAsyncStarted());
  verify(this.webSocketHandler).afterConnectionEstablished(this.session);
}

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

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

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

@Test
public void handleFrameOpenWithWebSocketHandlerException() throws Exception {
  willThrow(new IllegalStateException("Fake error")).given(this.handler).afterConnectionEstablished(this.session);
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  assertThat(this.session.isOpen(), is(true));
}

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

@Test
public void close() throws Exception {
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  this.session.close();
  assertThat(this.session.isOpen(), equalTo(false));
  assertThat(this.session.disconnectStatus, equalTo(CloseStatus.NORMAL));
  verify(this.handler).afterConnectionEstablished(this.session);
  verifyNoMoreInteractions(this.handler);
}

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

@Test
public void handleFrameClose() throws Exception {
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  this.session.handleFrame(SockJsFrame.closeFrame(1007, "").getContent());
  assertThat(this.session.isOpen(), equalTo(false));
  assertThat(this.session.disconnectStatus, equalTo(new CloseStatus(1007, "")));
  verify(this.handler).afterConnectionEstablished(this.session);
  verifyNoMoreInteractions(this.handler);
}

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

@Test
public void eventSourceTransport() throws Exception {
  EventSourceTransportHandler transportHandler = new EventSourceTransportHandler();
  transportHandler.initialize(this.sockJsConfig);
  StreamingSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null);
  transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
  assertEquals("text/event-stream;charset=UTF-8", this.response.getHeaders().getContentType().toString());
  assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
  verify(this.webSocketHandler).afterConnectionEstablished(session);
}

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

@Test
public void handleFrameOpen() throws Exception {
  assertThat(this.session.isOpen(), is(false));
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  assertThat(this.session.isOpen(), is(true));
  assertTrue(this.connectFuture.isDone());
  assertThat(this.connectFuture.get(), sameInstance(this.session));
  verify(this.handler).afterConnectionEstablished(this.session);
  verifyNoMoreInteractions(this.handler);
}

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

@Test
public void afterTransportClosed() throws Exception {
  this.session.handleFrame(SockJsFrame.openFrame().getContent());
  this.session.afterTransportClosed(CloseStatus.SERVER_ERROR);
  assertThat(this.session.isOpen(), equalTo(false));
  verify(this.handler).afterConnectionEstablished(this.session);
  verify(this.handler).afterConnectionClosed(this.session, CloseStatus.SERVER_ERROR);
  verifyNoMoreInteractions(this.handler);
}

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

@Test
public void handleRequestXhrStreaming() throws Exception {
  XhrStreamingTransportHandler transportHandler = new XhrStreamingTransportHandler();
  transportHandler.initialize(this.sockJsConfig);
  AbstractSockJsSession session = transportHandler.createSession("1", this.webSocketHandler, null);
  transportHandler.handleRequest(this.request, this.response, this.webSocketHandler, session);
  assertEquals("application/javascript;charset=UTF-8", this.response.getHeaders().getContentType().toString());
  assertTrue("Streaming request not started", this.servletRequest.isAsyncStarted());
  verify(this.webSocketHandler).afterConnectionEstablished(session);
}

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

@Test
public void errorResponseStatus() throws Exception {
  connect(response(HttpStatus.OK, "o\n"), response(HttpStatus.INTERNAL_SERVER_ERROR, "Oops"));
  verify(this.webSocketHandler).afterConnectionEstablished(any());
  verify(this.webSocketHandler).handleTransportError(any(), any());
  verify(this.webSocketHandler).afterConnectionClosed(any(), any());
  verifyNoMoreInteractions(this.webSocketHandler);
}

代码示例来源: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 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);
}

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