org.springframework.web.socket.messaging.WebSocketStompClient类的使用及代码示例

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

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

WebSocketStompClient介绍

[英]A STOMP over WebSocket client that connects using an implementation of org.springframework.web.socket.client.WebSocketClientincluding org.springframework.web.socket.sockjs.client.SockJsClient.
[中]一个使用org实现连接的STOMP over WebSocket客户端。springframework。网状物插座客户WebSocketClient包括组织。springframework。网状物插座索克斯。客户SockJsClient。

代码示例

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

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

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

@Test
public void heartbeatDefaultValueSetWithoutScheduler() throws Exception {
  WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
  stompClient.setDefaultHeartbeat(new long[] {5, 5});
  try {
    stompClient.processConnectHeaders(null);
    fail("Expected IllegalStateException");
  }
  catch (IllegalStateException ex) {
    // ignore
  }
}

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

@Test
public void heartbeatDefaultValueWithScheduler() throws Exception {
  WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
  stompClient.setTaskScheduler(mock(TaskScheduler.class));
  assertArrayEquals(new long[] {10000, 10000}, stompClient.getDefaultHeartbeat());
  StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
  assertArrayEquals(new long[] {10000, 10000}, connectHeaders.getHeartbeat());
}

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

@Override
public void start() {
  if (!isRunning()) {
    this.running = true;
    if (getWebSocketClient() instanceof Lifecycle) {
      ((Lifecycle) getWebSocketClient()).start();
    }
  }
}

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

/**
 * {@inheritDoc}
 * <p>Also automatically sets the {@link #setDefaultHeartbeat defaultHeartbeat}
 * property to "10000,10000" if it is currently set to "0,0".
 */
@Override
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
  if (!isDefaultHeartbeatEnabled()) {
    setDefaultHeartbeat(new long[] {10000, 10000});
  }
  super.setTaskScheduler(taskScheduler);
}

代码示例来源: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: CaledoniaProject/CVE-2018-1270

public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());

    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);

    new Scanner(System.in).nextLine(); //Don't close immediately.
  }
}

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

@Bean
@ConditionalOnMissingBean(WebSocketStompClient.class)
public WebSocketStompClient stompClient(WebSocketClient webSocketClient, MessageConverter messageConverter,
                    @Qualifier("proxyStompClientTaskScheduler") TaskScheduler taskScheduler) {
  int bufferSizeLimit = 1024 * 1024 * 8;
  WebSocketStompClient client = new WebSocketStompClient(webSocketClient);
  client.setInboundMessageSizeLimit(bufferSizeLimit);
  client.setMessageConverter(messageConverter);
  client.setTaskScheduler(taskScheduler);
  client.setDefaultHeartbeat(new long[]{0, 0});
  return client;
}

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

@Bean
public WebSocketStompClient stompClient(TaskScheduler taskScheduler) {
  WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient());
  webSocketStompClient.setTaskScheduler(taskScheduler);
  webSocketStompClient.setReceiptTimeLimit(5000);
  webSocketStompClient.setMessageConverter(new StringMessageConverter());
  return webSocketStompClient;
}

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

@Bean
public WebSocketStompClient stompClient(TaskScheduler taskScheduler) {
  WebSocketStompClient webSocketStompClient = new WebSocketStompClient(webSocketClient());
  webSocketStompClient.setMessageConverter(new MappingJackson2MessageConverter());
  webSocketStompClient.setTaskScheduler(taskScheduler);
  return webSocketStompClient;
}

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

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

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

@Before
public void setUp() throws Exception {
  logger.debug("Setting up before '" + this.testName.getMethodName() + "'");
  this.wac = new AnnotationConfigWebApplicationContext();
  this.wac.register(TestConfig.class);
  this.wac.refresh();
  this.server = new TomcatWebSocketTestServer();
  this.server.setup();
  this.server.deployConfig(this.wac);
  this.server.start();
  WebSocketClient webSocketClient = new StandardWebSocketClient();
  this.stompClient = new WebSocketStompClient(webSocketClient);
  this.stompClient.setMessageConverter(new StringMessageConverter());
}

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

@Override
public void onReadInactivity(final Runnable runnable, final long duration) {
  Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
  this.lastReadTime = System.currentTimeMillis();
  this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
    if (System.currentTimeMillis() - this.lastReadTime > duration) {
      try {
        runnable.run();
      }
      catch (Throwable ex) {
        if (logger.isDebugEnabled()) {
          logger.debug("ReadInactivityTask failure", ex);
        }
      }
    }
  }, duration / 2));
}

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

/**
 * Class constructor. Sets {@link #setDefaultHeartbeat} to "0,0" but will
 * reset it back to the preferred "10000,10000" when a
 * {@link #setTaskScheduler} is configured.
 * @param webSocketClient the WebSocket client to connect with
 */
public WebSocketStompClient(WebSocketClient webSocketClient) {
  Assert.notNull(webSocketClient, "WebSocketClient is required");
  this.webSocketClient = webSocketClient;
  setDefaultHeartbeat(new long[] {0, 0});
}

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

@Test
public void heartbeatDefaultValue() throws Exception {
  WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
  assertArrayEquals(new long[] {0, 0}, stompClient.getDefaultHeartbeat());
  StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
  assertArrayEquals(new long[] {0, 0}, connectHeaders.getHeartbeat());
}

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

@Override
public void stop() {
  if (isRunning()) {
    this.running = false;
    if (getWebSocketClient() instanceof Lifecycle) {
      ((Lifecycle) getWebSocketClient()).stop();
    }
  }
}

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

/**
 * {@inheritDoc}
 * <p>Also automatically sets the {@link #setDefaultHeartbeat defaultHeartbeat}
 * property to "10000,10000" if it is currently set to "0,0".
 */
@Override
public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) {
  if (!isDefaultHeartbeatEnabled()) {
    setDefaultHeartbeat(new long[] {10000, 10000});
  }
  super.setTaskScheduler(taskScheduler);
}

代码示例来源: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: spring-projects/spring-framework

@Override
public void onWriteInactivity(final Runnable runnable, final long duration) {
  Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
  this.lastWriteTime = System.currentTimeMillis();
  this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
    if (System.currentTimeMillis() - this.lastWriteTime > duration) {
      try {
        runnable.run();
      }
      catch (Throwable ex) {
        if (logger.isDebugEnabled()) {
          logger.debug("WriteInactivityTask failure", ex);
        }
      }
    }
  }, duration / 2));
}

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

/**
 * Class constructor. Sets {@link #setDefaultHeartbeat} to "0,0" but will
 * reset it back to the preferred "10000,10000" when a
 * {@link #setTaskScheduler} is configured.
 * @param webSocketClient the WebSocket client to connect with
 */
public WebSocketStompClient(WebSocketClient webSocketClient) {
  Assert.notNull(webSocketClient, "WebSocketClient is required");
  this.webSocketClient = webSocketClient;
  setDefaultHeartbeat(new long[] {0, 0});
}

相关文章