diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java index c1489f4f45..c4fb6c560b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -50,13 +50,13 @@ import org.springframework.expression.Expression; import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.messaging.MessageHandlingException; import org.springframework.integration.annotation.Header; import org.springframework.integration.annotation.Headers; import org.springframework.integration.annotation.Payload; import org.springframework.integration.annotation.Payloads; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHandlingException; import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -168,7 +168,12 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } Assert.notNull(targetObject, "targetObject must not be null"); this.targetObject = targetObject; - this.handlerMethod = new HandlerMethod(method, canProcessMessageList); + try { + this.handlerMethod = new HandlerMethod(method, canProcessMessageList); + } + catch (IneligibleMethodException e) { + throw new IllegalArgumentException(e); + } this.handlerMethods = null; this.handlerMessageMethods = null; this.handlerMethodsList = null; @@ -328,6 +333,13 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator try { handlerMethod = new HandlerMethod(method, canProcessMessageList); } + catch (IneligibleMethodException e) { + if (logger.isDebugEnabled()) { + logger.debug("Method [" + method + "] is not eligible for Message handling " + + e.getMessage() + "."); + } + return; + } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Method [" + method + "] is not eligible for Message handling.", e); @@ -741,8 +753,10 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } private synchronized void setExclusiveTargetParameterType(TypeDescriptor targetParameterType, MethodParameter methodParameter) { - Assert.isNull(this.targetParameterTypeDescriptor, "Found more than one parameter type candidate: [" + if (this.targetParameterTypeDescriptor != null) { + throw new IneligibleMethodException("Found more than one parameter type candidate: [" + this.targetParameterTypeDescriptor + "] and [" + targetParameterType + "]"); + } this.targetParameterTypeDescriptor = targetParameterType; if (Message.class.isAssignableFrom(targetParameterType.getObjectType())) { methodParameter.increaseNestingLevel(); @@ -806,4 +820,13 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } + @SuppressWarnings("serial") + private static class IneligibleMethodException extends RuntimeException { + + private IneligibleMethodException(String message) { + super(message); + } + + } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java index 0289af3b20..246dd20c8a 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java @@ -506,6 +506,16 @@ public class MethodInvokingMessageProcessorTests { assertEquals("FOO", helper.process(new GenericMessage(targetObject))); } + @Test + public void testIneligible() { + IneligibleMethodBean bean = new IneligibleMethodBean(); + MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo"); + processor.processMessage(MessageBuilder.withPayload("true").build()); + assertNotNull(bean.lastArg); + assertEquals(String.class, bean.lastArg.getClass()); + assertEquals("true", bean.lastArg); + } + private static class ExceptionCauseMatcher extends TypeSafeMatcher { private Throwable cause; @@ -683,4 +693,20 @@ public class MethodInvokingMessageProcessorTests { } + private static class IneligibleMethodBean { + + private volatile Object lastArg = null; + + @SuppressWarnings("unused") + public void foo(String s) { + this.lastArg = s; + } + + @SuppressWarnings("unused") + public void foo(String s, int i) { + throw new RuntimeException("expected ineligible"); + } + + } + }