Added namespace support for configuring endpoint-specific ErrorHandlers (INT-19).
This commit is contained in:
@@ -33,8 +33,10 @@ import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelectorRejectedException;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -140,4 +142,19 @@ public class EndpointParserTests {
|
||||
endpoint.handle(new GenericMessage<Integer>(123));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomErrorHandler() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithErrorHandler.xml", this.getClass());
|
||||
MessageHandler endpoint = (MessageHandler) context.getBean("endpoint");
|
||||
TestErrorHandler errorHandler = (TestErrorHandler) context.getBean("errorHandler");
|
||||
assertNull(errorHandler.getLastError());
|
||||
Message<?> message = new StringMessage("test");
|
||||
endpoint.handle(message);
|
||||
Throwable error = errorHandler.getLastError();
|
||||
assertEquals(MessageHandlingException.class, error.getClass());
|
||||
MessageHandlingException exception = (MessageHandlingException) error;
|
||||
assertEquals(message, exception.getFailedMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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;
|
||||
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ExceptionThrowingTestHandler implements MessageHandler {
|
||||
|
||||
public Message<?> handle(Message<?> message) {
|
||||
throw new MessageHandlingException(message, "intentional test failure");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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;
|
||||
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class TestErrorHandler implements ErrorHandler {
|
||||
|
||||
private volatile Throwable lastError;
|
||||
|
||||
|
||||
public void handle(Throwable t) {
|
||||
this.lastError = t;
|
||||
}
|
||||
|
||||
public Throwable getLastError() {
|
||||
return this.lastError;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
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-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<endpoint id="endpoint" input-channel="testChannel" handler-ref="testHandler" error-handler="errorHandler"/>
|
||||
|
||||
<beans:bean id="testHandler" class="org.springframework.integration.config.ExceptionThrowingTestHandler"/>
|
||||
|
||||
<beans:bean id="errorHandler" class="org.springframework.integration.config.TestErrorHandler"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user