use of org.springframework.web.socket.PingMessage in project ma-core-public by infiniteautomation.
the class MangoPingPongTracker method sendPing.
public void sendPing() {
try {
session.getAttributes().put(MangoWebSocketPublisher.RECEIVED_PONG, Boolean.FALSE);
session.sendMessage(new PingMessage());
} catch (IOException | WebSocketException e) {
if (log.isErrorEnabled()) {
log.error("Error sending websocket ping", e);
}
} finally {
task = new TimeoutTask(this.timeout, this);
}
}
use of org.springframework.web.socket.PingMessage in project spring-integration by spring-projects.
the class ClientWebSocketContainerTests method testClientWebSocketContainer.
@Test
public void testClientWebSocketContainer() throws Exception {
final AtomicBoolean failure = new AtomicBoolean();
StandardWebSocketClient webSocketClient = new StandardWebSocketClient() {
@Override
protected ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri, List<String> protocols, List<WebSocketExtension> extensions, Map<String, Object> attributes) {
ListenableFuture<WebSocketSession> future = super.doHandshakeInternal(webSocketHandler, headers, uri, protocols, extensions, attributes);
if (failure.get()) {
future.cancel(true);
}
return future;
}
};
Map<String, Object> userProperties = new HashMap<String, Object>();
userProperties.put(Constants.IO_TIMEOUT_MS_PROPERTY, "" + (Constants.IO_TIMEOUT_MS_DEFAULT * 6));
webSocketClient.setUserProperties(userProperties);
ClientWebSocketContainer container = new ClientWebSocketContainer(webSocketClient, server.getWsBaseUrl() + "/ws/websocket");
TestWebSocketListener messageListener = new TestWebSocketListener();
container.setMessageListener(messageListener);
container.setConnectionTimeout(30);
container.start();
WebSocketSession session = container.getSession(null);
assertNotNull(session);
assertTrue(session.isOpen());
assertEquals("v10.stomp", session.getAcceptedProtocol());
session.sendMessage(new PingMessage());
assertTrue(messageListener.messageLatch.await(10, TimeUnit.SECONDS));
container.stop();
try {
container.getSession(null);
fail("IllegalStateException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertEquals(e.getMessage(), "'clientSession' has not been established. Consider to 'start' this container.");
}
assertTrue(messageListener.sessionEndedLatch.await(10, TimeUnit.SECONDS));
assertFalse(session.isOpen());
assertTrue(messageListener.started);
assertThat(messageListener.message, instanceOf(PongMessage.class));
failure.set(true);
container.start();
try {
container.getSession(null);
fail("IllegalStateException is expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getCause(), instanceOf(CancellationException.class));
}
failure.set(false);
container.start();
session = container.getSession(null);
assertNotNull(session);
assertTrue(session.isOpen());
}
use of org.springframework.web.socket.PingMessage in project spring-boot by spring-projects.
the class LiveReloadServerTests method pingPong.
@Test
void pingPong() throws Exception {
LiveReloadWebSocketHandler handler = connect();
handler.sendMessage(new PingMessage());
await().atMost(Duration.ofSeconds(10)).until(handler::getPongCount, is(1));
}
Aggregations