use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-integration by spring-projects.
the class StompSessionManagerTests method testDoConnectFailure.
@Test
public void testDoConnectFailure() throws Exception {
StompClientSupport stompClient = mock(StompClientSupport.class);
stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
AbstractStompSessionManager sessionManager = new AbstractStompSessionManager(stompClient) {
private final AtomicBoolean thrown = new AtomicBoolean();
@Override
protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
if (!this.thrown.getAndSet(true)) {
throw new RuntimeException("intentional");
} else {
SettableListenableFuture<StompSession> future = new SettableListenableFuture<StompSession>();
StompSession stompSession = mock(StompSession.class);
future.set(stompSession);
handler.afterConnected(stompSession, getConnectHeaders());
return future;
}
}
};
sessionManager.start();
final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
sessionManager.connect(new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
stompSessionFuture.set(session);
}
});
assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
sessionManager.stop();
}
use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-framework by spring-projects.
the class WebSocketStompClientTests method heartbeatDefaultValueWithScheduler.
@Test
public void heartbeatDefaultValueWithScheduler() throws Exception {
WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
stompClient.setTaskScheduler(mock(TaskScheduler.class));
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] { 10000, 10000 });
StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
assertThat(connectHeaders.getHeartbeat()).isEqualTo(new long[] { 10000, 10000 });
}
use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-framework by spring-projects.
the class WebSocketStompClientTests method heartbeatDefaultValue.
@Test
public void heartbeatDefaultValue() throws Exception {
WebSocketStompClient stompClient = new WebSocketStompClient(mock(WebSocketClient.class));
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] { 0, 0 });
StompHeaders connectHeaders = stompClient.processConnectHeaders(null);
assertThat(connectHeaders.getHeartbeat()).isEqualTo(new long[] { 0, 0 });
}
use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-framework by spring-projects.
the class WebSocketStompClientTests method handleWebSocketMessageSplitAcrossTwoMessage.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void handleWebSocketMessageSplitAcrossTwoMessage() throws Exception {
WebSocketHandler webSocketHandler = connect();
String part1 = "SEND\na:alpha\n\nMessage";
webSocketHandler.handleMessage(this.webSocketSession, new TextMessage(part1));
verifyNoMoreInteractions(this.stompSession);
String part2 = " payload\0";
webSocketHandler.handleMessage(this.webSocketSession, new TextMessage(part2));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
verify(this.stompSession).handleMessage(captor.capture());
Message<byte[]> message = captor.getValue();
assertThat(message).isNotNull();
StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
StompHeaders headers = StompHeaders.readOnlyStompHeaders(accessor.toNativeHeaderMap());
assertThat(accessor.getCommand()).isEqualTo(StompCommand.SEND);
assertThat(headers.getFirst("a")).isEqualTo("alpha");
assertThat(new String(message.getPayload(), StandardCharsets.UTF_8)).isEqualTo("Message payload");
}
use of org.springframework.messaging.simp.stomp.StompHeaders in project spring-boot by spring-projects.
the class WebSocketMessagingAutoConfigurationTests method performStompSubscription.
private Object performStompSubscription(String topic) throws Throwable {
TestPropertyValues.of("server.port:0", "spring.jackson.serialization.indent-output:true").applyTo(this.context);
this.context.register(WebSocketMessagingConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
WebSocketStompClient stompClient = new WebSocketStompClient(this.sockJsClient);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final AtomicReference<Object> result = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
StompSessionHandler handler = new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
session.subscribe(topic, new StompFrameHandler() {
@Override
public void handleFrame(StompHeaders headers, Object payload) {
result.set(payload);
latch.countDown();
}
@Override
public Type getPayloadType(StompHeaders headers) {
return Object.class;
}
});
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
latch.countDown();
}
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
failure.set(exception);
latch.countDown();
}
@Override
public void handleTransportError(StompSession session, Throwable exception) {
failure.set(exception);
latch.countDown();
}
};
stompClient.setMessageConverter(new SimpleMessageConverter());
stompClient.connect("ws://localhost:{port}/messaging", handler, this.context.getEnvironment().getProperty("local.server.port"));
if (!latch.await(30, TimeUnit.SECONDS)) {
if (failure.get() != null) {
throw failure.get();
}
fail("Response was not received within 30 seconds");
}
return result.get();
}
Aggregations