use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class AbstractSockJsSession method delegateMessages.
public void delegateMessages(String... messages) throws SockJsMessageDeliveryException {
List<String> undelivered = new ArrayList<>(Arrays.asList(messages));
for (String message : messages) {
try {
if (isClosed()) {
throw new SockJsMessageDeliveryException(this.id, undelivered, "Session closed");
} else {
this.handler.handleMessage(this, new TextMessage(message));
undelivered.remove(0);
}
} catch (Throwable ex) {
throw new SockJsMessageDeliveryException(this.id, undelivered, ex);
}
}
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class WebSocketServerSockJsSession method writeFrameInternal.
@Override
protected void writeFrameInternal(SockJsFrame frame) throws IOException {
if (logger.isTraceEnabled()) {
logger.trace("Writing " + frame);
}
TextMessage message = new TextMessage(frame.getContent());
this.webSocketSession.sendMessage(message);
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class StompWebSocketIntegrationTests method sendSubscribeToControllerAndReceiveReply.
// SPR-11648
@Test
public void sendSubscribeToControllerAndReceiveReply() throws Exception {
String destHeader = "destination:/app/number";
TextMessage message = create(StompCommand.SUBSCRIBE).headers("id:subs1", destHeader).build();
TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(1, message);
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
try {
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
String payload = clientHandler.actual.get(0).getPayload();
assertTrue("Expected STOMP destination=/app/number, got " + payload, payload.contains(destHeader));
assertTrue("Expected STOMP Payload=42, got " + payload, payload.contains("42"));
} finally {
session.close();
}
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class StompWebSocketIntegrationTests method sendMessageToController.
@Test
public void sendMessageToController() throws Exception {
TextMessage message = create(StompCommand.SEND).headers("destination:/app/simple").build();
WebSocketSession session = doHandshake(new TestClientWebSocketHandler(0, message), "/ws").get();
SimpleController controller = this.wac.getBean(SimpleController.class);
try {
assertTrue(controller.latch.await(TIMEOUT, TimeUnit.SECONDS));
} finally {
session.close();
}
}
use of org.springframework.web.socket.TextMessage in project spring-framework by spring-projects.
the class StompWebSocketIntegrationTests method webSocketScope.
@Test
public void webSocketScope() throws Exception {
TextMessage message1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/scopedBeanValue").build();
TextMessage message2 = create(StompCommand.SEND).headers("destination:/app/scopedBeanValue").build();
TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(1, message1, message2);
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
try {
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
String payload = clientHandler.actual.get(0).getPayload();
assertTrue(payload.startsWith("MESSAGE\n"));
assertTrue(payload.contains("destination:/topic/scopedBeanValue\n"));
assertTrue(payload.endsWith("55\0"));
} finally {
session.close();
}
}
Aggregations