Search in sources :

Example 21 with BeanFactoryChannelResolver

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

the class AbstractPollingEndpoint method onInit.

@Override
protected void onInit() {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        Assert.notNull(this.trigger, "Trigger is required");
        if (this.taskExecutor != null) {
            if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
                if (this.errorHandler == null) {
                    Assert.notNull(this.getBeanFactory(), "BeanFactory is required");
                    this.errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
                    this.errorHandlerIsDefault = true;
                }
                this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, this.errorHandler);
            }
        }
        if (this.transactionSynchronizationFactory == null && this.adviceChain != null) {
            if (this.adviceChain.stream().anyMatch(TransactionInterceptor.class::isInstance)) {
                this.transactionSynchronizationFactory = new PassThroughTransactionSynchronizationFactory();
            }
        }
        this.initialized = true;
    }
    try {
        super.onInit();
    } catch (Exception e) {
        throw new BeanInitializationException("Cannot initialize: " + this, e);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) TransactionInterceptor(org.springframework.transaction.interceptor.TransactionInterceptor) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) PassThroughTransactionSynchronizationFactory(org.springframework.integration.transaction.PassThroughTransactionSynchronizationFactory) MessagingException(org.springframework.messaging.MessagingException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 22 with BeanFactoryChannelResolver

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

the class UdpMulticastEndToEndTests method launchSender.

public void launchSender(ApplicationContext applicationContext) throws Exception {
    DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(applicationContext);
    MessageChannel inputChannel = channelResolver.resolveDestination("mcInputChannel");
    if (!readyToReceive.await(30, TimeUnit.SECONDS)) {
        fail("Receiver failed to start in 30s");
    }
    String testingIpText;
    try {
        testingIpText = ">>>>>>> Testing IP (multicast) " + new Date();
        inputChannel.send(new GenericMessage<String>(testingIpText));
        sentFirst.countDown();
        try {
            // give some time for console interaction
            Thread.sleep(hangAroundFor);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } catch (MessagingException e) {
        // no multicast this host
        e.printStackTrace();
        return;
    } finally {
        if (hangAroundFor == 0) {
            sentFirst = new CountDownLatch(1);
        } else {
            okToRun = false;
        }
        // tell the receiver to we're done
        doneProcessing.countDown();
    }
    assertTrue(firstReceived.await(2, TimeUnit.SECONDS));
    assertEquals(testingIpText, new String(finalMessage.getPayload()));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) MessagingException(org.springframework.messaging.MessagingException) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date)

Example 23 with BeanFactoryChannelResolver

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

the class RedisQueueMessageDrivenEndpoint method onInit.

@Override
protected void onInit() {
    super.onInit();
    if (this.expectMessage) {
        Assert.notNull(this.serializer, "'serializer' has to be provided where 'expectMessage == true'.");
    }
    if (this.taskExecutor == null) {
        String beanName = this.getComponentName();
        this.taskExecutor = new SimpleAsyncTaskExecutor((beanName == null ? "" : beanName + "-") + this.getComponentType());
    }
    if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
        MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
        errorHandler.setDefaultErrorChannel(this.errorChannel);
        this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
    }
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 24 with BeanFactoryChannelResolver

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

the class MailToStringTransformerParserTests method topLevelTransformer.

@Test
public void topLevelTransformer() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("mailToStringTransformerParserTests.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("hello");
    input.send(new GenericMessage<javax.mail.Message>(mimeMessage));
    Message<?> result = output.receive(0);
    assertNotNull(result);
    assertEquals("hello", 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 25 with BeanFactoryChannelResolver

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

the class SubscribableRedisChannel method onInit.

@Override
public void onInit() throws Exception {
    if (this.initialized) {
        return;
    }
    super.onInit();
    if (this.maxSubscribers == null) {
        Integer maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, Integer.class);
        this.setMaxSubscribers(maxSubscribers);
    }
    if (this.messageConverter == null) {
        this.messageConverter = new SimpleMessageConverter();
    }
    if (this.messageConverter instanceof BeanFactoryAware) {
        ((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
    }
    this.container.setConnectionFactory(this.connectionFactory);
    if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
        ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
        this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
    }
    this.container.setTaskExecutor(this.taskExecutor);
    MessageListenerAdapter adapter = new MessageListenerAdapter(new MessageListenerDelegate());
    adapter.setSerializer(this.serializer);
    adapter.afterPropertiesSet();
    this.container.addMessageListener(adapter, new ChannelTopic(this.topicName));
    this.container.afterPropertiesSet();
    this.dispatcher.setBeanFactory(this.getBeanFactory());
    this.initialized = true;
}
Also used : MessageListenerAdapter(org.springframework.data.redis.listener.adapter.MessageListenerAdapter) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) ErrorHandler(org.springframework.util.ErrorHandler) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) SimpleMessageConverter(org.springframework.integration.support.converter.SimpleMessageConverter) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

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