Moved annotation-based method resolution into the MessageMappingMethodInvoker instead of the individual handler types (ServiceActivatingHandler, MethodInvokingRouter, and MethodInvokingSplitter).
This commit is contained in:
@@ -23,27 +23,18 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.util.DefaultMethodResolver;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
import org.springframework.integration.util.MethodResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler implements InitializingBean {
|
||||
|
||||
private final MethodResolver methodResolver = new DefaultMethodResolver(ServiceActivator.class);
|
||||
|
||||
private final MethodInvoker invoker;
|
||||
|
||||
|
||||
public ServiceActivatingHandler(final Object object) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Method method = this.methodResolver.findMethod(object);
|
||||
Assert.notNull(method, "unable to resolve ServiceActivator method on target class ["
|
||||
+ object.getClass() + "]");
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.invoker = new MessageMappingMethodInvoker(object, ServiceActivator.class);
|
||||
}
|
||||
|
||||
public ServiceActivatingHandler(Object object, Method method) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.integration.message;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -27,7 +28,9 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.util.DefaultMethodInvoker;
|
||||
import org.springframework.integration.util.DefaultMethodResolver;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
import org.springframework.integration.util.MethodResolver;
|
||||
import org.springframework.integration.util.NameResolvingMethodInvoker;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -71,6 +74,16 @@ public class MessageMappingMethodInvoker implements MethodInvoker, InitializingB
|
||||
this.methodName = method.getName();
|
||||
}
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, Class<? extends Annotation> annotationType) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Assert.notNull(annotationType, "annotation type must not be null");
|
||||
this.object = object;
|
||||
MethodResolver methodResolver = new DefaultMethodResolver(annotationType);
|
||||
this.method = methodResolver.findMethod(object);
|
||||
Assert.notNull(method, "unable to resolve method for annotation [" + annotationType.getSimpleName()
|
||||
+ "] on target class [" + object.getClass() + "]");
|
||||
}
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, String methodName) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Assert.notNull(methodName, "methodName must not be null");
|
||||
|
||||
@@ -29,8 +29,6 @@ import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessagingException;
|
||||
import org.springframework.integration.message.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.util.DefaultMethodResolver;
|
||||
import org.springframework.integration.util.MethodResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -44,8 +42,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MethodInvokingRouter extends AbstractMessageRouter implements InitializingBean {
|
||||
|
||||
private final MethodResolver methodResolver = new DefaultMethodResolver(Router.class);
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
|
||||
private volatile ChannelResolver channelResolver;
|
||||
@@ -60,11 +56,7 @@ public class MethodInvokingRouter extends AbstractMessageRouter implements Initi
|
||||
}
|
||||
|
||||
public MethodInvokingRouter(Object object) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Method method = this.methodResolver.findMethod(object);
|
||||
Assert.notNull(method, "unable to resolve Router method on target class ["
|
||||
+ object.getClass() + "]");
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.invoker = new MessageMappingMethodInvoker(object, Router.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.util.DefaultMethodResolver;
|
||||
import org.springframework.integration.util.MethodResolver;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* A Message Splitter implementation that invokes the specified method
|
||||
@@ -37,8 +34,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class MethodInvokingSplitter extends AbstractMessageSplitter implements InitializingBean {
|
||||
|
||||
private final MethodResolver methodResolver = new DefaultMethodResolver(Splitter.class);
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
|
||||
|
||||
@@ -51,11 +46,7 @@ public class MethodInvokingSplitter extends AbstractMessageSplitter implements I
|
||||
}
|
||||
|
||||
public MethodInvokingSplitter(Object object) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Method method = this.methodResolver.findMethod(object);
|
||||
Assert.notNull(method, "unable to resolve Splitter method on target class ["
|
||||
+ object.getClass() + "]");
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.invoker = new MessageMappingMethodInvoker(object, Splitter.class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user