Search in sources :

Example 11 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class MailToStringTransformerParserTests method transformerWithinChain.

@Test
public void transformerWithinChain() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("mailToStringTransformerWithinChain.xml", this.getClass());
    MessageChannel input = new BeanFactoryChannelResolver(context).resolveDestination("input");
    PollableChannel output = (PollableChannel) new BeanFactoryChannelResolver(context).resolveDestination("output");
    MimeMessage mimeMessage = Mockito.mock(MimeMessage.class);
    Mockito.when(mimeMessage.getContent()).thenReturn("foo");
    input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
    Message<?> result = output.receive(0);
    assertNotNull(result);
    assertEquals("FOO!!!", result.getPayload());
    Mockito.verify(mimeMessage).getContent();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) MimeMessage(javax.mail.internet.MimeMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MimeMessage(javax.mail.internet.MimeMessage) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Test(org.junit.Test)

Example 12 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration-samples by spring-projects.

the class WebServiceDemoTestApp method main.

public static void main(String[] args) {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/temperatureConversion.xml");
    DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(context);
    // Compose the XML message according to the server's schema
    String requestXml = "<FahrenheitToCelsius xmlns=\"http://www.w3schools.com/xml/\">" + "<Fahrenheit>90.0</Fahrenheit>" + "</FahrenheitToCelsius>";
    // Create the Message object
    Message<String> message = MessageBuilder.withPayload(requestXml).build();
    // Send the Message to the handler's input channel
    MessageChannel channel = channelResolver.resolveDestination("fahrenheitChannel");
    channel.send(message);
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver)

Example 13 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method outboundOnlyServiceActivator.

@Test
public void outboundOnlyServiceActivator() throws InterruptedException {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    context.registerChannel("testChannel", new DirectChannel());
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    CountDownLatch latch = new CountDownLatch(1);
    OutboundOnlyTestBean testBean = new OutboundOnlyTestBean(latch);
    postProcessor.postProcessAfterInitialization(testBean, "testBean");
    context.refresh();
    DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(context);
    MessageChannel testChannel = channelResolver.resolveDestination("testChannel");
    testChannel.send(new GenericMessage<String>("foo"));
    latch.await(1000, TimeUnit.MILLISECONDS);
    assertEquals(0, latch.getCount());
    assertEquals("foo", testBean.getMessageText());
    context.stop();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) CountDownLatch(java.util.concurrent.CountDownLatch) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 14 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class ExecutorChannel method onInit.

@Override
public final void onInit() throws Exception {
    Assert.state(getDispatcher().getHandlerCount() == 0, "You cannot subscribe() until the channel " + "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
    super.onInit();
    if (!(this.executor instanceof ErrorHandlingTaskExecutor)) {
        ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
        this.executor = new ErrorHandlingTaskExecutor(this.executor, errorHandler);
    }
    UnicastingDispatcher unicastingDispatcher = new UnicastingDispatcher(this.executor);
    unicastingDispatcher.setFailover(this.failover);
    if (this.maxSubscribers == null) {
        this.maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_UNICAST_SUBSCRIBERS, Integer.class);
    }
    unicastingDispatcher.setMaxSubscribers(this.maxSubscribers);
    if (this.loadBalancingStrategy != null) {
        unicastingDispatcher.setLoadBalancingStrategy(this.loadBalancingStrategy);
    }
    unicastingDispatcher.setMessageHandlingTaskDecorator(task -> {
        if (ExecutorChannel.this.executorInterceptorsSize > 0) {
            return new MessageHandlingTask(task);
        } else {
            return task;
        }
    });
    this.dispatcher = unicastingDispatcher;
}
Also used : ErrorHandler(org.springframework.util.ErrorHandler) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) UnicastingDispatcher(org.springframework.integration.dispatcher.UnicastingDispatcher) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 15 with BeanFactoryChannelResolver

use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.

the class PublishSubscribeChannel method onInit.

/**
 * Callback method for initialization.
 * @throws Exception the exception.
 */
@Override
public final void onInit() throws Exception {
    super.onInit();
    if (this.executor != null) {
        Assert.state(getDispatcher().getHandlerCount() == 0, "When providing an Executor, you cannot subscribe() until the channel " + "bean is fully initialized by the framework. Do not subscribe in a @Bean definition");
        if (!(this.executor instanceof ErrorHandlingTaskExecutor)) {
            if (this.errorHandler == null) {
                this.errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
            }
            this.executor = new ErrorHandlingTaskExecutor(this.executor, this.errorHandler);
        }
        this.dispatcher = new BroadcastingDispatcher(this.executor);
        getDispatcher().setIgnoreFailures(this.ignoreFailures);
        getDispatcher().setApplySequence(this.applySequence);
        getDispatcher().setMinSubscribers(this.minSubscribers);
    }
    if (this.maxSubscribers == null) {
        Integer maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, Integer.class);
        this.setMaxSubscribers(maxSubscribers);
    }
    getDispatcher().setBeanFactory(this.getBeanFactory());
    getDispatcher().setMessageHandlingTaskDecorator(task -> {
        if (PublishSubscribeChannel.this.executorInterceptorsSize > 0) {
            return new MessageHandlingTask(task);
        } else {
            return task;
        }
    });
}
Also used : BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher)

Aggregations

BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)25 Test (org.junit.Test)11 MessageChannel (org.springframework.messaging.MessageChannel)7 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 MessagePublishingErrorHandler (org.springframework.integration.channel.MessagePublishingErrorHandler)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 DirectChannel (org.springframework.integration.channel.DirectChannel)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 DestinationResolutionException (org.springframework.messaging.core.DestinationResolutionException)3 Date (java.util.Date)2 MimeMessage (javax.mail.internet.MimeMessage)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)2 Message (org.springframework.messaging.Message)2 MessagingException (org.springframework.messaging.MessagingException)2 PollableChannel (org.springframework.messaging.PollableChannel)2