INT-3790: Fix Parser for ROLE attribute usage

JIRA: https://jira.spring.io/browse/INT-3790
This commit is contained in:
Artem Bilan
2015-08-08 00:05:09 -04:00
committed by Gary Russell
parent f73898ba8b
commit 56bfe6b0ac
4 changed files with 32 additions and 39 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.util.StringUtils;
* @author Mark Fisher
* @author Michael Bannister
* @author Gary Russell
* @author Artem Bilan
*/
public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinitionParser {
@@ -121,6 +122,13 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
builder.addConstructorArgValue(hasExternalContainer(element));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
String role = element.getAttribute(IntegrationNamespaceUtils.ROLE);
if (StringUtils.hasText(role)) {
if (!StringUtils.hasText(element.getAttribute(ID_ATTRIBUTE))) {
parserContext.getReaderContext().error("When using 'role', 'id' is required", element);
}
IntegrationNamespaceUtils.putLifecycleInRole(role, element.getAttribute(ID_ATTRIBUTE), parserContext);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "acknowledge", "sessionAcknowledgeMode");
}
@@ -170,8 +178,8 @@ public class JmsMessageDrivenEndpointParser extends AbstractSingleBeanDefinition
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, pubSubDomainAttribute, "pubSubDomain");
}
if (StringUtils.hasText(element.getAttribute("subsription-name"))
&& StringUtils.hasText(element.getAttribute("durable-subsription-name"))) {
if (StringUtils.hasText(element.getAttribute("subscription-name"))
&& StringUtils.hasText(element.getAttribute("durable-subscription-name"))) {
parserContext.getReaderContext().error(
"Only one of 'subscription-name' or 'durable-subscription-name' is allowed.", element);
}

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.jms.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
@@ -31,9 +32,11 @@ import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.NotReadablePropertyException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.jms.JmsMessageDrivenEndpoint;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.core.JmsTemplate;
@@ -42,10 +45,12 @@ import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.support.destination.JmsDestinationAccessor;
import org.springframework.messaging.Message;
import org.springframework.messaging.PollableChannel;
import org.springframework.util.MultiValueMap;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
*/
public class JmsInboundGatewayParserTests {
@@ -315,7 +320,14 @@ public class JmsInboundGatewayParserTests {
public void testGatewayWithContainerReference() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"inboundGatewayWithContainerReference.xml", this.getClass());
JmsMessageDrivenEndpoint gateway = (JmsMessageDrivenEndpoint) context.getBean("gatewayWithContainerReference");
JmsMessageDrivenEndpoint gateway =
context.getBean("gatewayWithContainerReference", JmsMessageDrivenEndpoint.class);
SmartLifecycleRoleController roleController = context.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
MultiValueMap<String, SmartLifecycle> lifecycles =
TestUtils.getPropertyValue(roleController, "lifecycles", MultiValueMap.class);
assertTrue(lifecycles.containsKey("foo"));
assertSame(gateway, lifecycles.getFirst("foo"));
gateway.start();
AbstractMessageListenerContainer container = (AbstractMessageListenerContainer)
new DirectFieldAccessor(gateway).getPropertyValue("listenerContainer");

View File

@@ -17,6 +17,7 @@
<jms:inbound-gateway id="gatewayWithContainerReference"
container="messageListenerContainer"
request-channel="requestChannel"
role="foo"
auto-startup="false"/>
<bean id="testConnectionFactory" class="org.springframework.jms.connection.SingleConnectionFactory">

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 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.
@@ -18,60 +18,32 @@ package org.springframework.integration.websocket.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractChannelAdapterParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter;
import org.springframework.util.StringUtils;
/**
* The {@link AbstractSingleBeanDefinitionParser} implementation for
* the {@code <websocket:inbound-channel-adapter/>} element.
* The {@link AbstractChannelAdapterParser} implementation for
* the {@code <int-websocket:inbound-channel-adapter/>} element.
*
* @author Artem Bilan
* @since 4.1
*/
public class WebSocketInboundChannelAdapterParser extends AbstractSingleBeanDefinitionParser {
public class WebSocketInboundChannelAdapterParser extends AbstractChannelAdapterParser {
@Override
protected Class<?> getBeanClass(Element element) {
return WebSocketInboundChannelAdapter.class;
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String id = super.resolveId(element, definition, parserContext);
if (!element.hasAttribute("channel")) {
// the created channel will get the 'id', so the adapter's bean name includes a suffix
id = id + ".adapter";
}
if (!StringUtils.hasText(id)) {
id = BeanDefinitionReaderUtils.generateBeanName(definition, parserContext.getRegistry());
}
return id;
}
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(WebSocketInboundChannelAdapter.class);
WebSocketAdapterParsingUtils.configureWebSocketAdapter(builder, parserContext, element);
String channelName = element.getAttribute("channel");
if (!StringUtils.hasText(channelName)) {
channelName = IntegrationNamespaceUtils.createDirectChannel(element, parserContext);
}
builder.addPropertyReference("outputChannel", channelName);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "payload-type");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.AUTO_STARTUP);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, IntegrationNamespaceUtils.PHASE);
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "use-broker");
return builder.getBeanDefinition();
}
}