INT-765, INT-766 Added MessageProcessor interface. The MessageMappingMethodInvoking now implements that interface.
This commit is contained in:
@@ -29,24 +29,23 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class CorrelationStrategyAdapter implements CorrelationStrategy {
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
|
||||
|
||||
public CorrelationStrategyAdapter(Object object, String methodName) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, methodName, true);
|
||||
}
|
||||
public CorrelationStrategyAdapter(Object object, String methodName) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, methodName, true);
|
||||
}
|
||||
|
||||
public CorrelationStrategyAdapter(Object object, Method method) {
|
||||
Assert.notNull(object, "'object' must not be null");
|
||||
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);
|
||||
}
|
||||
public CorrelationStrategyAdapter(Object object, Method method) {
|
||||
Assert.notNull(object, "'object' must not be null");
|
||||
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);
|
||||
}
|
||||
|
||||
public Object getCorrelationKey(Message<?> message) {
|
||||
return invoker.processMessage(message);
|
||||
}
|
||||
|
||||
public Object getCorrelationKey(Message<?> message) {
|
||||
return invoker.invokeMethod(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MethodInvokingSelector implements MessageSelector {
|
||||
|
||||
|
||||
public boolean accept(Message<?> message) {
|
||||
Object result = this.invoker.invokeMethod(message);
|
||||
Object result = this.invoker.processMessage(message);
|
||||
Assert.notNull(result, "result must not be null");
|
||||
Assert.isAssignable(Boolean.class, result.getClass(), "a boolean result is required");
|
||||
return (Boolean) result;
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Marius Bogoevici
|
||||
* @see MethodParameterMessageMapper
|
||||
*/
|
||||
public class MessageMappingMethodInvoker {
|
||||
public class MessageMappingMethodInvoker implements MessageProcessor {
|
||||
|
||||
protected static final Log logger = LogFactory.getLog(MessageMappingMethodInvoker.class);
|
||||
|
||||
@@ -90,9 +90,8 @@ public class MessageMappingMethodInvoker {
|
||||
this.object = object;
|
||||
this.methodResolver = this.createResolverForMethodName(methodName, requiresReturnValue);
|
||||
}
|
||||
|
||||
|
||||
public Object invokeMethod(Message<?> message) {
|
||||
public Object processMessage(Message<?> message) {
|
||||
Assert.notNull(message, "message must not be null");
|
||||
if (message.getPayload() == null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
@@ -104,7 +103,7 @@ public class MessageMappingMethodInvoker {
|
||||
Object[] args = null;
|
||||
try {
|
||||
args = this.createArgumentArrayFromMessage(method, message);
|
||||
return this.doInvokeMethod(method, args, message);
|
||||
return this.invokeMethod(method, args, message);
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
if (e.getCause() != null && e.getCause() instanceof RuntimeException) {
|
||||
@@ -122,7 +121,7 @@ public class MessageMappingMethodInvoker {
|
||||
}
|
||||
}
|
||||
|
||||
private Object doInvokeMethod(Method method, Object[] args, Message<?> message) throws Exception {
|
||||
private Object invokeMethod(Method method, Object[] args, Message<?> message) throws Exception {
|
||||
Object result = null;
|
||||
MethodInvoker invoker = null;
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.handler;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
|
||||
/**
|
||||
* This defines the lowest-level strategy of processing a Message and returning
|
||||
* some Object (or null). Implementations will be focused on generic concerns,
|
||||
* such as invoking a method, running a script, or evaluating an expression.
|
||||
* <p>
|
||||
* Higher level MessageHandler implementations can delegate to these processors
|
||||
* for such functionality, but it is the responsibility of each handler type to
|
||||
* add the semantics such as routing, splitting, transforming, etc.
|
||||
* <p>
|
||||
* In some cases the return value might be a Message itself, but it does not
|
||||
* need to be. It is the responsibility of the caller to determine how to treat
|
||||
* the return value. That may require creating a Message or even creating
|
||||
* multiple Messages from that value.
|
||||
* <p>
|
||||
* This strategy and its various implementations are considered part of the
|
||||
* internal "support" API, intended for use by Spring Integration's various
|
||||
* message-handling components. As such, it is subject to change.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface MessageProcessor {
|
||||
|
||||
/**
|
||||
* Process the Message and return a value (or null).
|
||||
*/
|
||||
Object processMessage(Message<?> message);
|
||||
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class MethodInvokingMessageHandler extends MessageMappingMethodInvoker im
|
||||
}
|
||||
|
||||
public void handleMessage(Message<?> message) {
|
||||
Object result = this.invokeMethod(message);
|
||||
Object result = this.processMessage(message);
|
||||
if (result != null) {
|
||||
throw new MessagingException(message, "the MethodInvokingMessageHandler method must "
|
||||
+ "have a void return, but '" + this + "' received a value: [" + result + "]");
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ServiceActivatingHandler extends AbstractReplyProducingMessageHandl
|
||||
@Override
|
||||
protected void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) {
|
||||
try {
|
||||
Object result = this.invoker.invokeMethod(message);
|
||||
Object result = this.invoker.processMessage(message);
|
||||
if (result != null) {
|
||||
replyHolder.set(result);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class MethodInvokingRouter extends AbstractChannelNameResolvingMessageRou
|
||||
|
||||
@Override
|
||||
protected List<Object> getChannelIndicatorList(Message<?> message) {
|
||||
Object result = this.invoker.invokeMethod(message);
|
||||
Object result = this.invoker.processMessage(message);
|
||||
List<Object> asList = new ArrayList<Object>();
|
||||
asList.add(result);
|
||||
return asList;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MethodInvokingSplitter extends AbstractMessageSplitter {
|
||||
|
||||
@Override
|
||||
protected Object splitMessage(Message<?> message) {
|
||||
return this.invoker.invokeMethod(message);
|
||||
return this.invoker.processMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.handler.MessageMappingMethodInvoker;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
|
||||
@@ -30,25 +31,25 @@ import org.springframework.integration.message.MessageHandlingException;
|
||||
*/
|
||||
public class MethodInvokingTransformer implements Transformer {
|
||||
|
||||
private final MessageMappingMethodInvoker invoker;
|
||||
private final MessageProcessor messageProcessor;
|
||||
|
||||
|
||||
public MethodInvokingTransformer(Object object, Method method) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, method);
|
||||
this.messageProcessor = new MessageMappingMethodInvoker(object, method);
|
||||
}
|
||||
|
||||
public MethodInvokingTransformer(Object object, String methodName) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object, methodName);
|
||||
this.messageProcessor = new MessageMappingMethodInvoker(object, methodName);
|
||||
}
|
||||
|
||||
public MethodInvokingTransformer(Object object) {
|
||||
this.invoker = new MessageMappingMethodInvoker(object,
|
||||
this.messageProcessor = new MessageMappingMethodInvoker(object,
|
||||
org.springframework.integration.annotation.Transformer.class);
|
||||
}
|
||||
|
||||
|
||||
public Message<?> transform(Message<?> message) {
|
||||
Object result = this.invoker.invokeMethod(message);
|
||||
Object result = this.messageProcessor.processMessage(message);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user