Search in sources :

Example 1 with StompExceptionEvent

use of org.springframework.integration.stomp.event.StompExceptionEvent in project spring-integration by spring-projects.

the class StompMessageHandlerWebSocketIntegrationTests method testStompMessageHandler.

@Test
public void testStompMessageHandler() throws InterruptedException {
    StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setDestination("/app/simple");
    Message<String> message = MessageBuilder.withPayload("foo").setHeaders(headers).build();
    this.webSocketOutputChannel.send(message);
    SimpleController controller = this.serverContext.getBean(SimpleController.class);
    assertTrue(controller.latch.await(10, TimeUnit.SECONDS));
    Message<?> receive = this.stompEvents.receive(10000);
    assertNotNull(receive);
    assertThat(receive.getPayload(), instanceOf(StompSessionConnectedEvent.class));
    // Simple Broker Relay doesn't support RECEIPT Frame, so we check here the 'lost' StompReceiptEvent
    receive = this.stompEvents.receive(10000);
    assertNotNull(receive);
    assertThat(receive.getPayload(), instanceOf(StompReceiptEvent.class));
    StompReceiptEvent stompReceiptEvent = (StompReceiptEvent) receive.getPayload();
    assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
    assertEquals("/app/simple", stompReceiptEvent.getDestination());
    assertTrue(stompReceiptEvent.isLost());
    assertNotNull(stompReceiptEvent.getMessage());
    headers = StompHeaderAccessor.create(StompCommand.SEND);
    headers.setDestination("/foo");
    message = MessageBuilder.withPayload("bar").setHeaders(headers).build();
    this.webSocketOutputChannel.send(message);
    receive = this.stompEvents.receive(10000);
    assertNotNull(receive);
    assertThat(receive.getPayload(), instanceOf(StompExceptionEvent.class));
    StompExceptionEvent stompExceptionEvent = (StompExceptionEvent) receive.getPayload();
    Throwable cause = stompExceptionEvent.getCause();
    assertThat(cause, instanceOf(MessageDeliveryException.class));
    MessageDeliveryException messageDeliveryException = (MessageDeliveryException) cause;
    Message<?> failedMessage = messageDeliveryException.getFailedMessage();
    assertThat((String) failedMessage.getPayload(), containsString("preSend intentional Exception"));
    receive = this.stompEvents.receive(10000);
    assertNotNull(receive);
    assertThat(receive.getPayload(), instanceOf(StompReceiptEvent.class));
    stompReceiptEvent = (StompReceiptEvent) receive.getPayload();
    assertEquals(StompCommand.SEND, stompReceiptEvent.getStompCommand());
    assertEquals("/foo", stompReceiptEvent.getDestination());
    assertTrue(stompReceiptEvent.isLost());
}
Also used : StompReceiptEvent(org.springframework.integration.stomp.event.StompReceiptEvent) StompExceptionEvent(org.springframework.integration.stomp.event.StompExceptionEvent) StompHeaderAccessor(org.springframework.messaging.simp.stomp.StompHeaderAccessor) Matchers.containsString(org.hamcrest.Matchers.containsString) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) StompSessionConnectedEvent(org.springframework.integration.stomp.event.StompSessionConnectedEvent) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Aggregations

Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 StompExceptionEvent (org.springframework.integration.stomp.event.StompExceptionEvent)1 StompReceiptEvent (org.springframework.integration.stomp.event.StompReceiptEvent)1 StompSessionConnectedEvent (org.springframework.integration.stomp.event.StompSessionConnectedEvent)1 LongRunningIntegrationTest (org.springframework.integration.test.support.LongRunningIntegrationTest)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1 StompHeaderAccessor (org.springframework.messaging.simp.stomp.StompHeaderAccessor)1