diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
index 152397f468..add7805133 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/util/BeanFactoryTypeConverter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 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,10 +27,13 @@ import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.ConversionServiceFactory;
import org.springframework.expression.TypeConverter;
+import org.springframework.integration.MessageHeaders;
+import org.springframework.integration.history.MessageHistory;
/**
* @author Dave Syer
* @author Oleg Zhurakousky
+ * @author Gary Russell
*/
public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware {
@@ -98,6 +101,18 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
if ((targetType.getType() == Void.class || targetType.getType() == Void.TYPE) && value == null) {
return null;
}
+ /*
+ * INT-2630 Spring 3.1 now converts ALL arguments; we know we don't need to convert MessageHeaders
+ * or MessageHistory; the MapToMap converter requires a no-arg constructor.
+ */
+ if (sourceType != null && sourceType.getType() == MessageHeaders.class
+ && targetType.getType() == MessageHeaders.class) {
+ return value;
+ }
+ if (sourceType != null && sourceType.getType() == MessageHistory.class
+ && targetType.getType() == MessageHistory.class) {
+ return value;
+ }
if (conversionService.canConvert(sourceType, targetType)) {
return conversionService.convert(value, sourceType, targetType);
}
@@ -109,7 +124,7 @@ public class BeanFactoryTypeConverter implements TypeConverter, BeanFactoryAware
if (editor != null) { // INT-1441
editor.setValue(value);
String text = editor.getAsText();
- if (String.class.isAssignableFrom(targetType.getClass())) {
+ if (String.class.isAssignableFrom(targetType.getClass())) {
return text;
}
return convertValue(text, TypeDescriptor.valueOf(String.class), targetType);
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests-context.xml
new file mode 100644
index 0000000000..35a5edfea1
--- /dev/null
+++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests-context.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests.java
new file mode 100644
index 0000000000..71aa7afb36
--- /dev/null
+++ b/spring-integration-core/src/test/java/org/springframework/integration/transformer/MessageHistoryParameterTests.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2002-2012 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.transformer;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.integration.MessageChannel;
+import org.springframework.integration.MessageHeaders;
+import org.springframework.integration.annotation.Header;
+import org.springframework.integration.annotation.Headers;
+import org.springframework.integration.annotation.Payload;
+import org.springframework.integration.annotation.Transformer;
+import org.springframework.integration.core.PollableChannel;
+import org.springframework.integration.history.MessageHistory;
+import org.springframework.integration.message.GenericMessage;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Gary Russell
+ * @since 2.2
+ *
+ */
+@ContextConfiguration
+@RunWith(SpringJUnit4ClassRunner.class)
+public class MessageHistoryParameterTests {
+
+ @Autowired
+ private MessageChannel input;
+
+ @Autowired
+ private PollableChannel output;
+
+ @Test
+ public void test() {
+ input.send(new GenericMessage("foo"));
+ assertNotNull(output.receive(10000));
+ }
+
+ public static class MessageHistoryAwareTransformer {
+
+ @Transformer
+ public Object transform(@Headers MessageHeaders headers,
+ @Header("history") MessageHistory history, @Payload Object payload) {
+
+ return payload;
+ }
+ }
+
+}
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java b/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java
index b4fc6bc64b..8cfafca517 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/util/BeanFactoryTypeConverterTests.java
@@ -1,9 +1,10 @@
/**
- *
+ *
*/
package org.springframework.integration.util;
import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
import java.util.ArrayList;
import java.util.Arrays;
@@ -13,6 +14,11 @@ import java.util.List;
import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.convert.TypeDescriptor;
+import org.springframework.integration.Message;
+import org.springframework.integration.MessageHeaders;
+import org.springframework.integration.context.NamedComponent;
+import org.springframework.integration.history.MessageHistory;
+import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
@@ -25,7 +31,7 @@ public class BeanFactoryTypeConverterTests {
public void testEmptyCollectionConversion(){
BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
List sourceObject = new ArrayList();
- ArrayList convertedCollection =
+ ArrayList convertedCollection =
(ArrayList) typeConverter.convertValue(sourceObject, TypeDescriptor.forObject(sourceObject), TypeDescriptor.forObject(new ArrayList()));
assertEquals(sourceObject, convertedCollection);
}
@@ -47,4 +53,29 @@ public class BeanFactoryTypeConverterTests {
assertEquals(Arrays.asList(1234), converted);
}
+ @Test
+ public void testMessageHeadersNotConverted() {
+ BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
+ typeConverter.setBeanFactory(new DefaultListableBeanFactory());
+ MessageHeaders headers = new GenericMessage("foo").getHeaders();
+ assertSame(headers, typeConverter.convertValue(headers, TypeDescriptor.valueOf(MessageHeaders.class), TypeDescriptor.valueOf(MessageHeaders.class)));
+ }
+
+ @Test
+ public void testMessageHistoryNotConverted() {
+ BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
+ typeConverter.setBeanFactory(new DefaultListableBeanFactory());
+ Message message = new GenericMessage("foo");
+ message = MessageHistory.write(message, new NamedComponent(){
+ public String getComponentName() {
+ return "bar";
+ }
+
+ public String getComponentType() {
+ return "baz";
+ }
+ });
+ MessageHistory history = MessageHistory.read(message);
+ assertSame(history, typeConverter.convertValue(history, TypeDescriptor.valueOf(MessageHeaders.class), TypeDescriptor.valueOf(MessageHeaders.class)));
+ }
}