use of org.springframework.integration.support.context.NamedComponent in project spring-integration by spring-projects.
the class RouterSpec method channelMapping.
/**
* @param key the key.
* @param channelName the channelName.
* @return the router spec.
* @see AbstractMappingMessageRouter#setChannelMapping(String, String)
*/
public RouterSpec<K, R> channelMapping(K key, final String channelName) {
Assert.notNull(key, "'key' must not be null");
Assert.hasText(channelName, "'channelName' must not be null");
if (key instanceof String) {
this.handler.setChannelMapping((String) key, channelName);
} else {
this.mappingProvider.addMapping(key, new NamedComponent() {
@Override
public String getComponentName() {
return channelName;
}
@Override
public String getComponentType() {
return "channel";
}
});
}
return _this();
}
use of org.springframework.integration.support.context.NamedComponent in project spring-integration by spring-projects.
the class AmqpOutboundChannelAdapterParserTests method verifyIdAsChannel.
@Test
public void verifyIdAsChannel() {
Object channel = context.getBean("rabbitOutbound");
Object adapter = context.getBean("rabbitOutbound.adapter");
assertEquals(DirectChannel.class, channel.getClass());
assertEquals(EventDrivenConsumer.class, adapter.getClass());
MessageHandler handler = TestUtils.getPropertyValue(adapter, "handler", MessageHandler.class);
assertTrue(handler instanceof NamedComponent);
assertEquals("amqp:outbound-channel-adapter", ((NamedComponent) handler).getComponentType());
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertTrue(TestUtils.getPropertyValue(handler, "lazyConnect", Boolean.class));
}
use of org.springframework.integration.support.context.NamedComponent in project spring-integration by spring-projects.
the class AbstractSimpleMessageHandlerFactoryBean method createHandlerInternal.
protected final H createHandlerInternal() {
synchronized (this.initializationMonitor) {
if (this.initialized) {
// There was a problem when this method was called already
return null;
}
this.handler = createHandler();
if (this.handler instanceof ApplicationContextAware && this.applicationContext != null) {
((ApplicationContextAware) this.handler).setApplicationContext(this.applicationContext);
}
if (this.handler instanceof BeanFactoryAware && getBeanFactory() != null) {
((BeanFactoryAware) this.handler).setBeanFactory(getBeanFactory());
}
if (this.handler instanceof BeanNameAware && this.beanName != null) {
((BeanNameAware) this.handler).setBeanName(this.beanName);
}
if (this.handler instanceof ApplicationEventPublisherAware && this.applicationEventPublisher != null) {
((ApplicationEventPublisherAware) this.handler).setApplicationEventPublisher(this.applicationEventPublisher);
}
if (this.handler instanceof MessageProducer && this.outputChannel != null) {
((MessageProducer) this.handler).setOutputChannel(this.outputChannel);
}
Object actualHandler = extractTarget(this.handler);
if (actualHandler == null) {
actualHandler = this.handler;
}
if (actualHandler instanceof IntegrationObjectSupport) {
if (this.componentName != null) {
((IntegrationObjectSupport) actualHandler).setComponentName(this.componentName);
}
if (this.channelResolver != null) {
((IntegrationObjectSupport) actualHandler).setChannelResolver(this.channelResolver);
}
}
if (!CollectionUtils.isEmpty(this.adviceChain)) {
if (actualHandler instanceof AbstractReplyProducingMessageHandler) {
((AbstractReplyProducingMessageHandler) actualHandler).setAdviceChain(this.adviceChain);
} else if (this.logger.isDebugEnabled()) {
String name = this.componentName;
if (name == null && actualHandler instanceof NamedComponent) {
name = ((NamedComponent) actualHandler).getComponentName();
}
this.logger.debug("adviceChain can only be set on an AbstractReplyProducingMessageHandler" + (name == null ? "" : (", " + name)) + ".");
}
}
if (this.async != null) {
if (actualHandler instanceof AbstractMessageProducingHandler) {
((AbstractMessageProducingHandler) actualHandler).setAsync(this.async);
}
}
if (this.handler instanceof Orderable && this.order != null) {
((Orderable) this.handler).setOrder(this.order);
}
this.initialized = true;
}
if (this.handler instanceof InitializingBean) {
try {
((InitializingBean) this.handler).afterPropertiesSet();
} catch (Exception e) {
throw new BeanInitializationException("failed to initialize MessageHandler", e);
}
}
return this.handler;
}
use of org.springframework.integration.support.context.NamedComponent in project spring-integration by spring-projects.
the class BeanFactoryTypeConverterTests method testMessageHistoryNotConverted.
@Test
public void testMessageHistoryNotConverted() {
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
typeConverter.setBeanFactory(new DefaultListableBeanFactory());
Message<String> message = new GenericMessage<String>("foo");
message = MessageHistory.write(message, new NamedComponent() {
@Override
public String getComponentName() {
return "bar";
}
@Override
public String getComponentType() {
return "baz";
}
});
MessageHistory history = MessageHistory.read(message);
assertSame(history, typeConverter.convertValue(history, TypeDescriptor.valueOf(MessageHistory.class), TypeDescriptor.valueOf(MessageHistory.class)));
}
use of org.springframework.integration.support.context.NamedComponent in project spring-integration by spring-projects.
the class IntegrationMBeanExporter method registerChannels.
private void registerChannels() {
for (MessageChannelMetrics monitor : this.channels) {
String name = ((NamedComponent) monitor).getComponentName();
this.allChannelsByName.put(name, monitor);
if (!matches(this.componentNamePatterns, name)) {
continue;
}
String beanKey = getChannelBeanKey(name);
if (logger.isInfoEnabled()) {
logger.info("Registering MessageChannel " + name);
}
registerBeanNameOrInstance(monitor, beanKey);
}
}
Aggregations