use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class IntegrationFlowBeanPostProcessor method processStandardIntegrationFlow.
private Object processStandardIntegrationFlow(StandardIntegrationFlow flow, String flowBeanName) {
String flowNamePrefix = flowBeanName + ".";
int subFlowNameIndex = 0;
int channelNameIndex = 0;
Map<Object, String> integrationComponents = flow.getIntegrationComponents();
Map<Object, String> targetIntegrationComponents = new LinkedHashMap<>(integrationComponents.size());
for (Map.Entry<Object, String> entry : integrationComponents.entrySet()) {
Object component = entry.getKey();
if (component instanceof ConsumerEndpointSpec) {
ConsumerEndpointSpec<?, ?> endpointSpec = (ConsumerEndpointSpec<?, ?>) component;
MessageHandler messageHandler = endpointSpec.get().getT2();
ConsumerEndpointFactoryBean endpoint = endpointSpec.get().getT1();
String id = endpointSpec.getId();
if (id == null) {
id = generateBeanName(endpoint, entry.getValue());
}
Collection<?> messageHandlers = this.beanFactory.getBeansOfType(messageHandler.getClass(), false, false).values();
if (!messageHandlers.contains(messageHandler)) {
String handlerBeanName = generateBeanName(messageHandler);
String[] handlerAlias = new String[] { id + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX };
registerComponent(messageHandler, handlerBeanName, flowBeanName);
for (String alias : handlerAlias) {
this.beanFactory.registerAlias(handlerBeanName, alias);
}
}
registerComponent(endpoint, id, flowBeanName);
targetIntegrationComponents.put(endpoint, id);
} else {
Collection<?> values = this.beanFactory.getBeansOfType(component.getClass(), false, false).values();
if (!values.contains(component)) {
if (component instanceof AbstractMessageChannel) {
String channelBeanName = ((AbstractMessageChannel) component).getComponentName();
if (channelBeanName == null) {
channelBeanName = entry.getValue();
if (channelBeanName == null) {
channelBeanName = flowNamePrefix + "channel" + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + channelNameIndex++;
}
}
registerComponent(component, channelBeanName, flowBeanName);
targetIntegrationComponents.put(component, channelBeanName);
} else if (component instanceof MessageChannelReference) {
String channelBeanName = ((MessageChannelReference) component).getName();
if (!this.beanFactory.containsBean(channelBeanName)) {
DirectChannel directChannel = new DirectChannel();
registerComponent(directChannel, channelBeanName, flowBeanName);
targetIntegrationComponents.put(directChannel, channelBeanName);
}
} else if (component instanceof FixedSubscriberChannel) {
FixedSubscriberChannel fixedSubscriberChannel = (FixedSubscriberChannel) component;
String channelBeanName = fixedSubscriberChannel.getComponentName();
if ("Unnamed fixed subscriber channel".equals(channelBeanName)) {
channelBeanName = flowNamePrefix + "channel" + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + channelNameIndex++;
}
registerComponent(component, channelBeanName, flowBeanName);
targetIntegrationComponents.put(component, channelBeanName);
} else if (component instanceof SourcePollingChannelAdapterSpec) {
SourcePollingChannelAdapterSpec spec = (SourcePollingChannelAdapterSpec) component;
Map<Object, String> componentsToRegister = spec.getComponentsToRegister();
if (!CollectionUtils.isEmpty(componentsToRegister)) {
componentsToRegister.entrySet().stream().filter(o -> !this.beanFactory.getBeansOfType(o.getKey().getClass(), false, false).values().contains(o.getKey())).forEach(o -> registerComponent(o.getKey(), generateBeanName(o.getKey(), o.getValue())));
}
SourcePollingChannelAdapterFactoryBean pollingChannelAdapterFactoryBean = spec.get().getT1();
String id = spec.getId();
if (!StringUtils.hasText(id)) {
id = generateBeanName(pollingChannelAdapterFactoryBean, entry.getValue());
}
registerComponent(pollingChannelAdapterFactoryBean, id, flowBeanName);
targetIntegrationComponents.put(pollingChannelAdapterFactoryBean, id);
MessageSource<?> messageSource = spec.get().getT2();
if (!this.beanFactory.getBeansOfType(messageSource.getClass(), false, false).values().contains(messageSource)) {
String messageSourceId = id + ".source";
if (messageSource instanceof NamedComponent && ((NamedComponent) messageSource).getComponentName() != null) {
messageSourceId = ((NamedComponent) messageSource).getComponentName();
}
registerComponent(messageSource, messageSourceId, flowBeanName);
}
} else if (component instanceof StandardIntegrationFlow) {
String subFlowBeanName = entry.getValue() != null ? entry.getValue() : flowNamePrefix + "subFlow" + BeanFactoryUtils.GENERATED_BEAN_NAME_SEPARATOR + subFlowNameIndex++;
registerComponent(component, subFlowBeanName, flowBeanName);
targetIntegrationComponents.put(component, subFlowBeanName);
} else if (component instanceof AnnotationGatewayProxyFactoryBean) {
AnnotationGatewayProxyFactoryBean gateway = (AnnotationGatewayProxyFactoryBean) component;
String gatewayId = entry.getValue();
if (gatewayId == null) {
gatewayId = gateway.getComponentName();
}
if (gatewayId == null) {
gatewayId = flowNamePrefix + "gateway";
}
registerComponent(gateway, gatewayId, flowBeanName, beanDefinition -> {
((AbstractBeanDefinition) beanDefinition).setSource(new DescriptiveResource(gateway.getObjectType().getName()));
});
targetIntegrationComponents.put(component, gatewayId);
} else {
String generatedBeanName = generateBeanName(component, entry.getValue());
registerComponent(component, generatedBeanName, flowBeanName);
targetIntegrationComponents.put(component, generatedBeanName);
}
} else {
targetIntegrationComponents.put(entry.getKey(), entry.getValue());
}
}
}
flow.setIntegrationComponents(targetIntegrationComponents);
return flow;
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class FileInboundChannelAdapterWithPatternParserTests method channelName.
@Test
public void channelName() {
AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class);
assertEquals("adapterWithPattern", channel.getComponentName());
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParserWithMaxResultsExpression.
@Test
public void testJpaInboundChannelAdapterParserWithMaxResultsExpression() throws Exception {
AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "outputChannel", AbstractMessageChannel.class);
assertEquals("out", outputChannel.getComponentName());
JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter3, "source.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
SpelExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", SpelExpression.class);
assertNotNull(expression);
assertEquals("@maxNumberOfResults", TestUtils.getPropertyValue(expression, "expression"));
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class JpaInboundChannelAdapterParserTests method testJpaInboundChannelAdapterParserWithMaxResults.
@Test
public void testJpaInboundChannelAdapterParserWithMaxResults() throws Exception {
AbstractMessageChannel outputChannel = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "outputChannel", AbstractMessageChannel.class);
assertEquals("out", outputChannel.getComponentName());
JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.jpaInboundChannelAdapter2, "source.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
LiteralExpression expression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class);
assertNotNull(expression);
assertEquals("13", TestUtils.getPropertyValue(expression, "literalValue"));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class));
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class JpaOutboundGatewayParserTests method testRetrievingJpaOutboundGatewayParser.
@Test
public void testRetrievingJpaOutboundGatewayParser() throws Exception {
setUp("JpaOutboundGatewayParserTests.xml", getClass(), "retrievingJpaOutboundGateway");
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(this.consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("in", inputChannel.getComponentName());
final JpaOutboundGateway jpaOutboundGateway = TestUtils.getPropertyValue(this.consumer, "handler", JpaOutboundGateway.class);
final OutboundGatewayType gatewayType = TestUtils.getPropertyValue(jpaOutboundGateway, "gatewayType", OutboundGatewayType.class);
assertEquals(OutboundGatewayType.RETRIEVING, gatewayType);
long sendTimeout = TestUtils.getPropertyValue(jpaOutboundGateway, "messagingTemplate.sendTimeout", Long.class);
assertEquals(100, sendTimeout);
assertFalse(TestUtils.getPropertyValue(jpaOutboundGateway, "requiresReply", Boolean.class));
final JpaExecutor jpaExecutor = TestUtils.getPropertyValue(this.consumer, "handler.jpaExecutor", JpaExecutor.class);
assertNotNull(jpaExecutor);
final Class<?> entityClass = TestUtils.getPropertyValue(jpaExecutor, "entityClass", Class.class);
assertEquals("org.springframework.integration.jpa.test.entity.StudentDomain", entityClass.getName());
final JpaOperations jpaOperations = TestUtils.getPropertyValue(jpaExecutor, "jpaOperations", JpaOperations.class);
assertNotNull(jpaOperations);
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "expectSingleResult", Boolean.class));
final LiteralExpression maxResultsExpression = TestUtils.getPropertyValue(jpaExecutor, "maxResultsExpression", LiteralExpression.class);
assertNotNull(maxResultsExpression);
assertEquals("55", TestUtils.getPropertyValue(maxResultsExpression, "literalValue"));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "deleteAfterPoll", Boolean.class));
assertTrue(TestUtils.getPropertyValue(jpaExecutor, "flush", Boolean.class));
}
Aggregations