Merge pull request #339 from garyrussell/INT-2414
INT-2414 Error When container-class Supplied
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -24,7 +24,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
|||||||
import org.springframework.beans.factory.xml.ParserContext;
|
import org.springframework.beans.factory.xml.ParserContext;
|
||||||
import org.springframework.integration.config.xml.AbstractChannelParser;
|
import org.springframework.integration.config.xml.AbstractChannelParser;
|
||||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||||
import org.springframework.util.Assert;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,6 +32,7 @@ import org.springframework.util.StringUtils;
|
|||||||
*
|
*
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
* @author Oleg Zhurakusky
|
* @author Oleg Zhurakusky
|
||||||
|
* @author Gary Russell
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class JmsChannelParser extends AbstractChannelParser {
|
public class JmsChannelParser extends AbstractChannelParser {
|
||||||
@@ -65,20 +65,23 @@ public class JmsChannelParser extends AbstractChannelParser {
|
|||||||
}
|
}
|
||||||
String containerType = element.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
|
String containerType = element.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
|
||||||
String containerClass = element.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
|
String containerClass = element.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
|
||||||
Assert.isTrue(!(StringUtils.hasText(containerType) && StringUtils.hasText(containerClass)),
|
if (!StringUtils.hasText(containerClass)) {
|
||||||
"At most one of '" + CONTAINER_TYPE_ATTRIBUTE + "' or '" + CONTAINER_CLASS_ATTRIBUTE + "' may be configured.");
|
if ("default".equals(containerType)) {
|
||||||
if ("default".equals(containerType)) {
|
containerClass = "org.springframework.jms.listener.DefaultMessageListenerContainer";
|
||||||
containerClass = "org.springframework.jms.listener.DefaultMessageListenerContainer";
|
}
|
||||||
}
|
else if ("simple".equals(containerType)) {
|
||||||
else if ("simple".equals(containerType)) {
|
containerClass = "org.springframework.jms.listener.SimpleMessageListenerContainer";
|
||||||
containerClass = "org.springframework.jms.listener.SimpleMessageListenerContainer";
|
|
||||||
}
|
|
||||||
if (StringUtils.hasText(containerClass)) {
|
|
||||||
builder.addPropertyValue("containerType", containerClass);
|
|
||||||
if (containerClass.contains("DefaultMessageListenerContainer")) {
|
|
||||||
containerType = "default";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* Schema docs tell the user to ensure that, if they supply a container-class, it
|
||||||
|
* is their responsibility to set the container-type appropriately, based on the superclass
|
||||||
|
* of their implementation (default="default"). If it is set incorrectly, some attributes
|
||||||
|
* may not be applied.
|
||||||
|
*
|
||||||
|
* We cannot reliably infer it here.
|
||||||
|
*/
|
||||||
|
builder.addPropertyValue("containerType", containerClass);
|
||||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout");
|
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout");
|
||||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
|
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
|
||||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "transaction-manager");
|
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "transaction-manager");
|
||||||
|
|||||||
@@ -59,9 +59,19 @@
|
|||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<alias name="connectionFactory" alias="connFact"/>
|
<alias name="connectionFactory" alias="connFact"/>
|
||||||
|
|
||||||
|
|
||||||
<jms:channel id="withPlaceholders" queue="${queue}"
|
<jms:channel id="withPlaceholders" queue="${queue}"
|
||||||
concurrency="${concurrency}"/>
|
concurrency="${concurrency}"/>
|
||||||
|
|
||||||
|
<jms:channel id="withDefaultContainer" queue-name="default.container.queue" />
|
||||||
|
|
||||||
|
<jms:channel id="withExplicitDefaultContainer" queue-name="explicit.default.container.queue"
|
||||||
|
container-type="default" />
|
||||||
|
|
||||||
|
<jms:channel id="withSimpleContainer" queue-name="simple.container.queue"
|
||||||
|
container-type="simple"/>
|
||||||
|
|
||||||
|
<jms:channel id="withContainerClass" queue-name="custom.container.queue"
|
||||||
|
container-class="org.springframework.integration.jms.config.JmsChannelParserTests$CustomTestMessageListenerContainer" />
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2012 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -29,7 +29,6 @@ import javax.jms.Topic;
|
|||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.DirectFieldAccessor;
|
import org.springframework.beans.DirectFieldAccessor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.support.AbstractApplicationContext;
|
import org.springframework.context.support.AbstractApplicationContext;
|
||||||
@@ -42,12 +41,14 @@ import org.springframework.integration.test.util.TestUtils;
|
|||||||
import org.springframework.jms.core.JmsTemplate;
|
import org.springframework.jms.core.JmsTemplate;
|
||||||
import org.springframework.jms.listener.AbstractMessageListenerContainer;
|
import org.springframework.jms.listener.AbstractMessageListenerContainer;
|
||||||
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
import org.springframework.jms.listener.DefaultMessageListenerContainer;
|
||||||
|
import org.springframework.jms.listener.SimpleMessageListenerContainer;
|
||||||
import org.springframework.jms.support.destination.DestinationResolver;
|
import org.springframework.jms.support.destination.DestinationResolver;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mark Fisher
|
* @author Mark Fisher
|
||||||
|
* @author Gary Russell
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@@ -95,6 +96,18 @@ public class JmsChannelParserTests {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private Topic topic;
|
private Topic topic;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageChannel withDefaultContainer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageChannel withExplicitDefaultContainer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageChannel withSimpleContainer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MessageChannel withContainerClass;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AbstractApplicationContext context;
|
private AbstractApplicationContext context;
|
||||||
|
|
||||||
@@ -231,6 +244,38 @@ public class JmsChannelParserTests {
|
|||||||
System.out.println(container.getMaxConcurrentConsumers());
|
System.out.println(container.getMaxConcurrentConsumers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withDefaultContainer() {
|
||||||
|
DefaultMessageListenerContainer container = TestUtils.getPropertyValue(
|
||||||
|
withDefaultContainer, "container",
|
||||||
|
DefaultMessageListenerContainer.class);
|
||||||
|
assertEquals("default.container.queue", container.getDestinationName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withExplicitDefaultContainer() {
|
||||||
|
DefaultMessageListenerContainer container = TestUtils.getPropertyValue(
|
||||||
|
withExplicitDefaultContainer, "container",
|
||||||
|
DefaultMessageListenerContainer.class);
|
||||||
|
assertEquals("explicit.default.container.queue", container.getDestinationName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withSimpleContainer() {
|
||||||
|
SimpleMessageListenerContainer container = TestUtils.getPropertyValue(
|
||||||
|
withSimpleContainer, "container",
|
||||||
|
SimpleMessageListenerContainer.class);
|
||||||
|
assertEquals("simple.container.queue", container.getDestinationName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void withContainerClass() {
|
||||||
|
CustomTestMessageListenerContainer container = TestUtils.getPropertyValue(
|
||||||
|
withContainerClass, "container",
|
||||||
|
CustomTestMessageListenerContainer.class);
|
||||||
|
assertEquals("custom.container.queue", container.getDestinationName());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static class TestDestinationResolver implements DestinationResolver {
|
static class TestDestinationResolver implements DestinationResolver {
|
||||||
|
|
||||||
@@ -253,4 +298,8 @@ public class JmsChannelParserTests {
|
|||||||
static class TestInterceptor extends ChannelInterceptorAdapter {
|
static class TestInterceptor extends ChannelInterceptorAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class CustomTestMessageListenerContainer extends DefaultMessageListenerContainer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user