Added namespace support for configuring an endpoint's ErrorHandler strategy. For example, the "error-handler" attribute can be provided on the <service-activator/> element with a bean name reference to any implementation of the ErrorHandler interface (INT-178).

This commit is contained in:
Mark Fisher
2008-08-18 20:43:38 +00:00
parent 0ec6cd61d9
commit 58c768541a
6 changed files with 23 additions and 7 deletions

View File

@@ -54,6 +54,8 @@ public abstract class AbstractMessageEndpointParser extends AbstractSingleBeanDe
private static final String SELECTOR_ATTRIBUTE = "selector";
private static final String ERROR_HANDLER_ATTRIBUTE = "error-handler";
private static final String INTERCEPTORS_ELEMENT = "interceptors";
@@ -111,6 +113,7 @@ public abstract class AbstractMessageEndpointParser extends AbstractSingleBeanDe
IntegrationNamespaceUtils.setValueIfAttributeDefined(
builder, element, OUTPUT_CHANNEL_ATTRIBUTE, "outputChannelName");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, SELECTOR_ATTRIBUTE);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, ERROR_HANDLER_ATTRIBUTE);
String returnAddressOverridesAttribute = element.getAttribute(RETURN_ADDRESS_OVERRIDES_ATTRIBUTE);
boolean returnAddressOverrides = "true".equals(returnAddressOverridesAttribute);
builder.addPropertyValue("returnAddressOverrides", returnAddressOverrides);

View File

@@ -213,6 +213,7 @@
<xsd:attribute name="method" type="xsd:string"/>
<xsd:attribute name="input-channel" type="xsd:string" use="required"/>
<xsd:attribute name="selector" type="xsd:string"/>
<xsd:attribute name="error-handler" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.

View File

@@ -104,4 +104,16 @@ public class EndpointParserTests {
endpoint.send(message);
}
@Test
public void testEndpointWithErrorHandler() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"endpointWithErrorHandler.xml", this.getClass());
MessageChannel channel = (MessageChannel) context.getBean("channel");
TestErrorHandler errorHandler = (TestErrorHandler) context.getBean("errorHandler");
assertNull(errorHandler.getLastError());
channel.send(new StringMessage("test"));
assertNotNull(errorHandler.getLastError());
assertEquals("intentional test failure", errorHandler.getLastError().getMessage());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 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.

View File

@@ -6,15 +6,15 @@
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-core-1.0.xsd">
<message-bus/>
<channel id="testChannel"/>
<direct-channel id="channel"/>
<service-activator id="endpoint" input-channel="testChannel" ref="testHandler" error-handler="errorHandler"/>
<service-activator id="endpoint" input-channel="channel" ref="handler" error-handler="errorHandler"/>
<beans:bean id="testHandler" class="org.springframework.integration.config.ExceptionThrowingTestHandler"/>
<beans:bean id="handler" class="org.springframework.integration.config.ExceptionThrowingTestHandler"/>
<beans:bean id="errorHandler" class="org.springframework.integration.config.TestErrorHandler"/>
</beans:beans>