diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/DefaultMessageHandlerAdapter.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/DefaultMessageHandlerAdapter.java
index e7eae7c9e0..276534a842 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/handler/DefaultMessageHandlerAdapter.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/DefaultMessageHandlerAdapter.java
@@ -16,25 +16,41 @@
package org.springframework.integration.handler;
-import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.Ordered;
import org.springframework.integration.message.Message;
-import org.springframework.integration.message.MessageMapper;
import org.springframework.integration.util.SimpleMethodInvoker;
/**
* An implementation of {@link MessageHandler} that invokes the specified method
- * on the provided target object. It then uses a {@link MessageMapper} strategy
- * for converting the object to a {@link Message}. If the method has a non-null
- * return value, a reply message will be generated by the mapper.
+ * on the provided target object. If {@link #shouldUseMapperOnInvocation} is set
+ * to true (the default), it will use the provided
+ * {@link org.springframework.integration.message.MessageMapper} strategy to
+ * convert the inbound {@link Message} to an object that will be passed as the
+ * method parameter. If the method has a non-null return value, a reply message
+ * will be generated by the mapper.
*
* @author Mark Fisher
*/
-public class DefaultMessageHandlerAdapter extends AbstractMessageHandlerAdapter
- implements Ordered, InitializingBean {
+public class DefaultMessageHandlerAdapter extends AbstractMessageHandlerAdapter implements Ordered {
+
+ private boolean shouldUseMapperOnInvocation = true;
+
+
+ /**
+ * Specify whether the handler method should use the
+ * {@link org.springframework.integration.message.MessageMapper} when
+ * invoking the target method. Default is true. To force
+ * passing the {@link Message} directly, set this to false.
+ */
+ public void setShouldUseMapperOnInvocation(boolean shouldUseMapperOnInvocation) {
+ this.shouldUseMapperOnInvocation = shouldUseMapperOnInvocation;
+ }
public Object doHandle(Message message, SimpleMethodInvoker invoker) {
- return invoker.invokeMethod(this.getMapper().fromMessage(message));
+ if (this.shouldUseMapperOnInvocation) {
+ return invoker.invokeMethod(this.getMapper().fromMessage(message));
+ }
+ return invoker.invokeMethod(message);
}
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/config/AbstractMessageHandlerCreator.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/config/AbstractMessageHandlerCreator.java
index 56aa3c3ce3..6debd75e1d 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/handler/config/AbstractMessageHandlerCreator.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/config/AbstractMessageHandlerCreator.java
@@ -19,8 +19,10 @@ package org.springframework.integration.handler.config;
import java.lang.reflect.Method;
import java.util.Map;
+import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
+import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.handler.AbstractMessageHandlerAdapter;
import org.springframework.integration.handler.MessageHandler;
@@ -43,6 +45,14 @@ public abstract class AbstractMessageHandlerCreator implements MessageHandlerCre
adapter.setOrder(orderAnnotation.value());
}
}
+ if (handler instanceof InitializingBean) {
+ try {
+ ((InitializingBean) handler).afterPropertiesSet();
+ }
+ catch (Exception e) {
+ throw new MessagingConfigurationException("failed to initialize handler", e);
+ }
+ }
return handler;
}
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/config/DefaultMessageHandlerCreator.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/config/DefaultMessageHandlerCreator.java
index f767594b25..4a05bbf46d 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/handler/config/DefaultMessageHandlerCreator.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/config/DefaultMessageHandlerCreator.java
@@ -20,8 +20,10 @@ import java.lang.reflect.Method;
import java.util.Map;
import org.springframework.core.annotation.Order;
+import org.springframework.integration.MessagingConfigurationException;
import org.springframework.integration.handler.DefaultMessageHandlerAdapter;
import org.springframework.integration.handler.MessageHandler;
+import org.springframework.integration.message.Message;
/**
* Default implementation of the handler creator strategy that creates a
@@ -34,7 +36,14 @@ import org.springframework.integration.handler.MessageHandler;
public class DefaultMessageHandlerCreator extends AbstractMessageHandlerCreator {
public MessageHandler doCreateHandler(Object object, Method method, Map attributes) {
- return new DefaultMessageHandlerAdapter