Added support for the 'throw-exception-on-rejection' attribute for the 'filter' element.

This commit is contained in:
Mark Fisher
2008-11-21 22:52:11 +00:00
parent 2b166d6471
commit b53d96ba1e
4 changed files with 36 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ public class FilterParser extends AbstractConsumerEndpointParser {
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(MessageFilter.class);
builder.addConstructorArgReference(this.parseSelector(element, parserContext));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "throw-exception-on-rejection");
return builder;
}

View File

@@ -257,7 +257,15 @@
<xsd:extension base="inputOutputEndpointType">
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="unbounded">
<xsd:element name="filter" type="handlerType"/>
<xsd:element name="filter">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="handlerType">
<xsd:attribute name="throw-exception-on-rejection" type="xsd:string" default="false"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="transformer" type="handlerType"/>
<xsd:element name="service-activator" type="handlerType"/>
<xsd:element name="splitter" type="handlerType"/>
@@ -424,12 +432,19 @@
</xsd:annotation>
</xsd:element>
<xsd:element name="filter" type="inputOutputEndpointType">
<xsd:element name="filter">
<xsd:annotation>
<xsd:documentation>
Defines a Filter.
</xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="inputOutputEndpointType">
<xsd:attribute name="throw-exception-on-rejection" type="xsd:string" default="false"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="router">

View File

@@ -22,6 +22,8 @@
<filter ref="selectorImpl" input-channel="implementationInput" output-channel="implementationOutput"/>
<filter ref="selectorImpl" input-channel="exceptionInput" output-channel="implementationOutput" throw-exception-on-rejection="true"/>
<beans:bean id="selectorImpl"
class="org.springframework.integration.config.FilterParserTests$TestSelectorImpl"/>

View File

@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageRejectedException;
import org.springframework.integration.message.StringMessage;
import org.springframework.integration.selector.MessageSelector;
import org.springframework.test.context.ContextConfiguration;
@@ -53,6 +54,9 @@ public class FilterParserTests {
@Autowired @Qualifier("implementationOutput")
PollableChannel implementationOutput;
@Autowired @Qualifier("exceptionInput")
MessageChannel exceptionInput;
@Test
public void filterWithSelectorAdapterAccepts() {
@@ -84,6 +88,18 @@ public class FilterParserTests {
assertNull(reply);
}
@Test
public void exceptionThrowingFilterAccepts() {
exceptionInput.send(new StringMessage("test"));
Message<?> reply = implementationOutput.receive(0);
assertNotNull(reply);
}
@Test(expected = MessageRejectedException.class)
public void exceptionThrowingFilterRejects() {
exceptionInput.send(new StringMessage(""));
}
public static class TestSelectorBean {