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);
}
}
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()));
}
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);
}
}
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();
}
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;
}
Aggregations