INT-904, INT-907 added tests
This commit is contained in:
@@ -192,14 +192,15 @@ public abstract class AbstractMessagingGateway extends AbstractEndpoint {
|
||||
Throwable error = null;
|
||||
try {
|
||||
reply = this.channelTemplate.sendAndReceive(message, this.requestChannel);
|
||||
if (reply instanceof ErrorMessage) {
|
||||
error = ((ErrorMessage) reply).getPayload();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("failure occurred in gateway sendAndReceive.", e);
|
||||
error = e;
|
||||
}
|
||||
if (reply instanceof ErrorMessage) {
|
||||
error = ((ErrorMessage) reply).getPayload();
|
||||
}
|
||||
|
||||
if (error != null && this.exceptionMapper != null) {
|
||||
try {
|
||||
// create a reply message from the error
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd"
|
||||
xmlns:si="http://www.springframework.org/schema/integration">
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:task="http://www.springframework.org/schema/task">
|
||||
|
||||
<si:gateway id="simpleGateway"
|
||||
default-request-channel="inputA"
|
||||
@@ -19,13 +21,34 @@
|
||||
service-interface="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleGateway"
|
||||
exception-mapper="exceptionMapper"/>
|
||||
|
||||
|
||||
<si:gateway id="gatewayWithErrorAsync"
|
||||
default-request-channel="routingChannel"
|
||||
service-interface="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleGateway"/>
|
||||
|
||||
<si:gateway id="gatewayWithErrorAsyncAndMapper"
|
||||
default-request-channel="routingChannel"
|
||||
service-interface="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleGateway"
|
||||
exception-mapper="exceptionMapper"/>
|
||||
|
||||
<si:router input-channel="routingChannel" expression="payload"/>
|
||||
|
||||
<si:service-activator input-channel="echoWithRuntimeExceptionChannel" method="echoWithRuntimeException">
|
||||
<bean class="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleService" />
|
||||
</si:service-activator>
|
||||
|
||||
<si:channel id="echoWithErrorAsyncChannel">
|
||||
<si:queue/>
|
||||
</si:channel>
|
||||
|
||||
<si:service-activator input-channel="echoWithErrorAsyncChannel" method="echoWithErrorAsync">
|
||||
<bean class="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleService" />
|
||||
<si:poller max-messages-per-poll="1" task-executor="executor">
|
||||
<si:interval-trigger interval="100" time-unit="MILLISECONDS"/>
|
||||
</si:poller>
|
||||
</si:service-activator>
|
||||
<task:executor id="executor" pool-size="5"/>
|
||||
|
||||
|
||||
<si:service-activator input-channel="echoWithMessagingExceptionChannel" method="echoWithMessagingException">
|
||||
<bean class="org.springframework.integration.gateway.GatewayInvokingMessageHandlerTests$SimpleService" />
|
||||
</si:service-activator>
|
||||
|
||||
@@ -57,6 +57,16 @@ public class GatewayInvokingMessageHandlerTests {
|
||||
SimpleGateway gatewayWithErrorAndMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("gatewayWithErrorAsync")
|
||||
SimpleGateway gatewayWithErrorAsync;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("gatewayWithErrorAsyncAndMapper")
|
||||
SimpleGateway gatewayWithErrorAsyncAndMapper;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("inputB")
|
||||
SubscribableChannel output;
|
||||
@@ -118,6 +128,33 @@ public class GatewayInvokingMessageHandlerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateGatewayWithErrorAsync() {
|
||||
try {
|
||||
gatewayWithErrorAsync.sendRecieve("echoWithErrorAsyncChannel");
|
||||
Assert.fail();
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof MessageHandlingException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateGatewayWithErrorAsyncAndMaper() {
|
||||
try {
|
||||
gatewayWithErrorAsync.sendRecieve("echoWithErrorAsyncChannel");
|
||||
Assert.fail();
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue(e instanceof MessageHandlingException);
|
||||
}
|
||||
|
||||
try {
|
||||
Object result = gatewayWithErrorAsyncAndMapper.sendRecieve("echoWithErrorAsyncChannel");
|
||||
Assert.assertEquals("Error happened in message: echoWithErrorAsyncChannel", result);
|
||||
} catch (Exception e) {
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class SampleExceptionMapper implements InboundMessageMapper<Throwable>{
|
||||
public Message<?> toMessage(Throwable object) throws Exception {
|
||||
@@ -142,6 +179,10 @@ public class GatewayInvokingMessageHandlerTests {
|
||||
public MessageHandlingException echoWithMessagingException(String value) {
|
||||
throw new MessageHandlingException(new StringMessage(value));
|
||||
}
|
||||
public RuntimeException echoWithErrorAsync(String value) {
|
||||
throw new RuntimeException(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class SampleCheckedException extends Exception {
|
||||
|
||||
Reference in New Issue
Block a user