MethodInvokingTarget now extends AbstractMessageHandler instead of AbstractMessageHandlerAdapter. SplitterMessageHandlerCreator no longer requires configuration of the "outputChannel" property.

This commit is contained in:
Mark Fisher
2008-08-12 11:30:18 +00:00
parent 178c438159
commit 56f5a9374c
4 changed files with 22 additions and 28 deletions

View File

@@ -100,7 +100,7 @@ public abstract class AbstractMessageHandler implements MessageHandler, Initiali
public void setMethod(Method method) {
Assert.notNull(method, "method must not be null");
if (method.getParameterTypes().length == 0) {
throw new IllegalArgumentException("method must accept at least one parameter");
throw new ConfigurationException("method must accept at least one parameter");
}
if (method.getParameterTypes()[0].equals(Message.class)) {
this.methodExpectsMessage = true;

View File

@@ -17,15 +17,15 @@
package org.springframework.integration.handler;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.MessagingException;
import org.springframework.integration.message.MessageTarget;
import org.springframework.integration.message.MessagingException;
/**
* A messaging target that invokes the specified method on the provided object.
*
* @author Mark Fisher
*/
public class MethodInvokingTarget extends AbstractMessageHandlerAdapter implements MessageTarget {
public class MethodInvokingTarget extends AbstractMessageHandler implements MessageTarget {
public boolean send(Message<?> message) {
this.handle(message);
@@ -33,9 +33,9 @@ public class MethodInvokingTarget extends AbstractMessageHandlerAdapter implemen
}
@Override
protected Message<?> handleReturnValue(Object returnValue, Message<?> originalMessage) {
if (returnValue != null) {
throw new MessagingException(originalMessage, "The target method returned a non-null Object. " +
protected Message<?> createReplyMessage(Object result, Message<?> requestMessage) {
if (result != null) {
throw new MessagingException(requestMessage, "The target method returned a non-null Object. " +
"MethodInvokingTarget should only be used for methods that return no value (preferably void).");
}
return null;

View File

@@ -19,10 +19,6 @@ package org.springframework.integration.splitter;
import java.lang.reflect.Method;
import java.util.Map;
import org.springframework.aop.support.AopUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.handler.AbstractMessageHandlerAdapter;
import org.springframework.integration.handler.MessageHandler;
import org.springframework.integration.handler.config.AbstractMessageHandlerCreator;
@@ -34,13 +30,6 @@ import org.springframework.integration.handler.config.AbstractMessageHandlerCrea
public class SplitterMessageHandlerCreator extends AbstractMessageHandlerCreator {
public MessageHandler doCreateHandler(Object object, Method method, Map<String, ?> attributes) {
String outputChannelName = (String) attributes.get(AbstractMessageHandlerAdapter.OUTPUT_CHANNEL_NAME_KEY);
if (outputChannelName == null) {
MessageEndpoint endpointAnnotation = AnnotationUtils.findAnnotation(AopUtils.getTargetClass(object), MessageEndpoint.class);
if (endpointAnnotation != null) {
outputChannelName = endpointAnnotation.output();
}
}
return new SplitterMessageHandler(object, method);
}