diff --git a/docs/src/reference/docbook/channel.xml b/docs/src/reference/docbook/channel.xml
index e6a0fd27c7..665213d65c 100644
--- a/docs/src/reference/docbook/channel.xml
+++ b/docs/src/reference/docbook/channel.xml
@@ -582,7 +582,7 @@ payload to an Integer.
]]>
- By default, the channel will consult the MessagePriority header of the
+ By default, the channel will consult the priority header of the
message. However, a custom Comparator reference may be
provided instead. Also, note that the PriorityChannel (like the other types)
does support the datatype attribute. As with the QueueChannel, it also supports a capacity attribute.
diff --git a/docs/src/reference/docbook/message.xml b/docs/src/reference/docbook/message.xml
index 7ededb5be1..267460ba6d 100644
--- a/docs/src/reference/docbook/message.xml
+++ b/docs/src/reference/docbook/message.xml
@@ -106,7 +106,7 @@
PRIORITY
- MessagePriority (an enum)
+ java.lang.Integer
@@ -190,28 +190,21 @@ assertEquals(123, message4.getHeaders().get("foo"));
Finally, there are set methods available for the predefined headers as well as a non-destructive method for
setting any header (MessageHeaders also defines constants for the pre-defined header names).
Message<Integer> importantMessage = MessageBuilder.withPayload(99)
- .setPriority(MessagePriority.HIGHEST)
+ .setPriority(5)
.build();
-assertEquals(MessagePriority.HIGHEST, importantMessage.getHeaders().getPriority());
+assertEquals(5, importantMessage.getHeaders().getPriority());
-Message<Integer> anotherMessage = MessageBuilder.fromMessage(importantMessage)
- .setHeaderIfAbsent(MessageHeaders.PRIORITY, MessagePriority.LOW)
+Message<Integer> lessImportantMessage = MessageBuilder.fromMessage(importantMessage)
+ .setHeaderIfAbsent(MessageHeaders.PRIORITY, 2)
.build();
-assertEquals(MessagePriority.LOW, anotherMessage.getHeaders().getPriority());
+assertEquals(2, lessImportantMessage.getHeaders().getPriority());
- The MessagePriority is only considered when using a PriorityChannel
- (as described in the next chapter). It is defined as an enum with five possible values:
- public enum MessagePriority {
- HIGHEST,
- HIGH,
- NORMAL,
- LOW,
- LOWEST
-}
+ The priority header is only considered when using a PriorityChannel
+ (as described in the next chapter). It is defined as java.lang.Integer.
diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java
index b50b4bc42f..b64867b5d4 100644
--- a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java
+++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java
@@ -324,6 +324,10 @@ public final class MessageBuilder {
Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName
+ "' header value must be an Integer.");
}
+ else if (MessageHeaders.PRIORITY.equals(headerName)) {
+ Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName
+ + "' header value must be an Integer.)");
+ }
}
}
diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd
index 87d57ecd3e..f5764ddbd9 100644
--- a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd
+++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.0.xsd
@@ -1422,14 +1422,16 @@ endpoint itself is a Polling Consumer for a channel with a queue.
- Shortcut to specify value for 'priority' header when using PriotityChannel
+ Shortcut to specify value for 'priority' header when using PriorityChannel
-
-
-
+
+
+ Integer value identifying the value of the 'priority' header.
+
+
@@ -1524,16 +1526,6 @@ endpoint itself is a Polling Consumer for a channel with a queue.
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests-context.xml
index 20ab4cf9d5..1e4781cc15 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests-context.xml
+++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests-context.xml
@@ -22,5 +22,13 @@
+
+
+
+
+
+
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests.java
index 5a7f529668..9115123fe8 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/HeaderEnricherParserTests.java
@@ -16,17 +16,25 @@
package org.springframework.integration.config.xml;
-import static org.junit.Assert.assertEquals;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
+import org.springframework.integration.Message;
+import org.springframework.integration.channel.QueueChannel;
+import org.springframework.integration.core.MessageHandler;
+import org.springframework.integration.message.GenericMessage;
+import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
+import org.springframework.integration.transformer.MessageTransformationException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
/**
* @author Mark Fisher
* @since 2.0
@@ -73,5 +81,26 @@ public class HeaderEnricherParserTests {
Boolean shouldSkipNulls = TestUtils.getPropertyValue(endpoint, "handler.transformer.shouldSkipNulls", Boolean.class);
assertEquals(Boolean.TRUE, shouldSkipNulls);
}
-
+
+ @Test(expected=MessageTransformationException.class)
+ public void testStringPriorityHeader() {
+ MessageHandler messageHandler =
+ TestUtils.getPropertyValue(context.getBean("headerEnricherWithPriorityAsString"), "handler", MessageHandler.class);
+ Message> message = new GenericMessage("hello");
+ messageHandler.handleMessage(message);
+ }
+
+ @Test
+ public void testStringPriorityHeaderWithType() {
+ MessageHandler messageHandler =
+ TestUtils.getPropertyValue(context.getBean("headerEnricherWithPriorityAsStringAndType"), "handler", MessageHandler.class);
+ QueueChannel replyChannel = new QueueChannel();
+ Message> message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
+ messageHandler.handleMessage(message);
+ Message> transformed = replyChannel.receive(1000);
+ assertNotNull(transformed);
+ Object priority = transformed.getHeaders().get("priority");
+ assertNotNull(priority);
+ assertTrue(priority instanceof Integer);
+ }
}
diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/MessageBuilderTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageBuilderTests.java
index afa09e7f9b..03820b71c6 100644
--- a/spring-integration-core/src/test/java/org/springframework/integration/message/MessageBuilderTests.java
+++ b/spring-integration-core/src/test/java/org/springframework/integration/message/MessageBuilderTests.java
@@ -41,6 +41,11 @@ public class MessageBuilderTests {
Message message = MessageBuilder.withPayload("foo").build();
assertEquals("foo", message.getPayload());
}
+
+ @Test(expected= IllegalArgumentException.class) // priority must be an Integer
+ public void testPriorityHeader(){
+ MessageBuilder.withPayload("ha").setHeader("priority", "10").build();
+ }
@Test
public void testHeaderValues() {