Example usage for org.springframework.messaging MessageHeaders getReplyChannel

List of usage examples for org.springframework.messaging MessageHeaders getReplyChannel

Introduction

In this page you can find the example usage for org.springframework.messaging MessageHeaders getReplyChannel.

Prototype

@Nullable
    public Object getReplyChannel() 

Source Link

Usage

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testHeaderEnricher() {
    QueueChannel replyChannel = new QueueChannel();

    Message<String> message = MessageBuilder
            .withPayload("<root><elementOne>1</elementOne><elementTwo>2</elementTwo></root>")
            .setReplyChannel(replyChannel).build();

    try {/*from   w  w  w . j av  a  2 s  .  c  om*/
        this.xpathHeaderEnricherInput.send(message);
        fail("Expected MessageDispatchingException");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessageDeliveryException.class));
        assertThat(e.getCause(), instanceOf(MessageDispatchingException.class));
        assertThat(e.getMessage(), containsString("Dispatcher has no subscribers"));
    }

    this.controlBus.send("@xpathHeaderEnricher.start()");
    this.xpathHeaderEnricherInput.send(message);

    Message<?> result = replyChannel.receive(2000);
    assertNotNull(result);
    MessageHeaders headers = result.getHeaders();
    assertEquals("1", headers.get("one"));
    assertEquals("2", headers.get("two"));
    assertThat(headers.getReplyChannel(), instanceOf(String.class));
}

From source file:org.springframework.integration.dsl.test.xml.XmlTests.java

@Test
public void testHeaderEnricher() {
    QueueChannel replyChannel = new QueueChannel();

    Message<String> message = MessageBuilder
            .withPayload("<root><elementOne>1</elementOne><elementTwo>2</elementTwo></root>")
            .setReplyChannel(replyChannel).build();

    try {//from  w  w  w .  ja  va 2  s .c o m
        this.xpathHeaderEnricherInput.send(message);
        fail("Expected MessageDispatchingException");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessageDeliveryException.class));
        assertThat(e.getCause(), instanceOf(MessageDispatchingException.class));
        assertThat(e.getMessage(), containsString("Dispatcher has no subscribers"));
    }

    this.controlBusFlowInput.send(new GenericMessage<>("@xpathHeaderEnricher.start()"));
    this.xpathHeaderEnricherInput.send(message);

    Message<?> result = replyChannel.receive(2000);
    assertNotNull(result);
    MessageHeaders headers = result.getHeaders();
    assertEquals("1", headers.get("one"));
    assertEquals("2", headers.get("two"));
    assertThat(headers.getReplyChannel(), instanceOf(String.class));
    assertFalse(headers.containsKey("foo"));
}