Search in sources :

Example 66 with TextMessage

use of org.springframework.web.socket.TextMessage in project spring-boot-starter-samples by vindell.

the class WebsocketEndPoint method handleTextMessage.

@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
    super.handleTextMessage(session, message);
    TextMessage returnMessage = new TextMessage(message.getPayload() + " received at server");
    session.sendMessage(returnMessage);
}
Also used : TextMessage(org.springframework.web.socket.TextMessage)

Example 67 with TextMessage

use of org.springframework.web.socket.TextMessage in project roof-im by madfroglx.

the class WebSocketResponseEndPoint method send.

@Override
public void send(String connectId, Response response) throws IOException, ConnectNotExistException {
    WebSocketSession webSocketSession = webSocketSessionConnectManager.get(connectId);
    if (webSocketSession == null) {
        throw new ConnectNotExistException();
    }
    // if (!webSocketSession.isOpen()) {
    // return;
    // }
    TextMessage textMessage = new TextMessage(JSON.toJSONString(response));
    try {
        webSocketSession.sendMessage(textMessage);
    } catch (Exception e) {
        // 消息推送异常则关闭连接
        WebSocketUtils.tryCloseWithError(webSocketSession, e, LOGGER);
        throw e;
    }
}
Also used : ConnectNotExistException(org.roof.im.gateway.ConnectNotExistException) TextMessage(org.springframework.web.socket.TextMessage) IOException(java.io.IOException) ConnectNotExistException(org.roof.im.gateway.ConnectNotExistException) WebSocketSession(org.springframework.web.socket.WebSocketSession)

Aggregations

TextMessage (org.springframework.web.socket.TextMessage)67 Test (org.junit.Test)48 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)16 WebSocketSession (org.springframework.web.socket.WebSocketSession)11 IOException (java.io.IOException)8 BinaryMessage (org.springframework.web.socket.BinaryMessage)8 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)7 Message (org.springframework.messaging.Message)6 URI (java.net.URI)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 StompEncoder (org.springframework.messaging.simp.stomp.StompEncoder)4 WebSocketHandler (org.springframework.web.socket.WebSocketHandler)4 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)4 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)3 MessageChannel (org.springframework.messaging.MessageChannel)3 ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)3 ImmutableMessageChannelInterceptor (org.springframework.messaging.support.ImmutableMessageChannelInterceptor)3 CloseStatus (org.springframework.web.socket.CloseStatus)3 TestWebSocketSession (org.springframework.web.socket.handler.TestWebSocketSession)3 SockJsMessageDeliveryException (org.springframework.web.socket.sockjs.SockJsMessageDeliveryException)3