use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class SockJsSessionTests method delegateMessagesWithErrorAndConnectionClosing.
@Test
public void delegateMessagesWithErrorAndConnectionClosing() throws Exception {
WebSocketHandler wsHandler = new ExceptionWebSocketHandlerDecorator(this.webSocketHandler);
TestSockJsSession sockJsSession = new TestSockJsSession("1", this.sockJsConfig, wsHandler, Collections.<String, Object>emptyMap());
String msg1 = "message 1";
String msg2 = "message 2";
String msg3 = "message 3";
willThrow(new IOException()).given(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2));
sockJsSession.delegateConnectionEstablished();
try {
sockJsSession.delegateMessages(msg1, msg2, msg3);
fail("expected exception");
} catch (SockJsMessageDeliveryException ex) {
assertEquals(Collections.singletonList(msg3), ex.getUndeliveredMessages());
verify(this.webSocketHandler).afterConnectionEstablished(sockJsSession);
verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg1));
verify(this.webSocketHandler).handleMessage(sockJsSession, new TextMessage(msg2));
verify(this.webSocketHandler).afterConnectionClosed(sockJsSession, CloseStatus.SERVER_ERROR);
verifyNoMoreInteractions(this.webSocketHandler);
}
}
use of org.springframework.web.socket.TextMessage in project pinpoint by naver.
the class ActiveThreadCountResponseAggregator method flush.
@Override
public void flush(Executor executor) throws Exception {
if ((flushCount.getAndIncrement() % LOG_RECORD_RATE) == 0) {
logger.info("flush started. applicationName:{}", applicationName);
}
if (isStopped) {
return;
}
AgentActiveThreadCountList response = new AgentActiveThreadCountList();
synchronized (aggregatorLock) {
for (ActiveThreadCountWorker activeThreadCountWorker : activeThreadCountWorkerRepository.values()) {
String agentId = activeThreadCountWorker.getAgentId();
AgentActiveThreadCount agentActiveThreadCount = activeThreadCountMap.get(agentId);
if (agentActiveThreadCount != null) {
response.add(agentActiveThreadCount);
} else {
response.add(activeThreadCountWorker.getDefaultFailResponse());
}
}
activeThreadCountMap = new HashMap<>(activeThreadCountWorkerRepository.size());
}
TextMessage webSocketTextMessage = createWebSocketTextMessage(response);
if (webSocketTextMessage != null) {
if (executor == null) {
flush0(webSocketTextMessage);
} else {
flushAsync0(webSocketTextMessage, executor);
}
}
}
use of org.springframework.web.socket.TextMessage in project spring-boot by spring-projects.
the class EchoWebSocketHandler method handleTextMessage.
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String echoMessage = this.echoService.getMessage(message.getPayload());
logger.debug(echoMessage);
session.sendMessage(new TextMessage(echoMessage));
}
use of org.springframework.web.socket.TextMessage in project spring-boot by spring-projects.
the class EchoWebSocketHandler method handleTextMessage.
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
String echoMessage = this.echoService.getMessage(message.getPayload());
logger.debug(echoMessage);
session.sendMessage(new TextMessage(echoMessage));
}
use of org.springframework.web.socket.TextMessage in project spring-boot by spring-projects.
the class SimpleClientWebSocketHandler method afterConnectionEstablished.
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
TextMessage message = new TextMessage(this.greetingService.getGreeting());
session.sendMessage(message);
}
Aggregations