From f81c9e1d7bd6505c32246c626b4eacb5656dba34 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 18 Aug 2011 13:45:44 -0400 Subject: [PATCH] walks the cause hierarchy again this will accommodate InvocationTargetException and more --- .../gateway/GatewayProxyFactoryBean.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java index 03052f408c..24f709fbf4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/gateway/GatewayProxyFactoryBean.java @@ -20,9 +20,7 @@ import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.UndeclaredThrowableException; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.Executor; @@ -270,7 +268,7 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Trackab return this.invokeGatewayMethod(invocation); } catch (Throwable e) { - this.rethrowExceptionInThrowsClauseIfPossible(e, invocation.getMethod()); + this.rethrowExceptionCauseIfPossible(e, invocation.getMethod()); return null; // preceding call should always throw something } } @@ -308,24 +306,24 @@ public class GatewayProxyFactoryBean extends AbstractEndpoint implements Trackab return (response != null) ? this.convert(response, returnType) : null; } - private void rethrowExceptionInThrowsClauseIfPossible(Throwable originalException, Method method) throws Throwable { - List> exceptionTypes = Arrays.asList(method.getExceptionTypes()); + private void rethrowExceptionCauseIfPossible(Throwable originalException, Method method) throws Throwable { + Class[] exceptionTypes = method.getExceptionTypes(); Throwable t = originalException; - while (t instanceof MessagingException || t instanceof UndeclaredThrowableException) { - t = t.getCause(); - } - if (t instanceof RuntimeException) { - throw t; - } - for (Class exceptionType : exceptionTypes) { - if (exceptionType.isAssignableFrom(t.getClass())) { + while (t != null) { + for (Class exceptionType : exceptionTypes) { + if (exceptionType.isAssignableFrom(t.getClass())) { + throw t; + } + } + if ((t instanceof RuntimeException) && + !(t instanceof MessagingException) && !(t instanceof UndeclaredThrowableException)) { throw t; } + t = t.getCause(); } throw originalException; } - private MethodInvocationGateway createGatewayForMethod(Method method) { Gateway gatewayAnnotation = method.getAnnotation(Gateway.class); MessageChannel requestChannel = this.defaultRequestChannel;