Examples of MessageChannel


Examples of org.springframework.integration.core.MessageChannel

        Message response = null;
        if (isExpectReply()) {
            //Check the message header for the return address
            response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
            if (replyChannel == null) {
                MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
                if (messageReplyChannel != null) {
                    result = messageReplyChannel.send(response);
                } else {
                    throw new MessageDeliveryException(response, "Can't find reply channel from the CamelTargetAdapter or MessageHeaders");
                }
            } else {
                result = replyChannel.send(response);
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

public class SpringIntegrationTwoWayConsumerTest extends SpringTestSupport {
    private static final String MESSAGE_BODY = "Request message";   

    public void testSendingTwoWayMessage() throws Exception {
       
        MessageChannel requestChannel = (MessageChannel) applicationContext.getBean("requestChannel");
        Map<String, Object> maps = new HashMap<String, Object>();
        maps.put(MessageHeaders.REPLY_CHANNEL, "responseChannel");
        Message<String> message = new GenericMessage<String>(MESSAGE_BODY, maps);
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("responseChannel");
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }            
        });
        requestChannel.send(message);       
       
    }
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

    private static final String MESSAGE_BODY = "hello world";

    public void testSendingOneWayMessage() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
        MessageChannel outputChannel = (MessageChannel) applicationContext.getBean("outputChannel");
        outputChannel.send(new StringMessage(MESSAGE_BODY));
        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

    private static final String MESSAGE_BODY = "hello world";

    public void testSendingOneWayMessage() throws Exception {
        MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
        resultEndpoint.expectedBodiesReceived(MESSAGE_BODY);
        MessageChannel outputChannel = (MessageChannel) applicationContext.getBean("channelA");
        outputChannel.send(new StringMessage(MESSAGE_BODY));
        resultEndpoint.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

        resultEndpoint.assertIsSatisfied();
    }

    public void testSendingTwoWayMessage() throws Exception {

        MessageChannel requestChannel = (MessageChannel) applicationContext.getBean("channelB");
        Message message = new StringMessage(MESSAGE_BODY);
        //Need to subscribe the responseChannel first
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("channelC");
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);
    }
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

        requestChannel.send(message);
    }

    public void testSendingTwoWayMessageWithMessageAddress() throws Exception {

        MessageChannel requestChannel = (MessageChannel) applicationContext.getBean("channelD");
        DirectChannel responseChannel = (DirectChannel) applicationContext.getBean("channelC");
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put(MessageHeaders.REPLY_CHANNEL, responseChannel);
        GenericMessage<String> message = new GenericMessage<String>(MESSAGE_BODY, headers);
        responseChannel.subscribe(new MessageHandler() {
            public void handleMessage(Message<?> message) {
                String result = (String) message.getPayload();
                assertEquals("Get the wrong result", MESSAGE_BODY + " is processed",  result);               
            }           
        });
        requestChannel.send(message);       
    }
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

        Message response = null;
        if (isExpectReply()) {
            //Check the message header for the return address
            response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
            if (replyChannel == null) {
                MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
                if (messageReplyChannel != null) {
                    result = messageReplyChannel.send(response);
                } else {
                    throw new MessageDeliveryException(response, "Can't find reply channel from the CamelTargetAdapter or MessageHeaders");
                }
            } else {
                result = replyChannel.send(response);
View Full Code Here

Examples of org.springframework.integration.core.MessageChannel

        Message response = null;
        if (isExpectReply()) {
            //Check the message header for the return address
            response = SpringIntegrationBinding.storeToSpringIntegrationMessage(outExchange.getOut());
            if (replyChannel == null) {
                MessageChannel messageReplyChannel = (MessageChannel) message.getHeaders().get(MessageHeaders.REPLY_CHANNEL);
                if (messageReplyChannel != null) {
                    result = messageReplyChannel.send(response);
                } else {
                    throw new MessageDeliveryException(response, "Can't find reply channel from the CamelTargetAdapter or MessageHeaders");
                }
            } else {
                result = replyChannel.send(response);
View Full Code Here

Examples of org.springframework.messaging.MessageChannel

   * Test method for {@link org.springframework.integration.samples.ftp.DynamicFtpChannelResolver#resolve(java.lang.String)}.
   */
  @Test
  public void testResolve() {
    DynamicFtpChannelResolver dynamicFtpChannelResolver = new DynamicFtpChannelResolver();
    MessageChannel channel1 = dynamicFtpChannelResolver.resolve("customer1");
    assertNotNull(channel1);
    MessageChannel channel2 = dynamicFtpChannelResolver.resolve("customer2");
    assertNotNull(channel2);
    assertNotSame(channel1, channel2);
    MessageChannel channel1a = dynamicFtpChannelResolver.resolve("customer1");
    assertSame(channel1, channel1a);
  }
View Full Code Here

Examples of org.springframework.messaging.MessageChannel

  @Test
  public void runDemo() throws Exception{
    ConfigurableApplicationContext ctx =
      new ClassPathXmlApplicationContext("META-INF/spring/integration/DynamicFtpOutboundChannelAdapterSample-context.xml");
    MessageChannel channel = ctx.getBean("toDynRouter", MessageChannel.class);
    File file = File.createTempFile("temp", "txt");
    Message<File> message = MessageBuilder.withPayload(file)
            .setHeader("customer", "cust1")
            .build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send another so we can see in the log we don't create the ac again.
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust1"));
    }
    // send to a different customer; again, check the log to see a new ac is built
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust2").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust2"));
    }

    // send to a different customer; again, check the log to see a new ac is built
    //and the first one created (cust1) should be closed and removed as per the max cache size restriction
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust3").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertTrue(e.getCause().getCause().getCause().getMessage().startsWith("host.for.cust3"));
    }

    //send to cust1 again, since this one has been invalidated before, we should
    //see a new ac created (with ac of cust2 destroyed and removed)
    message = MessageBuilder.withPayload(file)
        .setHeader("customer", "cust1").build();
    try {
      channel.send(message);
    }
    catch (MessagingException e) {
      assertThat(e.getCause().getCause().getCause(), instanceOf(UnknownHostException.class));
      assertEquals("host.for.cust1", e.getCause().getCause().getCause().getMessage());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.