use of org.springframework.web.socket.WebSocketSession in project pinpoint by naver.
the class ActiveThreadCountResponseAggregator method flush0.
private void flush0(TextMessage webSocketMessage) {
for (WebSocketSession webSocketSession : webSocketSessions) {
try {
logger.debug("flush webSocketSession:{}, response:{}", webSocketSession, webSocketMessage);
webSocketSession.sendMessage(webSocketMessage);
} catch (Exception e) {
logger.warn("failed while flushing message to webSocket. session:{}, message:{}, error:{}", webSocketSession, webSocketMessage, e.getMessage(), e);
}
}
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class SubProtocolWebSocketHandler method handleMessage.
/**
* Handle an outbound Spring Message to a WebSocket client.
*/
@Override
public void handleMessage(Message<?> message) throws MessagingException {
String sessionId = resolveSessionId(message);
if (sessionId == null) {
if (logger.isErrorEnabled()) {
logger.error("Couldn't find session id in " + message);
}
return;
}
WebSocketSessionHolder holder = this.sessions.get(sessionId);
if (holder == null) {
if (logger.isDebugEnabled()) {
// The broker may not have removed the session yet
logger.debug("No session for " + message);
}
return;
}
WebSocketSession session = holder.getSession();
try {
findProtocolHandler(session).handleMessageToClient(session, message);
} catch (SessionLimitExceededException ex) {
try {
if (logger.isDebugEnabled()) {
logger.debug("Terminating '" + session + "'", ex);
}
this.stats.incrementLimitExceededCount();
// clear first, session may be unresponsive
clearSession(session, ex.getStatus());
session.close(ex.getStatus());
} catch (Exception secondException) {
logger.debug("Failure while closing session " + sessionId + ".", secondException);
}
} catch (Exception ex) {
// Could be part of normal workflow (e.g. browser tab closed)
if (logger.isDebugEnabled()) {
logger.debug("Failed to send message to client in " + session + ": " + message, ex);
}
}
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class StandardWebSocketClientTests method testGetRemoteAddress.
@Test
public void testGetRemoteAddress() throws Exception {
URI uri = new URI("wss://localhost/abc");
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
assertNotNull(session.getRemoteAddress());
assertEquals("localhost", session.getRemoteAddress().getHostName());
assertEquals(443, session.getLocalAddress().getPort());
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class StandardWebSocketClientTests method handshakeHeaders.
@Test
public void handshakeHeaders() throws Exception {
URI uri = new URI("ws://localhost/abc");
List<String> protocols = Collections.singletonList("abc");
this.headers.setSecWebSocketProtocol(protocols);
this.headers.add("foo", "bar");
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
assertEquals(1, session.getHandshakeHeaders().size());
assertEquals("bar", session.getHandshakeHeaders().getFirst("foo"));
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class WebSocketConfigurationTests method registerWebSocketHandler.
@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();
}
Aggregations