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..3a343a1347 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 e4cf1644a7..f478a932ac 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 @@ -1413,14 +1413,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. + + @@ -1515,16 +1517,6 @@ endpoint itself is a Polling Consumer for a channel with a queue. - - - - - - - - - - diff --git a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.1.xsd b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.1.xsd index 943215f816..f8d7763f55 100644 --- a/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.1.xsd +++ b/spring-integration-core/src/main/resources/org/springframework/integration/config/xml/spring-integration-2.1.xsd @@ -1638,14 +1638,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. + + @@ -1654,7 +1656,7 @@ endpoint itself is a Polling Consumer for a channel with a queue. an existing header value for the same name. - + @@ -1740,16 +1742,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..9330f2a066 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..1f3d90eb3f 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..92c8f9c61f 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 @@ -35,6 +35,11 @@ import org.springframework.integration.support.MessageBuilder; * @author Mark Fisher */ public class MessageBuilderTests { + + @Test(expected= IllegalArgumentException.class) // priority must be an Integer + public void testPriorityHeader(){ + MessageBuilder.withPayload("ha").setHeader("priority", "10").build(); + } @Test public void testSimpleMessageCreation() { diff --git a/src/reference/docbook/channel.xml b/src/reference/docbook/channel.xml index 192c5a56fe..7f6a3151e4 100644 --- a/src/reference/docbook/channel.xml +++ b/src/reference/docbook/channel.xml @@ -596,7 +596,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/src/reference/docbook/message.xml b/src/reference/docbook/message.xml index 7c846ffbbe..a207ada0eb 100644 --- a/src/reference/docbook/message.xml +++ b/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.