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