Simplified configuration and updated README

This commit is contained in:
David Turanski
2011-07-16 16:48:26 -04:00
parent d43f225c31
commit 9c6c4d30ad
15 changed files with 638 additions and 420 deletions

View File

@@ -19,54 +19,69 @@
package org.springframework.integration.flow;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ChannelNamePortConfiguration implements PortConfiguration {
private PortMetadata inputPortMetadata;
private List<PortMetadata> outputPortMetadataList;
private PortMetadata inputPortMetadata;
private List<PortMetadata> outputPortMetadataList;
public ChannelNamePortConfiguration(PortMetadata inputPortMetadata, List<PortMetadata> outputPortMetadataList) {
this.outputPortMetadataList = outputPortMetadataList;
this.inputPortMetadata = inputPortMetadata;
}
public ChannelNamePortConfiguration(PortMetadata inputPortMetadata, List<PortMetadata> outputPortMetadataList) {
this.outputPortMetadataList = outputPortMetadataList;
this.inputPortMetadata = inputPortMetadata;
}
@Override
public String getInputPortName() {
return this.inputPortMetadata.getPortName();
}
public ChannelNamePortConfiguration(String inputChannelName, String outputChannelName) {
this.inputPortMetadata = new PortMetadata("input", inputChannelName);
@Override
public String getInputChannel() {
return this.inputPortMetadata.getChannelName();
}
@Override
public String getOutputChannel(String portName) {
PortMetadata portMetadata = (PortMetadata) find(portName);
if (portMetadata != null) {
return portMetadata.getChannelName();
}
return null;
}
@Override
public List<String> getOutputPortNames() {
List<String> results = new ArrayList<String>();
for (PortMetadata portMetadata : outputPortMetadataList ) {
results.add(portMetadata.getPortName());
}
return results;
}
public PortMetadata find(String portName){
for (PortMetadata portMetadata : outputPortMetadataList ) {
if (portName.equals(portMetadata.getPortName())){
return portMetadata;
}
if (outputChannelName != null) {
PortMetadata outputPortMetadata = new PortMetadata("output", outputChannelName);
this.outputPortMetadataList = Collections.singletonList(outputPortMetadata);
} else {
// this.outputPortMetadataList = new ArrayList<PortMetadata>();
}
return null;
}
}
@Override
public String getInputPortName() {
return this.inputPortMetadata.getPortName();
}
@Override
public String getInputChannel() {
return this.inputPortMetadata.getChannelName();
}
@Override
public String getOutputChannel(String portName) {
PortMetadata portMetadata = (PortMetadata) findOutputPort(portName);
if (portMetadata != null) {
return portMetadata.getChannelName();
}
return null;
}
@Override
public List<String> getOutputPortNames() {
List<String> results = new ArrayList<String>();
if (outputPortMetadataList != null) {
for (PortMetadata portMetadata : outputPortMetadataList) {
results.add(portMetadata.getPortName());
}
}
return results;
}
private PortMetadata findOutputPort(String portName) {
if (outputPortMetadataList != null) {
for (PortMetadata portMetadata : outputPortMetadataList) {
if (portName.equals(portMetadata.getPortName())) {
return portMetadata;
}
}
}
return null;
}
}

View File

@@ -34,164 +34,171 @@ import org.springframework.util.StringUtils;
*/
public class Flow implements InitializingBean, BeanNameAware, ChannelResolver, ApplicationContextAware {
private static Log logger = LogFactory.getLog(Flow.class);
private static Log logger = LogFactory.getLog(Flow.class);
private volatile ClassPathXmlApplicationContext flowContext;
private ApplicationContext applicationContext;
private volatile ClassPathXmlApplicationContext flowContext;
private volatile FlowConfiguration flowConfiguration;
private ApplicationContext applicationContext;
private volatile String[] configLocations;
private volatile FlowConfiguration flowConfiguration;
private volatile String[] referencedBeanLocations;
private volatile String[] configLocations;
private volatile Properties flowProperties;
private volatile String[] referencedBeanLocations;
private volatile String beanName;
private volatile String flowId;
private volatile Properties flowProperties;
private volatile ChannelResolver flowChannelResolver;
private volatile String beanName;
private volatile PublishSubscribeChannel flowOutputChannel;
private volatile String flowId;
private volatile boolean help;
private volatile ChannelResolver flowChannelResolver;
public Flow() {
private volatile PublishSubscribeChannel flowOutputChannel;
}
private volatile boolean help;
public Flow(String[] configLocations) {
this.configLocations = configLocations;
}
public Flow() {
@Override
public void afterPropertiesSet() {
if (this.flowId == null){
this.flowId = this.beanName;
}
if (this.help) {
}
public Flow(Properties flowProperties, String[] configLocations) {
this.flowProperties = flowProperties;
this.configLocations = configLocations;
}
public Flow(String[] configLocations) {
this.configLocations = configLocations;
}
@Override
public void afterPropertiesSet() {
if (this.flowId == null) {
this.flowId = this.beanName;
}
if (this.help) {
System.out.println(FlowUtils.getDocumentation(this.flowId));
}
if (configLocations == null) {
configLocations = new String[] { String.format(
"classpath:META-INF/spring/integration/flows/%s/*.xml", this.flowId) };
}
if (configLocations == null) {
configLocations = new String[] { String.format("classpath:META-INF/spring/integration/flows/%s/*.xml",
this.flowId) };
}
if (referencedBeanLocations != null) {
configLocations = (String[]) ArrayUtils.addAll(configLocations, referencedBeanLocations);
}
if (referencedBeanLocations != null) {
configLocations = (String[]) ArrayUtils.addAll(configLocations, referencedBeanLocations);
}
logger.debug("instantiating flow context from configLocations ["
+ StringUtils.arrayToCommaDelimitedString(configLocations) + "]");
logger.debug("instantiating flow context from configLocations ["
+ StringUtils.arrayToCommaDelimitedString(configLocations) + "]");
Assert.notEmpty(configLocations, "configLocations cannot be empty");
Assert.notEmpty(configLocations, "configLocations cannot be empty");
flowContext = new ClassPathXmlApplicationContext(applicationContext);
flowContext = new ClassPathXmlApplicationContext(applicationContext);
addReferencedProperties();
addReferencedProperties();
this.flowContext.setConfigLocations(configLocations);
this.flowContext.refresh();
this.flowContext.refresh();
this.flowConfiguration = flowContext.getBean(FlowConfiguration.class);
Assert.notNull(flowConfiguration, "flow context does not contain a flow configuration");
Assert.notNull(flowConfiguration, "flow context does not contain a flow configuration");
validatePortMapping();
validatePortMapping();
this.flowChannelResolver = new BeanFactoryChannelResolver(flowContext);
bridgeMessagingPorts();
this.flowChannelResolver = new BeanFactoryChannelResolver(flowContext);
}
bridgeMessagingPorts();
public FlowConfiguration getFlowConfiguration() {
return this.flowConfiguration;
}
}
@Override
public void setBeanName(String name) {
this.beanName = name;
public FlowConfiguration getFlowConfiguration() {
return this.flowConfiguration;
}
}
@Override
public void setBeanName(String name) {
this.beanName = name;
public String getBeanName() {
return this.beanName;
}
}
public void setFlowId(String flowId) {
public String getBeanName() {
return this.beanName;
}
public void setFlowId(String flowId) {
this.flowId = flowId;
}
public void setReferencedBeanLocations(String[] referencedBeanLocations) {
this.referencedBeanLocations = referencedBeanLocations;
}
this.referencedBeanLocations = referencedBeanLocations;
}
public void setProperties(Properties flowProperties) {
this.flowProperties = flowProperties;
}
public void setProperties(Properties flowProperties) {
this.flowProperties = flowProperties;
}
public Properties getProperties() {
return this.flowProperties;
}
public void setHelp(boolean help) {
this.help = help;
}
public void setHelp(boolean help) {
this.help = help;
}
public PublishSubscribeChannel getFlowOutputChannel() {
return flowOutputChannel;
}
public PublishSubscribeChannel getFlowOutputChannel() {
return flowOutputChannel;
}
public void setFlowOutputChannel(PublishSubscribeChannel flowOutputChannel) {
this.flowOutputChannel = flowOutputChannel;
}
public void setFlowOutputChannel(PublishSubscribeChannel flowOutputChannel) {
this.flowOutputChannel = flowOutputChannel;
}
@Override
public MessageChannel resolveChannelName(String channelName) {
return flowChannelResolver.resolveChannelName(channelName);
}
@Override
public MessageChannel resolveChannelName(String channelName) {
return flowChannelResolver.resolveChannelName(channelName);
}
private void addReferencedProperties() {
if (flowProperties != null) {
PropertySource<?> propertySource = new PropertiesPropertySource("flowProperties", flowProperties);
private void addReferencedProperties() {
if (flowProperties != null) {
PropertySource<?> propertySource = new PropertiesPropertySource("flowProperties", flowProperties);
MutablePropertySources propertySources = flowContext.getEnvironment().getPropertySources();
propertySources.addLast(propertySource);
}
MutablePropertySources propertySources = flowContext.getEnvironment().getPropertySources();
propertySources.addLast(propertySource);
}
}
}
private void validatePortMapping() {
Assert.notEmpty(this.flowConfiguration.getPortConfigurations(),
"flow configuration contains no port configurations");
}
private void validatePortMapping() {
Assert.notEmpty(this.flowConfiguration.getPortConfigurations(),
"flow configuration contains no port configurations");
}
private void bridgeMessagingPorts() {
private void bridgeMessagingPorts() {
/*
* create a bridge for each target output port to the flow outputChannel
*/
for (PortConfiguration targetPortConfiguration : this.getFlowConfiguration()
.getPortConfigurations()) {
for (String outputPort : targetPortConfiguration.getOutputPortNames()) {
String targetOutputChannelName = (String) targetPortConfiguration.getOutputChannel(outputPort);
SubscribableChannel inputChannel = (SubscribableChannel) resolveChannelName(targetOutputChannelName);
/*
* create a bridge for each target output port to the flow outputChannel
*/
for (PortConfiguration targetPortConfiguration : this.getFlowConfiguration().getPortConfigurations()) {
for (String outputPort : targetPortConfiguration.getOutputPortNames()) {
String targetOutputChannelName = (String) targetPortConfiguration.getOutputChannel(outputPort);
SubscribableChannel inputChannel = (SubscribableChannel) resolveChannelName(targetOutputChannelName);
((AbstractMessageChannel)inputChannel).addInterceptor(new FlowInterceptor(outputPort));
((AbstractMessageChannel) inputChannel).addInterceptor(new FlowInterceptor(outputPort));
logger.debug("creating output bridge on [" + outputPort + "] inputChannelName = ["
+ targetOutputChannelName + "] outputChannel = [" + this.flowOutputChannel + "]");
FlowUtils.bridgeChannels(inputChannel, this.flowOutputChannel);
}
}
}
logger.debug("creating output bridge on [" + outputPort + "] inputChannelName = ["
+ targetOutputChannelName + "] outputChannel = [" + this.flowOutputChannel + "]");
FlowUtils.bridgeChannels(inputChannel, this.flowOutputChannel);
}
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
this.applicationContext = applicationContext;
}
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.integration.flow.config.xml;
import groovy.sql.OutParameter;
import java.util.List;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -23,6 +25,7 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.flow.ChannelNamePortConfiguration;
import org.springframework.integration.flow.FlowConfiguration;
import org.springframework.integration.flow.PortMetadata;
@@ -48,9 +51,36 @@ public class FlowConfigurationParser implements BeanDefinitionParser {
ManagedList<Object> portConfigList = new ManagedList<Object>();
for (Element el : portMappings) {
BeanDefinition portConfiguration = buildFlowProviderPortConfiguration(el, parserContext);
portConfigList.add(portConfiguration);
if (!DomUtils.getChildElements(el).isEmpty()){
if (el.hasAttribute("input-channel") || el.hasAttribute("output-channel")){
parserContext.getReaderContext().error(
"port-mapping cannot include both channel attributes and child elements",
flowConfigurationBuilder);
}
BeanDefinition portConfiguration = buildFlowProviderPortConfiguration(el, parserContext);
portConfigList.add(portConfiguration);
}
else
{
// A default port configuration
if (!(el.hasAttribute("input-channel"))){
parserContext.getReaderContext().error(
"port-mapping with no child elements must include an 'input-channel' attribute",
flowConfigurationBuilder);
}
BeanDefinitionBuilder portConfigurationBuilder = BeanDefinitionBuilder
.genericBeanDefinition(ChannelNamePortConfiguration.class);
portConfigurationBuilder.addConstructorArgValue(el.getAttribute("input-channel"));
if (el.hasAttribute("output-channel")){
portConfigurationBuilder.addConstructorArgValue(el.getAttribute("output-channel"));
} else {
portConfigurationBuilder.addConstructorArgValue(null);
}
portConfigList.add(portConfigurationBuilder.getBeanDefinition());
}
}
flowConfigurationBuilder.addConstructorArgValue(portConfigList);

View File

@@ -23,6 +23,7 @@ import org.springframework.integration.channel.PublishSubscribeChannel;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.flow.Flow;
import org.springframework.integration.flow.config.FlowUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
@@ -34,6 +35,16 @@ public class FlowParser implements BeanDefinitionParser {
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
Element props = DomUtils.getChildElementByTagName(element,"props");
if(element.hasAttribute("properties") && props !=null) {
parserContext.getReaderContext().error(
"Element cannot have both 'properties' attribute and inner 'props' element",element);
}
BeanDefinitionBuilder flowBuilder = BeanDefinitionBuilder.genericBeanDefinition(Flow.class);
String id = element.getAttribute("id");
BeanDefinitionBuilder flowOutputChannelBuilder = BeanDefinitionBuilder
@@ -45,11 +56,17 @@ public class FlowParser implements BeanDefinitionParser {
IntegrationNamespaceUtils.setValueIfAttributeDefined(flowBuilder, element, "referenced-bean-locations");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(flowBuilder, element, "properties");
IntegrationNamespaceUtils.setValueIfAttributeDefined(flowBuilder, element, "help");
IntegrationNamespaceUtils.setValueIfAttributeDefined(flowBuilder, element, "flow-id");
IntegrationNamespaceUtils.setValueIfAttributeDefined(flowBuilder, element, "flow-id");
if (props != null) {
flowBuilder.addPropertyValue("properties",parserContext.getDelegate().parsePropsElement(props));
}
BeanDefinition beanDefinition = flowBuilder.getBeanDefinition();
parserContext.getRegistry().registerBeanDefinition(id, beanDefinition);
return beanDefinition;
}
}

View File

@@ -1,49 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.springframework.org/schema/integration/flow"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/schema/integration/flow"
elementFormDefault="qualified" attributeFormDefault="unqualified">
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:bean="http://www.springframework.org/schema/beans"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/schema/integration/flow"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/schema/tool" />
<xsd:element name="flow">
<xsd:annotation>
<xsd:documentation><![CDATA[
<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/integration" />
<xsd:element name="flow">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines an integration flow
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="bean:props" minOccurs="0"
maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"
use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the referenced flow
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="properties" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="properties" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
An optional reference to a properties object containing optional or required properties provided to configure the flow
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="referenced-bean-locations" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="referenced-bean-locations"
type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
An optional list of config locations containing optional or required bean definitions referenced by the flow
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="help" type="xsd:boolean"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="help" type="xsd:boolean"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Display port configuration discription
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="flow-id" type="xsd:string"
use="optional">
<xsd:annotation>
@@ -52,101 +61,136 @@
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:complexType>
</xsd:element>
<xsd:element name="outbound-gateway">
<xsd:complexType>
<xsd:attribute name="input-channel" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.core.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="flow" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation>
<xsd:element name="outbound-gateway">
<xsd:complexType>
<xsd:attribute name="input-channel" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="flow" type="xsd:string"
use="required">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The name of the referenced flow]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="input-port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="input-port" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation>
<![CDATA[
The name of the input port]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="flow-configuration">
<xsd:annotation>
<xsd:documentation><![CDATA[
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="flow-configuration">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines a flow configuration (metadata exposed by the flow provider)
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="port-mapping-ref">
<xsd:complexType>
<xsd:attribute name="bean" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="port-mapping" type="PortMappingType" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="port-mapping-ref">
<xsd:complexType>
<xsd:attribute name="bean"
type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="port-mapping" type="PortMappingType">
<xsd:annotation>
<xsd:documentation><![CDATA[
<xsd:element name="port-mapping" type="PortMappingType" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="port-mapping" type="PortMappingType">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines an integration flow port mapping configuraiotn
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:annotation>
</xsd:element>
<xsd:complexType name="BasePortType">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines an integration flow port binding
]]></xsd:documentation>
</xsd:annotation>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="channel" type="xsd:string" use="required" />
</xsd:complexType>
<xsd:complexType name="PortMappingType">
<xsd:sequence>
<xsd:element name="input-port" minOccurs="0"
maxOccurs="1" type="BasePortType"/>
<xsd:element name="output-port" minOccurs="0"
maxOccurs="unbounded" type="BasePortType" />
</xsd:sequence>
<xsd:attribute name="input-channel" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
The receiving Message channel of this endpoint
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type
type="org.springframework.integration.core.SubscribableChannel" />
</tool:annotation>
</xsd:appinfo>
<xsd:documentation>
The receiving Message channel of this endpoint
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="BasePortType">
<xsd:annotation>
<xsd:documentation><![CDATA[
Defines an integration flow port binding
]]></xsd:documentation>
</xsd:annotation>
<xsd:attribute name="name" type="xsd:string" use="required" />
<xsd:attribute name="channel" type="xsd:string"
use="required" />
</xsd:complexType>
<xsd:complexType name="PortMappingType">
<xsd:sequence>
<xsd:element name="input-port" minOccurs="1" maxOccurs="1"
nillable="false" type="BasePortType">
</xsd:element>
<xsd:element name="output-port" minOccurs="0" maxOccurs="unbounded" type="BasePortType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

View File

@@ -25,71 +25,77 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.flow.Flow;
import org.springframework.integration.message.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author David Turanski
*
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/FlowClientNamespaceTest-context.xml")
public class FlowClientNamespaceTest {
@Autowired
@Qualifier("another-input")
MessageChannel gatewayInput;
@Autowired
@Qualifier("another-output")
PollableChannel gatewayOutput;
@Test
public void testGateway(){
Message<String> msg = new GenericMessage<String>("hello");
gatewayInput.send(msg);
Message<?> reply = gatewayOutput.receive();
assertNotNull(reply);
@Autowired
@Qualifier("inputC1")
MessageChannel gatewayInput;
@Autowired
@Qualifier("outputC1")
PollableChannel gatewayOutput;
@Test
public void testGateway() {
Message<String> msg = new GenericMessage<String>("hello");
gatewayInput.send(msg);
Message<?> reply = gatewayOutput.receive();
assertNotNull(reply);
}
@Autowired
@Qualifier("another-input2")
MessageChannel gatewayInput2;
@Autowired
@Qualifier("another-output2")
PollableChannel gatewayOutput2;
@Test
public void testOutboundGateway(){
Message<String> msg1 = new GenericMessage<String>("hello");
Message<String> msg2 = new GenericMessage<String>("world");
Message<?> reply = null;
gatewayInput2.send(msg1);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-output",reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!",reply.getHeaders().get("gateway"));
gatewayInput2.send(msg2);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-discard",reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!",reply.getHeaders().get("gateway"));
gatewayInput2.send(msg1);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-output",reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!",reply.getHeaders().get("gateway"));
@Autowired
@Qualifier("inputC2")
MessageChannel gatewayInput2;
@Autowired
@Qualifier("outputC2")
PollableChannel gatewayOutput2;
@Test
public void testOutboundGateway() {
Message<String> msg1 = new GenericMessage<String>("hello");
Message<String> msg2 = new GenericMessage<String>("world");
Message<?> reply = null;
gatewayInput2.send(msg1);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-output", reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!", reply.getHeaders().get("gateway"));
gatewayInput2.send(msg2);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-discard", reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!", reply.getHeaders().get("gateway"));
gatewayInput2.send(msg1);
reply = gatewayOutput2.receive();
assertNotNull(reply);
assertEquals("gateway-output", reply.getHeaders().get("flow.output.port"));
assertEquals("yeah!", reply.getHeaders().get("gateway"));
}
@Autowired
@Qualifier("flowWithProps")
Flow flowWithProps;
@Test
public void testFlowWithInnerProps() {
assertEquals("val1",flowWithProps.getProperties().getProperty("key1"));
}
}

View File

@@ -18,9 +18,13 @@ package org.springframework.integration.flow.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.Iterator;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.flow.FlowConfiguration;
import org.springframework.integration.flow.PortConfiguration;
import org.springframework.test.context.ContextConfiguration;
@@ -35,10 +39,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration("classpath:/FlowConfigNamespaceTest-context.xml")
public class FlowConfigNamespaceTest {
@Autowired
FlowConfiguration flowConfiguration;
ApplicationContext applicationContext;
@Test
public void test() {
Map<String,FlowConfiguration> flowConfigurations = applicationContext.getBeansOfType(FlowConfiguration.class);
Iterator<FlowConfiguration> iterator = flowConfigurations.values().iterator();
FlowConfiguration flowConfiguration = iterator.next();
assertNotNull(flowConfiguration.getPortConfigurations());
assertEquals(2, flowConfiguration.getPortConfigurations().size());
PortConfiguration pc0 = flowConfiguration.getPortConfigurations().get(0);
@@ -47,6 +56,10 @@ public class FlowConfigNamespaceTest {
assertEquals("subflow-output", pc0.getOutputChannel("output"));
assertEquals(1, pc0.getOutputPortNames().size());
flowConfiguration = iterator.next();
assertNotNull(flowConfiguration.getPortConfigurations());
assertEquals (1, flowConfiguration.getPortConfigurations().size());
}
}

View File

@@ -1,28 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<!-- Instantiate the flow (folded into its own application context) -->
<int-flow:flow id="subflow1" />
<int-flow:outbound-gateway flow="subflow1" input-channel="another-input"
output-channel="another-output" input-port="gateway-input"/>
<!-- Instantiate the flow (folded into its own application context) -->
<int-flow:flow id="subflow1" />
<int-flow:outbound-gateway flow="subflow1"
input-channel="inputC1" output-channel="outputC1" input-port="gateway-input" />
<int:chain input-channel="inputC2" output-channel="outputC2">
<int-flow:outbound-gateway flow="subflow1"
input-port="gateway-input" />
</int:chain>
<int:channel id="outputC1">
<int:queue />
</int:channel>
<int:channel id="outputC2">
<int:queue />
</int:channel>
<int:chain input-channel="another-input2" output-channel="another-output2">
<int-flow:outbound-gateway flow="subflow1" input-port="gateway-input"/>
</int:chain>
<int:channel id="another-output">
<int:queue />
</int:channel>
<int:channel id="another-output2">
<int:queue />
</int:channel>
<int-flow:flow id="flowWithProps" flow-id="subflow1">
<props>
<prop key="key1">val1</prop>
</props>
</int-flow:flow>
</beans>

View File

@@ -2,11 +2,12 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
xsi:schemaLocation="http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<int-flow:flow-configuration>
<int-flow:port-mapping>
<int-flow:input-port name="input"
channel="subflow-input" />
@@ -32,4 +33,8 @@
<int-flow:output-port name="output2"
channel="subflow-output2" />
</int-flow:port-mapping>
<int-flow:flow-configuration>
<int-flow:port-mapping input-channel="inputChannel" output-channel="outputChannel"/>
</int-flow:flow-configuration>
</beans>

View File

@@ -1,24 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-flow="http://www.springframework.org/schema/integration/flow"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/flow http://www.springframework.org/schema/integration/flow/spring-integration-flow-2.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<util:properties id="flowProperties">
<prop key="key1">val1</prop>
</util:properties>
<!-- Instantiate the flow -->
<int-flow:flow id="subflow2" referenced-bean-locations="classpath:ref-bean-config.xml" properties="flowProperties"/>
<int-flow:flow id="subflow2" referenced-bean-locations="classpath:ref-bean-config.xml">
<props>
<prop key="key1">val1</prop>
</props>
</int-flow:flow>
<!-- input port not required if only one -->
<int-flow:outbound-gateway
flow="subflow2"
<int-flow:outbound-gateway flow="subflow2"
input-channel="inputC"
output-channel="outputC"/>

View File

@@ -10,9 +10,7 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<int-flow:flow-configuration>
<int-flow:port-mapping>
<int-flow:input-port name="input" channel="flow-input"/>
</int-flow:port-mapping>
<int-flow:port-mapping input-channel="flow-input"/>
</int-flow:flow-configuration>
<int:bridge input-channel="flow-input" output-channel="nullChannel"/>

View File

@@ -10,10 +10,7 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<int-flow:flow-configuration>
<int-flow:port-mapping>
<int-flow:input-port name="input" channel="flow-input"/>
<int-flow:output-port name="output" channel="flow-output"/>
</int-flow:port-mapping>
<int-flow:port-mapping input-channel="flow-input" output-channel="flow-output"/>
</int-flow:flow-configuration>
<int:filter input-channel="flow-input"

View File

@@ -15,10 +15,7 @@
<context:property-placeholder/>
<int-flow:flow-configuration>
<int-flow:port-mapping>
<int-flow:input-port name="input" channel="subflow-input" />
<int-flow:output-port name="output" channel="subflow-output" />
</int-flow:port-mapping>
<int-flow:port-mapping input-channel="subflow-input" output-channel="subflow-output"/>
</int-flow:flow-configuration>
<int:channel id="subflow-output" />

View File

@@ -12,11 +12,9 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<int-flow:flow-configuration>
<int-flow:port-mapping>
<int-flow:input-port name="input" channel="subflow-input"/>
<int-flow:output-port name="output" channel="subflow-output"/>
</int-flow:port-mapping>
</int-flow:flow-configuration>
<int-flow:port-mapping input-channel="subflow-input" output-channel="subflow-output"/>
</int-flow:flow-configuration>
<!-- Throws exception -->