diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java index 6f06dfd7fe..c0d522a7a3 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/inbound/AmqpInboundGateway.java @@ -25,6 +25,7 @@ import org.springframework.amqp.core.MessageListener; import org.springframework.amqp.core.MessagePostProcessor; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer; +import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.SimpleMessageConverter; import org.springframework.integration.amqp.support.AmqpHeaderMapper; import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper; @@ -45,7 +46,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { private final AbstractMessageListenerContainer messageListenerContainer; - private final SimpleMessageConverter messageConverter = new SimpleMessageConverter(); + private volatile MessageConverter amqpMessageConverter = new SimpleMessageConverter(); private volatile AmqpHeaderMapper headerMapper = new DefaultAmqpHeaderMapper(); @@ -62,6 +63,12 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { } + public void setMessageConverter(MessageConverter messageConverter) { + Assert.notNull(messageConverter, "MessageConverter must not be null"); + this.amqpMessageConverter = messageConverter; + this.amqpTemplate.setMessageConverter(messageConverter); + } + public void setHeaderMapper(AmqpHeaderMapper headerMapper) { Assert.notNull(headerMapper, "headerMapper must not be null"); this.headerMapper = headerMapper; @@ -71,7 +78,7 @@ public class AmqpInboundGateway extends MessagingGatewaySupport { protected void onInit() throws Exception { this.messageListenerContainer.setMessageListener(new MessageListener() { public void onMessage(Message message) { - Object payload = messageConverter.fromMessage(message); + Object payload = amqpMessageConverter.fromMessage(message); Map headers = headerMapper.toHeaders(message.getMessageProperties()); org.springframework.integration.Message request = MessageBuilder.withPayload(payload).copyHeaders(headers).build(); diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests-context.xml b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests-context.xml new file mode 100644 index 0000000000..a8246faa01 --- /dev/null +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests-context.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java new file mode 100644 index 0000000000..40b31187fa --- /dev/null +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpInboundGatewayParserTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2002-2011 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.amqp.config; + +import static org.junit.Assert.assertSame; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.amqp.support.converter.SimpleMessageConverter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.integration.test.util.TestUtils; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Mark Fisher + * @since 2.1 + */ +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class AmqpInboundGatewayParserTests { + + @Autowired + private ApplicationContext context; + + @Test + public void customMessageConverter() { + Object gateway = context.getBean("gateway"); + MessageConverter gatewayConverter = TestUtils.getPropertyValue(gateway, "amqpMessageConverter", MessageConverter.class); + MessageConverter templateConverter = TestUtils.getPropertyValue(gateway, "amqpTemplate.messageConverter", MessageConverter.class); + TestConverter testConverter = context.getBean("testConverter", TestConverter.class); + assertSame(testConverter, gatewayConverter); + assertSame(testConverter, templateConverter); + } + + + private static class TestConverter extends SimpleMessageConverter {} + +}