diff --git a/spring-integration-jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java b/spring-integration-jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java index 2e1ede4682..f15440ce3e 100644 --- a/spring-integration-jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java +++ b/spring-integration-jms/src/main/java/org/springframework/integration/jms/AbstractJmsTemplateBasedAdapter.java @@ -191,21 +191,13 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS && (this.destination != null || this.destinationName != null), "Either a 'jmsTemplate' or *both* 'connectionFactory' and" + " 'destination' (or 'destination-name') are required."); - this.jmsTemplate = this.createDefaultJmsTemplate(); + this.jmsTemplate = this.createJmsTemplate(); } - this.jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled); - this.jmsTemplate.setTimeToLive(this.timeToLive); - this.jmsTemplate.setPriority(this.priority); - this.jmsTemplate.setDeliveryMode(this.deliveryMode); - if (this.messageConverter != null) { - this.jmsTemplate.setMessageConverter(this.messageConverter); - } - //this.configureMessageConverter(this.jmsTemplate); this.initialized = true; } } - private JmsTemplate createDefaultJmsTemplate() { + private JmsTemplate createJmsTemplate() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setConnectionFactory(this.connectionFactory); if (this.destination != null) { @@ -218,16 +210,18 @@ public abstract class AbstractJmsTemplateBasedAdapter extends IntegrationObjectS if (this.destinationResolver != null) { jmsTemplate.setDestinationResolver(this.destinationResolver); } + jmsTemplate.setExplicitQosEnabled(this.explicitQosEnabled); + jmsTemplate.setTimeToLive(this.timeToLive); + jmsTemplate.setPriority(this.priority); + jmsTemplate.setDeliveryMode(this.deliveryMode); + if (this.messageConverter != null) { + jmsTemplate.setMessageConverter(this.messageConverter); + } return jmsTemplate; } -// protected void configureMessageConverter(JmsTemplate jmsTemplate) { -// MessageConverter converter = jmsTemplate.getMessageConverter(); -// if (converter == null) { -// jmsTemplate.setMessageConverter(new SimpleMessageConverter()); -// } -// } protected boolean shouldExtractPayload() { return extractPayload; } + } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExceptionHandlingSiConsumerTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExceptionHandlingSiConsumerTests.java index ee09b2a3d6..4eddd20e73 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExceptionHandlingSiConsumerTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/ExceptionHandlingSiConsumerTests.java @@ -13,8 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.jms.config; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import javax.jms.ConnectionFactory; import javax.jms.Destination; import javax.jms.JMSException; @@ -22,9 +26,8 @@ import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; -import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.mapping.InboundMessageMapper; @@ -55,10 +58,10 @@ public class ExceptionHandlingSiConsumerTests { } }); Message message = jmsTemplate.receive(reply); - System.out.println(message); - Assert.assertNotNull(message); + assertNotNull(message); applicationContext.close(); } + @Test public void nonSiProducer_siConsumer_sync_withReturnNoException() throws Exception { ActiveMqTestUtils.prepare(); @@ -76,7 +79,8 @@ public class ExceptionHandlingSiConsumerTests { } }); Message message = jmsTemplate.receive(reply); - Assert.assertNotNull(message); + assertNotNull(message); + assertEquals("echoWithException", ((TextMessage) message).getText()); applicationContext.close(); } @@ -86,35 +90,40 @@ public class ExceptionHandlingSiConsumerTests { final ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext("Exception-nonSiProducer-siConsumer.xml", ExceptionHandlingSiConsumerTests.class); SampleGateway gateway = applicationContext.getBean("sampleGateway", SampleGateway.class); String reply = gateway.echo("echoWithExceptionChannel"); - System.out.println("Reply: " + reply); + assertEquals("echoWithException", reply); applicationContext.close(); } -// - public static class SampleService{ - public String echoWithException(String value){ + + + public static class SampleService { + + public String echoWithException(String value) { throw new SampleException("echoWithException"); } + public String echo(String value){ return value; } } - - + + @SuppressWarnings("serial") - public static class SampleException extends RuntimeException{ + public static class SampleException extends RuntimeException { public SampleException(String message){ super(message); } } - - public static interface SampleGateway{ + + + public static interface SampleGateway { public String echo(String value); } - - public static class SampleErrorMessageMapper implements InboundMessageMapper{ - public org.springframework.integration.Message toMessage( - Throwable t) throws Exception { + + + public static class SampleErrorMessageMapper implements InboundMessageMapper { + public org.springframework.integration.Message toMessage(Throwable t) throws Exception { return MessageBuilder.withPayload(t.getCause().getMessage()).build(); } } + } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java index b1733a89ca..4e78ba5683 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsMessageHistoryTests.java @@ -58,7 +58,6 @@ public class JmsMessageHistoryTests { assertEquals("jms:inbound-channel-adapter", event1.getProperty(MessageHistory.TYPE_PROPERTY)); assertEquals("sampleJmsInboundAdapter", event1.getProperty(MessageHistory.NAME_PROPERTY)); Properties event2 = historyIterator.next(); - System.out.println(event2); assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY)); assertEquals("jmsInputChannel", event2.getProperty(MessageHistory.NAME_PROPERTY)); } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java index 912c02f04e..40be26a252 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsOutboundChannelAdapterParserTests.java @@ -101,6 +101,20 @@ public class JmsOutboundChannelAdapterParserTests { assertEquals(context.getBean("template"), jmsTemplate); } + @Test + public void adapterWithJmsTemplateQos() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "jmsOutboundWithJmsTemplateQos.xml", this.getClass()); + EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("adapter"); + DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler")); + JmsTemplate jmsTemplate = (JmsTemplate) handlerAccessor.getPropertyValue("jmsTemplate"); + assertNotNull(jmsTemplate); + assertEquals(context.getBean("template"), jmsTemplate); + assertTrue(jmsTemplate.isExplicitQosEnabled()); + assertEquals(7, jmsTemplate.getPriority()); + assertEquals(12345, jmsTemplate.getTimeToLive()); + } + @Test public void adapterWithMessageConverter() { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsOutboundWithJmsTemplateQos.xml b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsOutboundWithJmsTemplateQos.xml new file mode 100644 index 0000000000..77bb36941f --- /dev/null +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/jmsOutboundWithJmsTemplateQos.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + +