gpt4 book ai didi

org.springframework.web.socket.client.WebSocketClient.doHandshake()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-24 13:01:05 29 4
gpt4 key购买 nike

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

WebSocketClient.doHandshake介绍

暂无

代码示例

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

@Override
protected void openConnection() {
  if (logger.isInfoEnabled()) {
    logger.info("Connecting to WebSocket at " + getUri());
  }
  ListenableFuture<WebSocketSession> future =
      this.client.doHandshake(this.webSocketHandler, this.headers, getUri());
  future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
    @Override
    public void onSuccess(@Nullable WebSocketSession result) {
      webSocketSession = result;
      logger.info("Successfully connected");
    }
    @Override
    public void onFailure(Throwable ex) {
      logger.error("Failed to connect", ex);
    }
  });
}

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

protected ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler clientHandler, String endpointPath) {
  return this.webSocketClient.doHandshake(clientHandler, getWsBaseUrl() + endpointPath);
}

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

/**
 * An overloaded version of
 * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)}
 * that accepts a fully prepared {@link java.net.URI}.
 * @param url the url to connect to
 * @param handshakeHeaders the headers for the WebSocket handshake
 * @param connectHeaders headers for the STOMP CONNECT frame
 * @param sessionHandler the STOMP session handler
 * @return a ListenableFuture for access to the session when ready for use
 */
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
    @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
  Assert.notNull(url, "'url' must not be null");
  ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler);
  WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session);
  getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter);
  return session.getSessionFuture();
}

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

@Before
public void setUp() throws Exception {
  MockitoAnnotations.initMocks(this);
  WebSocketClient webSocketClient = mock(WebSocketClient.class);
  this.stompClient = new TestWebSocketStompClient(webSocketClient);
  this.stompClient.setTaskScheduler(this.taskScheduler);
  this.stompClient.setStompSession(this.stompSession);
  this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class);
  this.handshakeFuture = new SettableListenableFuture<>();
  when(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class)))
      .thenReturn(this.handshakeFuture);
}

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

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
  final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<>();
  WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
  handler = new ClientSockJsWebSocketHandler(session);
  request.addTimeoutTask(session.getTimeoutTask());
  URI url = request.getTransportUrl();
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
  if (logger.isDebugEnabled()) {
    logger.debug("Starting WebSocket session on " + url);
  }
  this.webSocketClient.doHandshake(handler, headers, url).addCallback(
      new ListenableFutureCallback<WebSocketSession>() {
        @Override
        public void onSuccess(@Nullable WebSocketSession webSocketSession) {
          // WebSocket session ready, SockJS Session not yet
        }
        @Override
        public void onFailure(Throwable ex) {
          future.setException(ex);
        }
      });
  return future;
}

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

@Test
public void registerWebSocketHandlerWithSockJS() throws Exception {
  WebSocketSession session = this.webSocketClient.doHandshake(
      new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/sockjs/websocket").get();
  TestHandler serverHandler = this.wac.getBean(TestHandler.class);
  assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
  session.close();
}

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

@Test
public void registerWebSocketHandler() throws Exception {
  WebSocketSession session = this.webSocketClient.doHandshake(
      new AbstractWebSocketHandler() {}, getWsBaseUrl() + "/ws").get();
  TestHandler serverHandler = this.wac.getBean(TestHandler.class);
  assertTrue(serverHandler.connectLatch.await(2, TimeUnit.SECONDS));
  session.close();
}

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

@Test  // SPR-12727
public void unsolicitedPongWithEmptyPayload() throws Exception {
  String url = getWsBaseUrl() + "/ws";
  WebSocketSession session = this.webSocketClient.doHandshake(new AbstractWebSocketHandler() {}, url).get();
  TestWebSocketHandler serverHandler = this.wac.getBean(TestWebSocketHandler.class);
  serverHandler.setWaitMessageCount(1);
  session.sendMessage(new PongMessage());
  serverHandler.await();
  assertNull(serverHandler.getTransportError());
  assertEquals(1, serverHandler.getReceivedMessages().size());
  assertEquals(PongMessage.class, serverHandler.getReceivedMessages().get(0).getClass());
}

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

@Test
public void subProtocolNegotiation() throws Exception {
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
  headers.setSecWebSocketProtocol("foo");
  URI url = new URI(getWsBaseUrl() + "/ws");
  WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get();
  assertEquals("foo", session.getAcceptedProtocol());
  session.close();
}

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

@Override
protected void openConnection() {
  logger.info("Connecting to WebSocket at " + getUri());
  ClientWebSocketContainer.this.headers.setSecWebSocketProtocol(getSubProtocols());
  ListenableFuture<WebSocketSession> future =
      this.client.doHandshake(ClientWebSocketContainer.this.webSocketHandler,
          ClientWebSocketContainer.this.headers, getUri());
  future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
    @Override
    public void onSuccess(WebSocketSession session) {
      ClientWebSocketContainer.this.clientSession = session;
      logger.info("Successfully connected");
      ClientWebSocketContainer.this.connectionLatch.countDown();
    }
    @Override
    public void onFailure(Throwable t) {
      logger.error("Failed to connect", t);
      ClientWebSocketContainer.this.openConnectionException = t;
      ClientWebSocketContainer.this.connectionLatch.countDown();
    }
  });
}

代码示例来源:origin: org.springframework/spring-websocket

@Override
protected void openConnection() {
  if (logger.isInfoEnabled()) {
    logger.info("Connecting to WebSocket at " + getUri());
  }
  ListenableFuture<WebSocketSession> future =
      this.client.doHandshake(this.webSocketHandler, this.headers, getUri());
  future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
    @Override
    public void onSuccess(@Nullable WebSocketSession result) {
      webSocketSession = result;
      logger.info("Successfully connected");
    }
    @Override
    public void onFailure(Throwable ex) {
      logger.error("Failed to connect", ex);
    }
  });
}

代码示例来源:origin: apache/servicemix-bundles

@Override
protected void openConnection() {
  if (logger.isInfoEnabled()) {
    logger.info("Connecting to WebSocket at " + getUri());
  }
  ListenableFuture<WebSocketSession> future =
      this.client.doHandshake(this.webSocketHandler, this.headers, getUri());
  future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
    @Override
    public void onSuccess(@Nullable WebSocketSession result) {
      webSocketSession = result;
      logger.info("Successfully connected");
    }
    @Override
    public void onFailure(Throwable ex) {
      logger.error("Failed to connect", ex);
    }
  });
}

代码示例来源:origin: org.springframework/spring-websocket

/**
 * An overloaded version of
 * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)}
 * that accepts a fully prepared {@link java.net.URI}.
 * @param url the url to connect to
 * @param handshakeHeaders the headers for the WebSocket handshake
 * @param connectHeaders headers for the STOMP CONNECT frame
 * @param sessionHandler the STOMP session handler
 * @return a ListenableFuture for access to the session when ready for use
 */
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
    @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
  Assert.notNull(url, "'url' must not be null");
  ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler);
  WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session);
  getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter);
  return session.getSessionFuture();
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * An overloaded version of
 * {@link #connect(String, WebSocketHttpHeaders, StompSessionHandler, Object...)}
 * that accepts a fully prepared {@link java.net.URI}.
 * @param url the url to connect to
 * @param handshakeHeaders the headers for the WebSocket handshake
 * @param connectHeaders headers for the STOMP CONNECT frame
 * @param sessionHandler the STOMP session handler
 * @return a ListenableFuture for access to the session when ready for use
 */
public ListenableFuture<StompSession> connect(URI url, @Nullable WebSocketHttpHeaders handshakeHeaders,
    @Nullable StompHeaders connectHeaders, StompSessionHandler sessionHandler) {
  Assert.notNull(url, "'url' must not be null");
  ConnectionHandlingStompSession session = createSession(connectHeaders, sessionHandler);
  WebSocketTcpConnectionHandlerAdapter adapter = new WebSocketTcpConnectionHandlerAdapter(session);
  getWebSocketClient().doHandshake(adapter, handshakeHeaders, url).addCallback(adapter);
  return session.getSessionFuture();
}

代码示例来源:origin: org.springframework.integration/spring-integration-websocket

@Override
protected void openConnection() {
  logger.info("Connecting to WebSocket at " + getUri());
  ClientWebSocketContainer.this.headers.setSecWebSocketProtocol(getSubProtocols());
  ListenableFuture<WebSocketSession> future =
      this.client.doHandshake(ClientWebSocketContainer.this.webSocketHandler,
          ClientWebSocketContainer.this.headers, getUri());
  future.addCallback(new ListenableFutureCallback<WebSocketSession>() {
    @Override
    public void onSuccess(WebSocketSession session) {
      ClientWebSocketContainer.this.clientSession = session;
      logger.info("Successfully connected");
      ClientWebSocketContainer.this.connectionLatch.countDown();
    }
    @Override
    public void onFailure(Throwable t) {
      logger.error("Failed to connect", t);
      ClientWebSocketContainer.this.openConnectionException = t;
      ClientWebSocketContainer.this.connectionLatch.countDown();
    }
  });
}

代码示例来源:origin: codeabovelab/haven-platform

private void connectToContainer(WebSocketSession session, String containerId) {
  ContainerRegistration containerReg = containerStorage.getContainer(containerId);
  ExtendedAssert.notFound(containerReg, "Can not find container: " + containerId);
  NodeRegistration nodeReg = nodeStorage.getNodeRegistration(containerReg.getNode());
  DockerContainer dc = containerReg.getContainer();
  NodeInfo nodeInfo = nodeReg.getNodeInfo();
  TtyProxy tty = new TtyProxy(containerReg.getId(), session, ImmutableMap.<String, String>builder()
   .put("container.name", dc.getName())
   .put("container.image", dc.getImage())
   .put("node.name", nodeInfo.getName())
   .put("node.addr", nodeInfo.getAddress())
   .build()
  );
  TtyProxy.set(session, tty);
  ListenableFuture<WebSocketSession> future = webSocketClient.doHandshake(tty, getContainerUri(containerReg.getId(), nodeReg));
  future.addCallback((r) -> {}, (e) -> log.error("failure to open backend connection to '{}' of cluster '{}' due to error: ", containerId, nodeReg.getCluster(), e));
}

代码示例来源:origin: org.springframework/spring-websocket

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
  final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<>();
  WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
  handler = new ClientSockJsWebSocketHandler(session);
  request.addTimeoutTask(session.getTimeoutTask());
  URI url = request.getTransportUrl();
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
  if (logger.isDebugEnabled()) {
    logger.debug("Starting WebSocket session on " + url);
  }
  this.webSocketClient.doHandshake(handler, headers, url).addCallback(
      new ListenableFutureCallback<WebSocketSession>() {
        @Override
        public void onSuccess(@Nullable WebSocketSession webSocketSession) {
          // WebSocket session ready, SockJS Session not yet
        }
        @Override
        public void onFailure(Throwable ex) {
          future.setException(ex);
        }
      });
  return future;
}

代码示例来源:origin: apache/servicemix-bundles

@Override
public ListenableFuture<WebSocketSession> connect(TransportRequest request, WebSocketHandler handler) {
  final SettableListenableFuture<WebSocketSession> future = new SettableListenableFuture<>();
  WebSocketClientSockJsSession session = new WebSocketClientSockJsSession(request, handler, future);
  handler = new ClientSockJsWebSocketHandler(session);
  request.addTimeoutTask(session.getTimeoutTask());
  URI url = request.getTransportUrl();
  WebSocketHttpHeaders headers = new WebSocketHttpHeaders(request.getHandshakeHeaders());
  if (logger.isDebugEnabled()) {
    logger.debug("Starting WebSocket session on " + url);
  }
  this.webSocketClient.doHandshake(handler, headers, url).addCallback(
      new ListenableFutureCallback<WebSocketSession>() {
        @Override
        public void onSuccess(@Nullable WebSocketSession webSocketSession) {
          // WebSocket session ready, SockJS Session not yet
        }
        @Override
        public void onFailure(Throwable ex) {
          future.setException(ex);
        }
      });
  return future;
}

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