use of org.springframework.web.socket.WebSocketSession 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.WebSocketSession 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.WebSocketSession 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();
}
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class StompWebSocketIntegrationTests method sendMessageToBrokerAndReceiveReplyViaTopic.
// SPR-10930
@Test
public void sendMessageToBrokerAndReceiveReplyViaTopic() throws Exception {
TextMessage m1 = create(StompCommand.SUBSCRIBE).headers("id:subs1", "destination:/topic/foo").build();
TextMessage m2 = create(StompCommand.SEND).headers("destination:/topic/foo").body("5").build();
TestClientWebSocketHandler clientHandler = new TestClientWebSocketHandler(1, m1, m2);
WebSocketSession session = doHandshake(clientHandler, "/ws").get();
try {
assertTrue(clientHandler.latch.await(TIMEOUT, TimeUnit.SECONDS));
String payload = clientHandler.actual.get(0).getPayload();
assertTrue("Expected STOMP MESSAGE, got " + payload, payload.startsWith("MESSAGE\n"));
} finally {
session.close();
}
}
use of org.springframework.web.socket.WebSocketSession in project spring-framework by spring-projects.
the class StandardWebSocketClientTests method testGetLocalAddressWss.
@Test
public void testGetLocalAddressWss() throws Exception {
URI uri = new URI("wss://localhost/abc");
WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
assertNotNull(session.getLocalAddress());
assertEquals(443, session.getLocalAddress().getPort());
}
Aggregations