INT-1859 added namespace support for exception-type-router
This commit is contained in:
@@ -62,14 +62,7 @@ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParse
|
||||
if (childElements != null && childElements.size() > 0) {
|
||||
ManagedMap<String, String> channelMap = new ManagedMap<String, String>();
|
||||
for (Element childElement : childElements) {
|
||||
String beanClassName = beanDefinition.getBeanClassName();
|
||||
String key = null;
|
||||
if (beanClassName.endsWith("PayloadTypeRouter")){
|
||||
key = childElement.getAttribute("type");
|
||||
}
|
||||
else {
|
||||
key = childElement.getAttribute("value");
|
||||
}
|
||||
String key = childElement.getAttribute(this.getMappingKeyAttributeValue());
|
||||
channelMap.put(key, childElement.getAttribute("channel"));
|
||||
}
|
||||
beanDefinition.getPropertyValues().add("channelIdentifierMap", channelMap);
|
||||
@@ -79,5 +72,9 @@ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParse
|
||||
}
|
||||
|
||||
protected abstract BeanDefinition doParseRouter(Element element, ParserContext parserContext);
|
||||
|
||||
protected String getMappingKeyAttributeValue(){
|
||||
return "value";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <exception-type-router/> element.
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0.4
|
||||
*/
|
||||
public class ErrorMessageExceptionTypeRouterParser extends AbstractRouterParser {
|
||||
|
||||
@Override
|
||||
protected BeanDefinition doParseRouter(Element element,
|
||||
ParserContext parserContext) {
|
||||
BeanDefinitionBuilder payloadTypeRouterBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".router.ErrorMessageExceptionTypeRouter");
|
||||
return payloadTypeRouterBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMappingKeyAttributeValue(){
|
||||
return "exception-type";
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class IntegrationNamespaceHandler extends AbstractIntegrationNamespaceHan
|
||||
registerBeanDefinitionParser("router", new DefaultRouterParser());
|
||||
registerBeanDefinitionParser("header-value-router", new HeaderValueRouterParser());
|
||||
registerBeanDefinitionParser("payload-type-router", new PayloadTypeRouterParser());
|
||||
registerBeanDefinitionParser("exception-type-router", new ErrorMessageExceptionTypeRouterParser());
|
||||
registerBeanDefinitionParser("recipient-list-router", new RecipientListRouterParser());
|
||||
registerBeanDefinitionParser("splitter", new SplitterParser());
|
||||
registerBeanDefinitionParser("aggregator", new AggregatorParser());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,4 +37,9 @@ public class PayloadTypeRouterParser extends AbstractRouterParser {
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".router.PayloadTypeRouter");
|
||||
return payloadTypeRouterBuilder.getBeanDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMappingKeyAttributeValue(){
|
||||
return "type";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2103,6 +2103,46 @@ Name of the header whose value will be used to route messages
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="exception-type-router">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a Exception Type Router which resolves the target MessageChannel for
|
||||
messages whose payload is an Exception. The channel resolution is based upon
|
||||
the most specific cause of the error for which a channel mapping exists.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="exception-type-router-type">
|
||||
<xsd:attributeGroup ref="inputOutputChannelGroup" />
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:complexType name="exception-type-router-type">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="channelResolvingRouterType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="mapping" minOccurs="1" maxOccurs="unbounded">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="exception-type" type="xsd:string"/>
|
||||
<xsd:attribute name="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:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="router">
|
||||
<xsd:annotation>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
|
||||
|
||||
|
||||
<int:exception-type-router input-channel="inChannel" default-output-channel="outputChannel">
|
||||
<int:mapping exception-type="java.lang.NullPointerException" channel="nullPointerChannel"/>
|
||||
<int:mapping exception-type="java.lang.IllegalArgumentException" channel="illegalArgumentChannel"/>
|
||||
</int:exception-type-router>
|
||||
|
||||
<int:channel id="nullPointerChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="illegalArgumentChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="outputChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.router.config;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class ExceptionTypeRouterParserTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExceptionTypeRouterConfig(){
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("ExceptionTypeRouterParserTests-context.xml", this.getClass());
|
||||
MessageChannel inputChannel = context.getBean("inChannel", MessageChannel.class);
|
||||
|
||||
inputChannel.send(new GenericMessage<Throwable>(new NullPointerException()));
|
||||
QueueChannel nullPointerChannel = context.getBean("nullPointerChannel", QueueChannel.class);
|
||||
Message<Throwable> npeMessage = (Message<Throwable>) nullPointerChannel.receive(1000);
|
||||
assertNotNull(npeMessage);
|
||||
assertTrue(npeMessage.getPayload() instanceof NullPointerException);
|
||||
|
||||
inputChannel.send(new GenericMessage<Throwable>(new IllegalArgumentException()));
|
||||
QueueChannel illegalArgumentChannel = context.getBean("illegalArgumentChannel", QueueChannel.class);
|
||||
Message<Throwable> iaMessage = (Message<Throwable>) illegalArgumentChannel.receive(1000);
|
||||
assertNotNull(iaMessage);
|
||||
assertTrue(iaMessage.getPayload() instanceof IllegalArgumentException);
|
||||
|
||||
inputChannel.send(new GenericMessage<String>("Hello"));
|
||||
QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
|
||||
assertNotNull(outputChannel.receive(1000));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user