MessageMappingMethodInvoker is now MethodInvokingMessageProcessor since it implements the MessageProcessor interface and is a parallel implementation to ExpressionEvaluatingMessageProcessor.
This commit is contained in:
@@ -19,7 +19,7 @@ package org.springframework.integration.aggregator;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -29,11 +29,11 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class CorrelationStrategyAdapter implements CorrelationStrategy {
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
private final MethodInvokingMessageProcessor processor;
|
||||
|
||||
|
||||
public CorrelationStrategyAdapter(Object object, String methodName) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, methodName, true);
|
||||
this.processor = new MethodInvokingMessageProcessor(object, methodName, true);
|
||||
}
|
||||
|
||||
public CorrelationStrategyAdapter(Object object, Method method) {
|
||||
@@ -41,11 +41,11 @@ public class CorrelationStrategyAdapter implements CorrelationStrategy {
|
||||
Assert.notNull(method, "'method' must not be null");
|
||||
Assert.isTrue(method.getParameterTypes().length == 1, "Method must accept exactly one parameter");
|
||||
Assert.isTrue(!Void.TYPE.equals(method.getReturnType()), "Method return type must not be void");
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.processor = new MethodInvokingMessageProcessor(object, method);
|
||||
}
|
||||
|
||||
public Object getCorrelationKey(Message<?> message) {
|
||||
return invoker.processMessage(message);
|
||||
return processor.processMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.transformer.MessageTransformingHandler;
|
||||
@@ -41,11 +41,11 @@ public class TransformerFactoryBean extends AbstractMessageHandlerFactoryBean {
|
||||
transformer = (Transformer) targetObject;
|
||||
}
|
||||
else if (StringUtils.hasText(targetMethodName)) {
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(targetObject, targetMethodName);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(targetObject, targetMethodName);
|
||||
transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
}
|
||||
else {
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(
|
||||
targetObject, org.springframework.integration.annotation.Transformer.class);
|
||||
transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.transformer.MessageProcessingTransformer;
|
||||
@@ -41,7 +41,7 @@ public class TransformerAnnotationPostProcessor extends AbstractMethodAnnotation
|
||||
|
||||
@Override
|
||||
protected MessageHandler createHandler(Object bean, Method method, Transformer annotation) {
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(bean, method);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(bean, method);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
|
||||
String outputChannelName = annotation.outputChannel();
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.integration.filter;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.integration.selector.MessageSelector;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
public class MethodInvokingSelector extends AbstractMessageProcessingSelector {
|
||||
|
||||
public MethodInvokingSelector(Object object, Method method) {
|
||||
super(new MessageMappingMethodInvoker(object, method));
|
||||
super(new MethodInvokingMessageProcessor(object, method));
|
||||
Class<?> returnType = method.getReturnType();
|
||||
Assert.isTrue(boolean.class.isAssignableFrom(returnType)
|
||||
|| Boolean.class.isAssignableFrom(returnType),
|
||||
@@ -38,7 +38,7 @@ public class MethodInvokingSelector extends AbstractMessageProcessingSelector {
|
||||
}
|
||||
|
||||
public MethodInvokingSelector(Object object, String methodName) {
|
||||
super(new MessageMappingMethodInvoker(object, methodName));
|
||||
super(new MethodInvokingMessageProcessor(object, methodName));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -115,15 +115,15 @@ public class ArgumentArrayMessageMapper implements InboundMessageMapper<Object[]
|
||||
this.payloadParameterMetadata = getPayloadParameterFrom(this.parameterMetadata);
|
||||
}
|
||||
|
||||
public Message<?> toMessage(Object[] parameters) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(parameters), "parameter array is required");
|
||||
Assert.isTrue(parameters.length == this.parameterMetadata.length, "wrong number of parameters: expected "
|
||||
+ this.parameterMetadata.length + ", received " + parameters.length);
|
||||
public Message<?> toMessage(Object[] arguments) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(arguments), "argument array is required");
|
||||
Assert.isTrue(arguments.length == this.parameterMetadata.length, "wrong number of arguments: expected "
|
||||
+ this.parameterMetadata.length + ", received " + arguments.length);
|
||||
Message<?> message = null;
|
||||
Object payload = null;
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
Object value = parameters[i];
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
Object value = arguments[i];
|
||||
MethodParameterMetadata metadata = this.parameterMetadata[i];
|
||||
Header headerAnnotation = metadata.getHeaderAnnotation();
|
||||
if (metadata == payloadParameterMetadata) {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MethodInvokingMessageHandler extends MessageMappingMethodInvoker implements MessageHandler, Ordered {
|
||||
public class MethodInvokingMessageHandler extends MethodInvokingMessageProcessor implements MessageHandler, Ordered {
|
||||
|
||||
private volatile int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
|
||||
@@ -48,11 +48,11 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
* @see MethodParameterMessageMapper
|
||||
* @see ArgumentArrayMessageMapper
|
||||
*/
|
||||
public class MessageMappingMethodInvoker implements MessageProcessor {
|
||||
public class MethodInvokingMessageProcessor implements MessageProcessor {
|
||||
|
||||
protected static final Log logger = LogFactory.getLog(MessageMappingMethodInvoker.class);
|
||||
protected static final Log logger = LogFactory.getLog(MethodInvokingMessageProcessor.class);
|
||||
|
||||
private volatile Object object;
|
||||
|
||||
@@ -66,25 +66,25 @@ public class MessageMappingMethodInvoker implements MessageProcessor {
|
||||
private final Set<Method> methodsExpectingMessage = new HashSet<Method>();
|
||||
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, Method method) {
|
||||
public MethodInvokingMessageProcessor(Object object, Method method) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Assert.notNull(method, "method must not be null");
|
||||
this.object = object;
|
||||
this.methodResolver = new StaticHandlerMethodResolver(method);
|
||||
}
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, Class<? extends Annotation> annotationType) {
|
||||
public MethodInvokingMessageProcessor(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;
|
||||
this.methodResolver = this.createResolverForAnnotation(annotationType);
|
||||
}
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, String methodName) {
|
||||
public MethodInvokingMessageProcessor(Object object, String methodName) {
|
||||
this(object, methodName, false);
|
||||
}
|
||||
|
||||
public MessageMappingMethodInvoker(Object object, String methodName, boolean requiresReturnValue) {
|
||||
public MethodInvokingMessageProcessor(Object object, String methodName, boolean requiresReturnValue) {
|
||||
Assert.notNull(object, "object must not be null");
|
||||
Assert.notNull(methodName, "methodName must not be null");
|
||||
this.object = object;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -27,26 +27,26 @@ import org.springframework.integration.message.MessageHandlingException;
|
||||
*/
|
||||
public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
private final MethodInvokingMessageProcessor processor;
|
||||
|
||||
|
||||
public ServiceActivatingHandler(final Object object) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, ServiceActivator.class);
|
||||
this.processor = new MethodInvokingMessageProcessor(object, ServiceActivator.class);
|
||||
}
|
||||
|
||||
public ServiceActivatingHandler(Object object, Method method) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.processor = new MethodInvokingMessageProcessor(object, method);
|
||||
}
|
||||
|
||||
public ServiceActivatingHandler(Object object, String methodName) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, methodName);
|
||||
this.processor = new MethodInvokingMessageProcessor(object, methodName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) {
|
||||
try {
|
||||
Object result = this.invoker.processMessage(message);
|
||||
Object result = this.processor.processMessage(message);
|
||||
if (result != null) {
|
||||
replyHolder.set(result);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "ServiceActivator for [" + this.invoker + "]";
|
||||
return "ServiceActivator for [" + this.processor + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.integration.annotation.Router;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
|
||||
/**
|
||||
* A Message Router that invokes the specified method on the given object. The
|
||||
@@ -34,15 +34,15 @@ import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
public class MethodInvokingRouter extends AbstractMessageProcessingRouter {
|
||||
|
||||
public MethodInvokingRouter(Object object, Method method) {
|
||||
super(new MessageMappingMethodInvoker(object, method));
|
||||
super(new MethodInvokingMessageProcessor(object, method));
|
||||
}
|
||||
|
||||
public MethodInvokingRouter(Object object, String methodName) {
|
||||
super(new MessageMappingMethodInvoker(object, methodName));
|
||||
super(new MethodInvokingMessageProcessor(object, methodName));
|
||||
}
|
||||
|
||||
public MethodInvokingRouter(Object object) {
|
||||
super(new MessageMappingMethodInvoker(object, Router.class));
|
||||
super(new MethodInvokingMessageProcessor(object, Router.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.integration.splitter;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.integration.annotation.Splitter;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
|
||||
/**
|
||||
* A Message Splitter implementation that invokes the specified method
|
||||
@@ -33,15 +33,15 @@ import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
public class MethodInvokingSplitter extends AbstractMessageProcessingSplitter {
|
||||
|
||||
public MethodInvokingSplitter(Object object, Method method) {
|
||||
super(new MessageMappingMethodInvoker(object, method));
|
||||
super(new MethodInvokingMessageProcessor(object, method));
|
||||
}
|
||||
|
||||
public MethodInvokingSplitter(Object object, String methodName) {
|
||||
super(new MessageMappingMethodInvoker(object, methodName));
|
||||
super(new MethodInvokingMessageProcessor(object, methodName));
|
||||
}
|
||||
|
||||
public MethodInvokingSplitter(Object object) {
|
||||
super(new MessageMappingMethodInvoker(object, Splitter.class));
|
||||
super(new MethodInvokingMessageProcessor(object, Splitter.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class AggregatorAnnotationTests {
|
||||
Assert.assertTrue(correlationStrategy instanceof CorrelationStrategyAdapter);
|
||||
CorrelationStrategyAdapter completionStrategyAdapter = (CorrelationStrategyAdapter) correlationStrategy;
|
||||
DirectFieldAccessor invokerAccessor = new DirectFieldAccessor(
|
||||
new DirectFieldAccessor(completionStrategyAdapter).getPropertyValue("invoker"));
|
||||
new DirectFieldAccessor(completionStrategyAdapter).getPropertyValue("processor"));
|
||||
Object targetObject = invokerAccessor.getPropertyValue("object");
|
||||
assertSame(context.getBean(endpointName), targetObject);
|
||||
HandlerMethodResolver completionCheckerMethodResolver = (HandlerMethodResolver) invokerAccessor.getPropertyValue("methodResolver");
|
||||
|
||||
@@ -81,7 +81,7 @@ public class PNamespaceTest {
|
||||
DirectFieldAccessor saAccessor = new DirectFieldAccessor(serviceActivator);
|
||||
Object handler = saAccessor.getPropertyValue("handler");
|
||||
DirectFieldAccessor hAccessor = new DirectFieldAccessor(handler);
|
||||
Object invoker = hAccessor.getPropertyValue("invoker");
|
||||
Object invoker = hAccessor.getPropertyValue("processor");
|
||||
DirectFieldAccessor iAccessor = new DirectFieldAccessor(invoker);
|
||||
return (TestBean) iAccessor.getPropertyValue("object");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -36,79 +36,79 @@ import org.springframework.integration.message.StringMessage;
|
||||
* @author Mark Fisher
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public class MessageMappingMethodInvokerTests {
|
||||
public class MethodInvokingMessageProcessorTests {
|
||||
|
||||
@Test
|
||||
public void payloadAsMethodParameterAndObjectAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptPayloadAndReturnObject");
|
||||
Object result = invoker.processMessage(new StringMessage("testing"));
|
||||
Object result = processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-1", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void payloadAsMethodParameterAndMessageAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptPayloadAndReturnMessage");
|
||||
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
|
||||
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-2", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageAsMethodParameterAndObjectAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptMessageAndReturnObject");
|
||||
Object result = invoker.processMessage(new StringMessage("testing"));
|
||||
Object result = processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-3", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageAsMethodParameterAndMessageAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptMessageAndReturnMessage");
|
||||
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
|
||||
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-4", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageSubclassAsMethodParameterAndMessageAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptMessageSubclassAndReturnMessage");
|
||||
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
|
||||
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-5", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageSubclassAsMethodParameterAndMessageSubclassAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptMessageSubclassAndReturnMessageSubclass");
|
||||
Message<?> result = (Message<?>) invoker.processMessage(new StringMessage("testing"));
|
||||
Message<?> result = (Message<?>) processor.processMessage(new StringMessage("testing"));
|
||||
assertEquals("testing-6", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void payloadAndHeaderAnnotationMethodParametersAndObjectAsReturnValue() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(
|
||||
new TestBean(), "acceptPayloadAndHeaderAndReturnObject");
|
||||
Message<?> request = MessageBuilder.withPayload("testing")
|
||||
.setHeader("number", new Integer(123)).build();
|
||||
Object result = invoker.processMessage(request);
|
||||
Object result = processor.processMessage(request);
|
||||
assertEquals("testing-123", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoidMethodsIncludedbyDefault() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(new TestBean(), "testVoidReturningMethods");
|
||||
assertNull(invoker.processMessage(MessageBuilder.withPayload("Something").build()));
|
||||
assertEquals(12, invoker.processMessage(MessageBuilder.withPayload(12).build()));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new TestBean(), "testVoidReturningMethods");
|
||||
assertNull(processor.processMessage(MessageBuilder.withPayload("Something").build()));
|
||||
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoidMethodsExcludedByFlag() {
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(new TestBean(), "testVoidReturningMethods", true);
|
||||
assertEquals(12, invoker.processMessage(MessageBuilder.withPayload(12).build()));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new TestBean(), "testVoidReturningMethods", true);
|
||||
assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build()));
|
||||
try {
|
||||
assertNull(invoker.processMessage(MessageBuilder.withPayload("Something").build()));
|
||||
assertNull(processor.processMessage(MessageBuilder.withPayload("Something").build()));
|
||||
fail();
|
||||
} catch(IllegalArgumentException ex){
|
||||
|
||||
@@ -119,8 +119,8 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void messageOnlyWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("messageOnly", Message.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
Object result = invoker.processMessage(new StringMessage("foo"));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Object result = processor.processMessage(new StringMessage("foo"));
|
||||
assertEquals("foo", result);
|
||||
}
|
||||
|
||||
@@ -128,8 +128,8 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void payloadWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("integerMethod", Integer.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
Object result = invoker.processMessage(new GenericMessage<Integer>(new Integer(123)));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Object result = processor.processMessage(new GenericMessage<Integer>(new Integer(123)));
|
||||
assertEquals(new Integer(123), result);
|
||||
}
|
||||
|
||||
@@ -137,8 +137,8 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void convertedPayloadWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("integerMethod", Integer.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
Object result = invoker.processMessage(new StringMessage("456"));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Object result = processor.processMessage(new StringMessage("456"));
|
||||
assertEquals(new Integer(456), result);
|
||||
}
|
||||
|
||||
@@ -146,8 +146,8 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void conversionFailureWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("integerMethod", Integer.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
Object result = invoker.processMessage(new StringMessage("foo"));
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Object result = processor.processMessage(new StringMessage("foo"));
|
||||
assertEquals(new Integer(123), result);
|
||||
}
|
||||
|
||||
@@ -155,10 +155,10 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("messageAndHeader", Message.class, Integer.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("number", 42).build();
|
||||
Object result = invoker.processMessage(message);
|
||||
Object result = processor.processMessage(message);
|
||||
assertEquals("foo-42", result);
|
||||
}
|
||||
|
||||
@@ -166,15 +166,16 @@ public class MessageMappingMethodInvokerTests {
|
||||
public void multipleHeadersWithAnnotatedMethod() throws Exception {
|
||||
AnnotatedTestService service = new AnnotatedTestService();
|
||||
Method method = service.getClass().getMethod("twoHeaders", String.class, Integer.class);
|
||||
MessageMappingMethodInvoker invoker = new MessageMappingMethodInvoker(service, method);
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("prop", "bar")
|
||||
.setHeader("number", 42).build();
|
||||
Object result = invoker.processMessage(message);
|
||||
Object result = processor.processMessage(message);
|
||||
assertEquals("bar-42", result);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class TestBean {
|
||||
|
||||
public String acceptPayloadAndReturnObject(String s) {
|
||||
@@ -215,6 +216,8 @@ public class MessageMappingMethodInvokerTests {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class AnnotatedTestService {
|
||||
|
||||
public String messageOnly(Message<?> message) {
|
||||
@@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
import org.springframework.integration.annotation.Header;
|
||||
import org.springframework.integration.annotation.Transformer;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MethodInvokingMessageProcessor;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
@@ -44,7 +44,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void simplePayloadConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new StringMessage("foo");
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -54,7 +54,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void simplePayloadConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new StringMessage("foo");
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -65,7 +65,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void typeConversionConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new GenericMessage<Integer>(123);
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -75,7 +75,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void typeConversionConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new GenericMessage<Integer>(123);
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -86,7 +86,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void typeConversionFailureConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("exclaim", String.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new GenericMessage<Date>(new Date());
|
||||
transformer.transform(message);
|
||||
@@ -95,7 +95,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void typeConversionFailureConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "exclaim");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "exclaim");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<?> message = new GenericMessage<Date>(new Date());
|
||||
transformer.transform(message);
|
||||
@@ -105,7 +105,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void headerAnnotationConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("headerTest", String.class, Integer.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("number", 123).build();
|
||||
@@ -116,7 +116,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void headerAnnotationConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "headerTest");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "headerTest");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("number", 123).build();
|
||||
@@ -128,7 +128,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void headerValueNotProvided() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("headerTest", String.class, Integer.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("wrong", 123).build();
|
||||
@@ -139,7 +139,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void optionalHeaderAnnotation() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("foo").setHeader("number", 99).build();
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -150,7 +150,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void optionalHeaderValueNotProvided() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("optionalHeaderTest", String.class, Integer.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("foo").build();
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -161,7 +161,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void headerEnricherConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("propertyEnricherTest", String.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("prop1", "bad")
|
||||
@@ -176,7 +176,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void headerEnricherConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "propertyEnricherTest");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "propertyEnricherTest");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("test")
|
||||
.setHeader("prop1", "bad")
|
||||
@@ -192,7 +192,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void messageReturnValueConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("messageReturnValueTest", Message.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("test").build();
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -202,7 +202,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void messageReturnValueConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "messageReturnValueTest");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "messageReturnValueTest");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Message<String> message = MessageBuilder.withPayload("test").build();
|
||||
Message<?> result = transformer.transform(message);
|
||||
@@ -214,7 +214,7 @@ public class MethodInvokingTransformerTests {
|
||||
public void propertiesPayloadConfiguredWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method testMethod = testBean.getClass().getMethod("propertyPayloadTest", Properties.class);
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, testMethod);
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, testMethod);
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Properties props = new Properties();
|
||||
props.setProperty("prop1", "bad");
|
||||
@@ -235,7 +235,7 @@ public class MethodInvokingTransformerTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void propertiesPayloadConfiguredWithMethodName() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "propertyPayloadTest");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "propertyPayloadTest");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
Properties props = new Properties();
|
||||
props.setProperty("prop1", "bad");
|
||||
@@ -255,7 +255,7 @@ public class MethodInvokingTransformerTests {
|
||||
@Test
|
||||
public void nullReturningMethod() {
|
||||
TestBean testBean = new TestBean();
|
||||
MessageProcessor messageProcessor = new MessageMappingMethodInvoker(testBean, "nullReturnValueTest");
|
||||
MessageProcessor messageProcessor = new MethodInvokingMessageProcessor(testBean, "nullReturnValueTest");
|
||||
MessageProcessingTransformer transformer = new MessageProcessingTransformer(messageProcessor);
|
||||
StringMessage message = new StringMessage("test");
|
||||
Message<?> result = transformer.transform(message);
|
||||
|
||||
Reference in New Issue
Block a user