org.springframework.web.socket.messaging.WebSocketStompClient.connect()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(124)

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

WebSocketStompClient.connect介绍

[英]Connect to the given WebSocket URL and notify the given org.springframework.messaging.simp.stomp.StompSessionHandlerwhen connected on the STOMP level after the CONNECTED frame is received.
[中]连接到给定的WebSocket URL并通知给定的组织。springframework。信息。辛普。跺脚StompSessionHandler在收到连接的帧后在STOMP级别上连接时。

代码示例

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

  1. /**
  2. * Connect to the given WebSocket URL and notify the given
  3. * {@link org.springframework.messaging.simp.stomp.StompSessionHandler}
  4. * when connected on the STOMP level after the CONNECTED frame is received.
  5. * @param url the url to connect to
  6. * @param handler the session handler
  7. * @param uriVars the URI variables to expand into the URL
  8. * @return a ListenableFuture for access to the session when ready for use
  9. */
  10. public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
  11. return connect(url, null, handler, uriVars);
  12. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also
  4. * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake.
  5. * @param url the url to connect to
  6. * @param handshakeHeaders the headers for the WebSocket handshake
  7. * @param handler the session handler
  8. * @param uriVariables the URI variables to expand into the URL
  9. * @return a ListenableFuture for access to the session when ready for use
  10. */
  11. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  12. StompSessionHandler handler, Object... uriVariables) {
  13. return connect(url, handshakeHeaders, null, handler, uriVariables);
  14. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also accepts
  4. * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and
  5. * {@link StompHeaders} for the STOMP CONNECT frame.
  6. * @param url the url to connect to
  7. * @param handshakeHeaders headers for the WebSocket handshake
  8. * @param connectHeaders headers for the STOMP CONNECT frame
  9. * @param handler the session handler
  10. * @param uriVariables the URI variables to expand into the URL
  11. * @return a ListenableFuture for access to the session when ready for use
  12. */
  13. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  14. @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
  15. Assert.notNull(url, "'url' must not be null");
  16. URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri();
  17. return connect(uri, handshakeHeaders, connectHeaders, handler);
  18. }

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

  1. @Test
  2. public void publishSubscribe() throws Exception {
  3. String url = "ws://127.0.0.1:" + this.server.getPort() + "/stomp";
  4. TestHandler testHandler = new TestHandler("/topic/foo", "payload");
  5. this.stompClient.connect(url, testHandler);
  6. assertTrue(testHandler.awaitForMessageCount(1, 5000));
  7. assertThat(testHandler.getReceived(), containsInAnyOrder("payload"));
  8. }

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

  1. @Override
  2. protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
  3. return ((WebSocketStompClient) this.stompClient).connect(this.url, this.handshakeHeaders, getConnectHeaders(),
  4. handler, this.uriVariables);
  5. }

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

  1. /**
  2. * Connect to the given WebSocket URL and notify the given
  3. * {@link org.springframework.messaging.simp.stomp.StompSessionHandler}
  4. * when connected on the STOMP level after the CONNECTED frame is received.
  5. * @param url the url to connect to
  6. * @param handler the session handler
  7. * @param uriVars the URI variables to expand into the URL
  8. * @return a ListenableFuture for access to the session when ready for use
  9. */
  10. public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
  11. return connect(url, null, handler, uriVars);
  12. }

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

  1. /**
  2. * Connect to the given WebSocket URL and notify the given
  3. * {@link org.springframework.messaging.simp.stomp.StompSessionHandler}
  4. * when connected on the STOMP level after the CONNECTED frame is received.
  5. * @param url the url to connect to
  6. * @param handler the session handler
  7. * @param uriVars the URI variables to expand into the URL
  8. * @return a ListenableFuture for access to the session when ready for use
  9. */
  10. public ListenableFuture<StompSession> connect(String url, StompSessionHandler handler, Object... uriVars) {
  11. return connect(url, null, handler, uriVars);
  12. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also
  4. * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake.
  5. * @param url the url to connect to
  6. * @param handshakeHeaders the headers for the WebSocket handshake
  7. * @param handler the session handler
  8. * @param uriVariables the URI variables to expand into the URL
  9. * @return a ListenableFuture for access to the session when ready for use
  10. */
  11. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  12. StompSessionHandler handler, Object... uriVariables) {
  13. return connect(url, handshakeHeaders, null, handler, uriVariables);
  14. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also
  4. * accepts {@link WebSocketHttpHeaders} to use for the WebSocket handshake.
  5. * @param url the url to connect to
  6. * @param handshakeHeaders the headers for the WebSocket handshake
  7. * @param handler the session handler
  8. * @param uriVariables the URI variables to expand into the URL
  9. * @return a ListenableFuture for access to the session when ready for use
  10. */
  11. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  12. StompSessionHandler handler, Object... uriVariables) {
  13. return connect(url, handshakeHeaders, null, handler, uriVariables);
  14. }

代码示例来源:origin: mthizo247/spring-cloud-netflix-zuul-websocket

  1. public void connect() {
  2. try {
  3. serverSession = stompClient
  4. .connect(getUri().toString(), buildWebSocketHttpHeaders(), this)
  5. .get();
  6. } catch (Exception e) {
  7. logger.error("Error connecting to web socket uri " + getUri(), e);
  8. throw new RuntimeException(e);
  9. }
  10. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also accepts
  4. * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and
  5. * {@link StompHeaders} for the STOMP CONNECT frame.
  6. * @param url the url to connect to
  7. * @param handshakeHeaders headers for the WebSocket handshake
  8. * @param connectHeaders headers for the STOMP CONNECT frame
  9. * @param handler the session handler
  10. * @param uriVariables the URI variables to expand into the URL
  11. * @return a ListenableFuture for access to the session when ready for use
  12. */
  13. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  14. @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
  15. Assert.notNull(url, "'url' must not be null");
  16. URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri();
  17. return connect(uri, handshakeHeaders, connectHeaders, handler);
  18. }

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

  1. /**
  2. * An overloaded version of
  3. * {@link #connect(String, StompSessionHandler, Object...)} that also accepts
  4. * {@link WebSocketHttpHeaders} to use for the WebSocket handshake and
  5. * {@link StompHeaders} for the STOMP CONNECT frame.
  6. * @param url the url to connect to
  7. * @param handshakeHeaders headers for the WebSocket handshake
  8. * @param connectHeaders headers for the STOMP CONNECT frame
  9. * @param handler the session handler
  10. * @param uriVariables the URI variables to expand into the URL
  11. * @return a ListenableFuture for access to the session when ready for use
  12. */
  13. public ListenableFuture<StompSession> connect(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
  14. @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
  15. Assert.notNull(url, "'url' must not be null");
  16. URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri();
  17. return connect(uri, handshakeHeaders, connectHeaders, handler);
  18. }

代码示例来源:origin: stackoverflow.com

  1. WebSocketClient transport = new StandardWebSocketClient();
  2. WebSocketStompClient stompClient = new WebSocketStompClient(transport);
  3. MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
  4. stompClient.setMessageConverter(converter);
  5. StompSessionHandler handler = new WSClient(); //custom implementation
  6. String url = "ws://{URL}/ws/websocket";
  7. stompClient.connect(url, handler);

代码示例来源:origin: CaledoniaProject/CVE-2018-1270

  1. public static void main(String... argv) {
  2. WebSocketClient webSocketClient = new StandardWebSocketClient();
  3. WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
  4. stompClient.setMessageConverter(new MappingJackson2MessageConverter());
  5. stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
  6. String url = "ws://127.0.0.1:8080/hello";
  7. StompSessionHandler sessionHandler = new MySessionHandler();
  8. stompClient.connect(url, sessionHandler);
  9. new Scanner(System.in).nextLine(); //Don't close immediately.
  10. }
  11. }

相关文章