From 9621a663fce9d5835f0b583f34ca684e06a63aa3 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sat, 12 Dec 2009 23:36:50 +0000 Subject: [PATCH] INT-837 The 'inbound-channel-adapter' element in the JMS namespace now accepts a MessageConverter reference. --- .../jms/JmsDestinationPollingSource.java | 9 +++++ .../JmsInboundChannelAdapterParser.java | 1 + .../jms/config/spring-integration-jms-2.0.xsd | 36 +++++------------ .../JmsInboundChannelAdapterParserTests.java | 20 ++++++++++ .../config/jmsInboundWithMessageConverter.xml | 39 +++++++++++++++++++ 5 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/jmsInboundWithMessageConverter.xml diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java index 242795e416..bf8156d8ca 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/JmsDestinationPollingSource.java @@ -60,6 +60,15 @@ public class JmsDestinationPollingSource extends AbstractJmsTemplateBasedAdapter this.messageSelector = messageSelector; } + /** + * Specify a MessageConverter to use when mapping from JMS Mesages to + * Spring Integration Messages. If it is not itself an implementation + * of {@link HeaderMappingMessageConverter}, it will be wrapped. + */ + public void setMessageConverter(MessageConverter messageConverter) { + this.getJmsTemplate().setMessageConverter(messageConverter); + } + /** * Specify whether the payload should be extracted from each received JMS * Message to be used as the Spring Integration Message payload. diff --git a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java index e6c30c052d..1e722f9df3 100644 --- a/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java +++ b/org.springframework.integration.jms/src/main/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParser.java @@ -78,6 +78,7 @@ public class JmsInboundChannelAdapterParser extends AbstractPollingInboundChanne if (StringUtils.hasText(headerMapper)) { builder.addPropertyReference(JmsAdapterParserUtils.HEADER_MAPPER_PROPERTY, headerMapper); } + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "selector", "messageSelector"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "extract-payload"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "destination-resolver"); diff --git a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd index 7e0371b153..7628a54d26 100644 --- a/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd +++ b/org.springframework.integration.jms/src/main/resources/org/springframework/integration/jms/config/spring-integration-jms-2.0.xsd @@ -131,15 +131,6 @@ - - - - - - - - - @@ -254,15 +245,6 @@ - - - - - - - - - @@ -373,15 +355,6 @@ - - - - - - - - - @@ -600,6 +573,15 @@ + + + + + + + + + diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java index 4efa6ab23f..8c47b700fa 100644 --- a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/JmsInboundChannelAdapterParserTests.java @@ -138,4 +138,24 @@ public class JmsInboundChannelAdapterParserTests { assertEquals("test [with selector: TestProperty = 'foo']", message.getPayload()); } + @Test + public void pollingAdapterWithMessageConverter() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "jmsInboundWithMessageConverter.xml", this.getClass()); + PollableChannel output = (PollableChannel) context.getBean("output1"); + Message message = output.receive(timeoutOnReceive); + assertNotNull("message should not be null", message); + assertEquals("converted-test", message.getPayload()); + } + + @Test + public void messageDrivenAdapterWithMessageConverter() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "jmsInboundWithMessageConverter.xml", this.getClass()); + PollableChannel output = (PollableChannel) context.getBean("output2"); + Message message = output.receive(timeoutOnReceive); + assertNotNull("message should not be null", message); + assertEquals("converted-test", message.getPayload()); + } + } diff --git a/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/jmsInboundWithMessageConverter.xml b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/jmsInboundWithMessageConverter.xml new file mode 100644 index 0000000000..661eac3539 --- /dev/null +++ b/org.springframework.integration.jms/src/test/java/org/springframework/integration/jms/config/jmsInboundWithMessageConverter.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +