From fc9109e5cb2b2c564ae8efb1e2043e365f27714f Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Wed, 15 Oct 2008 03:44:17 +0000 Subject: [PATCH] Refactored invokeMethod() method. --- .../message/MessageMappingMethodInvoker.java | 51 +++++++++---------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMappingMethodInvoker.java b/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMappingMethodInvoker.java index 165cf3f28d..46abf68b1d 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMappingMethodInvoker.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/message/MessageMappingMethodInvoker.java @@ -122,9 +122,7 @@ public class MessageMappingMethodInvoker implements MethodInvoker, InitializingB if (!this.initialized) { this.afterPropertiesSet(); } - if (ObjectUtils.isEmpty(args)) { - return null; - } + Assert.notEmpty(args, "argument array must not be empty"); Message message = null; if (args.length == 1 && args[0] != null && (args[0] instanceof Message)) { message = (Message) args[0]; @@ -137,43 +135,44 @@ public class MessageMappingMethodInvoker implements MethodInvoker, InitializingB args = this.createArgumentArrayFromMessage(message); } try { - Object result = null; - try { - result = this.invoker.invokeMethod(args); - } - catch (NoSuchMethodException e) { - try { - if (message != null) { - result = this.invoker.invokeMethod(message); - this.methodExpectsMessage = true; - } - } - catch (NoSuchMethodException e2) { - throw new MessageHandlingException(message, "unable to resolve method for args: " - + StringUtils.arrayToCommaDelimitedString(args)); - } - } - if (result == null) { - return null; - } - return result; + return this.doInvokeMethod(args, message); } catch (InvocationTargetException e) { if (e.getCause() != null && e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } - throw new MessageHandlingException(message, "Handler method '" - + this.methodName + "' threw an Exception.", e.getCause()); + throw new MessageHandlingException(message, + "method '" + this.methodName + "' threw an Exception.", e.getCause()); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } - throw new MessageHandlingException(message, "Failed to invoke handler method '" + throw new MessageHandlingException(message, "Failed to invoke method '" + this.methodName + "' with arguments: " + ObjectUtils.nullSafeToString(args), e); } } + private Object doInvokeMethod(Object[] args, Message message) throws Exception { + Object result = null; + try { + result = this.invoker.invokeMethod(args); + } + catch (NoSuchMethodException e) { + try { + if (message != null) { + result = this.invoker.invokeMethod(message); + this.methodExpectsMessage = true; + } + } + catch (NoSuchMethodException e2) { + throw new MessageHandlingException(message, "unable to resolve method for args: " + + StringUtils.arrayToCommaDelimitedString(args)); + } + } + return result; + } + private Object[] createArgumentArrayFromMessage(Message message) { Object args[] = null; Object mappingResult = this.methodExpectsMessage