From ea080e8a9b35324fd52355e3e4609d15dccde49a Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 5 Feb 2014 13:57:40 +0200 Subject: [PATCH] INT-3284: Add 'spring.factories' Infrastructure JIRA: https://jira.springsource.org/browse/INT-3284 * Introduce `IntegrationConfigurationBeanFactoryPostProcessor`, `IntegrationConfigurationInitializer` * Apply `IntegrationConfigurationInitializer` and 'spring.factories' for HTTP and Security modules INT-3284: Address PR's comments JIRA: https://jira.springsource.org/browse/INT-3287 * Fix package tangle (INT-3287) * Apply `IntegrationConfigurationInitializer` for `MBeanExporterHelper` * Previously, there was a separate `ChannelSecurityInterceptorBeanPostProcessor` for each `ChannelSecurityInterceptor` whereas now, there is one `ChannelSecurityInterceptorBeanPostProcessor` that processes all interceptors INT-3284 Refactoring around config package tangle --- .../config/{xml => }/ChannelInitializer.java | 6 +- ...ltConfiguringBeanFactoryPostProcessor.java | 12 ++-- .../{annotation => }/EnableIntegration.java | 2 +- .../config/IntegrationConfigUtils.java | 52 ++++++++++++++ ...ConfigurationBeanFactoryPostProcessor.java | 56 +++++++++++++++ .../IntegrationConfigurationInitializer.java | 35 ++++++++++ .../config/IntegrationRegistrar.java | 34 ++++++---- ...stractCorrelatingMessageHandlerParser.java | 10 +-- .../integration/config/xml/BridgeParser.java | 8 +-- .../integration/config/xml/ChainParser.java | 3 +- .../config/xml/ClaimCheckInParser.java | 7 +- .../config/xml/ClaimCheckOutParser.java | 7 +- .../DefaultInboundChannelAdapterParser.java | 3 +- .../config/xml/EnricherParser.java | 5 +- .../xml/GlobalChannelInterceptorParser.java | 16 +++-- .../xml/HeaderEnricherParserSupport.java | 13 ++-- .../config/xml/HeaderFilterParser.java | 7 +- .../config/xml/IntegrationNamespaceUtils.java | 22 +----- .../xml/LoggingChannelAdapterParser.java | 8 +-- ...PayloadDeserializingTransformerParser.java | 7 +- .../PayloadSerializingTransformerParser.java | 7 +- .../config/xml/ResequencerParser.java | 25 +++---- .../config/xml/SelectorChainParser.java | 19 ++---- .../config/xml/SelectorParser.java | 9 +-- .../xml/SpelPropertyAccessorsParser.java | 3 +- .../xml/StandardHeaderEnricherParser.java | 6 +- .../integration/config/xml/WireTapParser.java | 14 ++-- .../context/IntegrationContextUtils.java | 8 +-- .../{xml => }/IdGeneratorConfigurerTests.java | 2 +- ...ribersDontOverrideDefaultTests-context.xml | 2 +- ...sableChannelAutoCreation-after-context.xml | 2 +- ...ableChannelAutoCreation-before-context.xml | 2 +- ...nableChannelAutoCreation-after-context.xml | 2 +- ...ableChannelAutoCreation-before-context.xml | 2 +- .../configuration/EnableIntegrationTests.java | 2 +- .../config/HttpInboundEndpointParser.java | 28 +------- ...tpIntegrationConfigurationInitializer.java | 68 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 2 + ...mxIntegrationConfigurationInitializer.java | 48 +++++++++++++ .../jmx/config/MBeanExporterParser.java | 8 --- .../main/resources/META-INF/spring.factories | 2 + .../ScriptExecutingMessageSource.java | 2 +- ...lSecurityInterceptorBeanPostProcessor.java | 45 +++++++----- .../config/SecuredChannelsParser.java | 44 +++++------- ...tyIntegrationConfigurationInitializer.java | 40 +++++++++++ .../main/resources/META-INF/spring.factories | 2 + ...dapterSecurityIntegrationTests-context.xml | 4 +- ...hannelAdapterSecurityIntegrationTests.java | 19 +++++- ...rityInterceptorBeanPostProcessorTests.java | 5 +- .../xml/config/XPathHeaderEnricherParser.java | 3 +- 50 files changed, 513 insertions(+), 225 deletions(-) rename spring-integration-core/src/main/java/org/springframework/integration/config/{xml => }/ChannelInitializer.java (93%) rename spring-integration-core/src/main/java/org/springframework/integration/config/{xml => }/DefaultConfiguringBeanFactoryPostProcessor.java (94%) rename spring-integration-core/src/main/java/org/springframework/integration/config/{annotation => }/EnableIntegration.java (96%) create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigUtils.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationBeanFactoryPostProcessor.java create mode 100644 spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java rename spring-integration-core/src/test/java/org/springframework/integration/config/{xml => }/IdGeneratorConfigurerTests.java (99%) create mode 100644 spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java create mode 100644 spring-integration-http/src/main/resources/META-INF/spring.factories create mode 100644 spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxIntegrationConfigurationInitializer.java create mode 100644 spring-integration-jmx/src/main/resources/META-INF/spring.factories create mode 100644 spring-integration-security/src/main/java/org/springframework/integration/security/config/SecurityIntegrationConfigurationInitializer.java create mode 100644 spring-integration-security/src/main/resources/META-INF/spring.factories diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/ChannelInitializer.java similarity index 93% rename from spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInitializer.java rename to spring-integration-core/src/main/java/org/springframework/integration/config/ChannelInitializer.java index 9c893a8d0c..a9e15a4edb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChannelInitializer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/ChannelInitializer.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.config.xml; +package org.springframework.integration.config; import java.util.Collection; @@ -35,7 +35,7 @@ import org.springframework.util.Assert; * * This bean plays a role of pre-instantiator since it is instantiated and * initialized as the very first bean of all SI beans using - * {@link AbstractIntegrationNamespaceHandler}. + * {@link org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler}. * * @author Oleg Zhurakousky * @author Gary Russell @@ -75,7 +75,7 @@ final class ChannelInitializer implements BeanFactoryAware, InitializingBean { if (this.logger.isDebugEnabled()){ this.logger.debug("Auto-creating channel '" + channelName + "' as DirectChannel"); } - IntegrationNamespaceUtils.autoCreateDirectChannel(channelName, (BeanDefinitionRegistry) this.beanFactory); + IntegrationConfigUtils.autoCreateDirectChannel(channelName, (BeanDefinitionRegistry) this.beanFactory); } } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java similarity index 94% rename from spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java rename to spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java index df4b0b6a76..36a430e56d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultConfiguringBeanFactoryPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/DefaultConfiguringBeanFactoryPostProcessor.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.config.xml; +package org.springframework.integration.config; import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy; @@ -111,7 +111,7 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce } else { RootBeanDefinition nullChannelDef = new RootBeanDefinition(); - nullChannelDef.setBeanClassName(IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.NullChannel"); + nullChannelDef.setBeanClassName(IntegrationConfigUtils.BASE_PACKAGE + ".channel.NullChannel"); BeanDefinitionHolder nullChannelHolder = new BeanDefinitionHolder(nullChannelDef, IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME); BeanDefinitionReaderUtils.registerBeanDefinition(nullChannelHolder, registry); @@ -127,16 +127,16 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce "' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created."); } RootBeanDefinition errorChannelDef = new RootBeanDefinition(); - errorChannelDef.setBeanClassName(IntegrationNamespaceUtils.BASE_PACKAGE + errorChannelDef.setBeanClassName(IntegrationConfigUtils.BASE_PACKAGE + ".channel.PublishSubscribeChannel"); BeanDefinitionHolder errorChannelHolder = new BeanDefinitionHolder(errorChannelDef, IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME); BeanDefinitionReaderUtils.registerBeanDefinition(errorChannelHolder, registry); BeanDefinitionBuilder loggingHandlerBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.LoggingHandler"); + IntegrationConfigUtils.BASE_PACKAGE + ".handler.LoggingHandler"); loggingHandlerBuilder.addConstructorArgValue("ERROR"); BeanDefinitionBuilder loggingEndpointBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".endpoint.EventDrivenConsumer"); + IntegrationConfigUtils.BASE_PACKAGE + ".endpoint.EventDrivenConsumer"); loggingEndpointBuilder.addConstructorArgReference(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME); loggingEndpointBuilder.addConstructorArgValue(loggingHandlerBuilder.getBeanDefinition()); BeanComponentDefinition componentDefinition = new BeanComponentDefinition( @@ -159,7 +159,7 @@ class DefaultConfiguringBeanFactoryPostProcessor implements BeanFactoryPostProce schedulerBuilder.addPropertyValue("threadNamePrefix", "task-scheduler-"); schedulerBuilder.addPropertyValue("rejectedExecutionHandler", new CallerRunsPolicy()); BeanDefinitionBuilder errorHandlerBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.MessagePublishingErrorHandler"); + IntegrationConfigUtils.BASE_PACKAGE + ".channel.MessagePublishingErrorHandler"); errorHandlerBuilder.addPropertyReference("defaultErrorChannel", IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME); schedulerBuilder.addPropertyValue("errorHandler", errorHandlerBuilder.getBeanDefinition()); BeanComponentDefinition schedulerComponent = new BeanComponentDefinition( diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/EnableIntegration.java b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegration.java similarity index 96% rename from spring-integration-core/src/main/java/org/springframework/integration/config/annotation/EnableIntegration.java rename to spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegration.java index b56b790a3d..7d09cdf786 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/annotation/EnableIntegration.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/EnableIntegration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.integration.config.annotation; +package org.springframework.integration.config; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigUtils.java new file mode 100644 index 0000000000..47ddf89f6d --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigUtils.java @@ -0,0 +1,52 @@ +/* + * Copyright 2014 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.config; + +import org.springframework.beans.factory.config.BeanDefinitionHolder; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.integration.channel.DirectChannel; + +/** + * Shared utility methods for Integration configuration. + * + * @author Artem Bilan + * @since 4.0 + */ +public final class IntegrationConfigUtils { + + public static final String BASE_PACKAGE = "org.springframework.integration"; + + public static void registerSpelFunctionBean(BeanDefinitionRegistry registry, String functionId, String className, + String methodSignature) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SpelFunctionFactoryBean.class) + .addConstructorArgValue(className) + .addConstructorArgValue(methodSignature); + registry.registerBeanDefinition(functionId, builder.getBeanDefinition()); + } + + public static void autoCreateDirectChannel(String channelName, BeanDefinitionRegistry registry) { + BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); + BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelName); + BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); + } + + private IntegrationConfigUtils() { + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationBeanFactoryPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationBeanFactoryPostProcessor.java new file mode 100644 index 0000000000..ced3431dc9 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationBeanFactoryPostProcessor.java @@ -0,0 +1,56 @@ +/* + * Copyright 2014 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.config; + +import java.util.HashSet; +import java.util.Set; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.core.io.support.SpringFactoriesLoader; +import org.springframework.util.Assert; +import org.springframework.util.ClassUtils; + +/** + * {@link BeanFactoryPostProcessor} to apply external Integration infrastructure configurations + * via loading {@link IntegrationConfigurationInitializer} implementations using {@link SpringFactoriesLoader}. + * + * @author Artem Bilan + * @since 4.0 + */ +public class IntegrationConfigurationBeanFactoryPostProcessor implements BeanFactoryPostProcessor { + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + Set initializerNames = new HashSet( + SpringFactoriesLoader.loadFactoryNames(IntegrationConfigurationInitializer.class, beanFactory.getBeanClassLoader())); + + for (String initializerName : initializerNames) { + try { + Class instanceClass = ClassUtils.forName(initializerName, beanFactory.getBeanClassLoader()); + Assert.isAssignable(IntegrationConfigurationInitializer.class, instanceClass); + IntegrationConfigurationInitializer instance = (IntegrationConfigurationInitializer) instanceClass.newInstance(); + instance.initialize(beanFactory); + } + catch (Exception e) { + throw new IllegalArgumentException("Cannot instantiate 'IntegrationConfigurationInitializer': " + initializerName, e); + } + } + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java new file mode 100644 index 0000000000..e163c70622 --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationConfigurationInitializer.java @@ -0,0 +1,35 @@ +/* + * Copyright 2014 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.config; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; + +/** + * The strategy to initialize the external Integration infrastructure (@{code BeanFactoryPostProcessor}s, + * global beans etc.) in the provided {@code beanFactory}. + *

+ * Typically implementations are loaded by {@link org.springframework.core.io.support.SpringFactoriesLoader}. + * + * @author Artem Bilan + * @since 4.0 + */ +public interface IntegrationConfigurationInitializer { + + void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException; + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java index 624c5b4bcc..4a7af30840 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationRegistrar.java @@ -44,9 +44,7 @@ import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.type.AnnotationMetadata; import org.springframework.integration.aop.PublisherAnnotationBeanPostProcessor; import org.springframework.integration.channel.DefaultHeaderChannelRegistry; -import org.springframework.integration.config.annotation.EnableIntegration; import org.springframework.integration.config.annotation.MessagingAnnotationPostProcessor; -import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.expression.IntegrationEvaluationContextAwareBeanPostProcessor; @@ -89,6 +87,7 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean if (importingClassMetadata != null) { this.registerMessagingAnnotationPostProcessors(importingClassMetadata, registry); } + this.registerIntegrationConfigurationBeanFactoryPostProcessor(registry); } /** @@ -102,8 +101,7 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean private void registerImplicitChannelCreator(BeanDefinitionRegistry registry) { if (!registry.containsBeanDefinition(IntegrationContextUtils.CHANNEL_INITIALIZER_BEAN_NAME)) { String channelsAutoCreateExpression = IntegrationProperties.getExpressionFor(IntegrationProperties.CHANNELS_AUTOCREATE); - BeanDefinitionBuilder channelDef = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config.xml.ChannelInitializer") + BeanDefinitionBuilder channelDef = BeanDefinitionBuilder.genericBeanDefinition(ChannelInitializer.class) .addPropertyValue("autoCreate", channelsAutoCreateExpression); BeanDefinitionHolder channelCreatorHolder = new BeanDefinitionHolder(channelDef.getBeanDefinition(), IntegrationContextUtils.CHANNEL_INITIALIZER_BEAN_NAME); @@ -112,7 +110,7 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean if (!registry.containsBeanDefinition(IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME)) { BeanDefinitionBuilder channelRegistryBuilder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config.xml.ChannelInitializer$AutoCreateCandidatesCollector"); + .genericBeanDefinition(ChannelInitializer.AutoCreateCandidatesCollector.class); channelRegistryBuilder.addConstructorArgValue(new ManagedSet()); BeanDefinitionHolder channelRegistryHolder = new BeanDefinitionHolder(channelRegistryBuilder.getBeanDefinition(), IntegrationContextUtils.AUTO_CREATE_CHANNEL_CANDIDATES_BEAN_NAME); @@ -206,8 +204,8 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean } if (jsonPathClass != null) { - IntegrationNamespaceUtils.registerSpelFunctionBean(registry, jsonPathBeanName, - IntegrationNamespaceUtils.BASE_PACKAGE + ".json.JsonPathUtils", "evaluate"); + IntegrationConfigUtils.registerSpelFunctionBean(registry, jsonPathBeanName, + IntegrationConfigUtils.BASE_PACKAGE + ".json.JsonPathUtils", "evaluate"); } } @@ -222,16 +220,15 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean if (!alreadyRegistered && !registriesProcessed.contains(registryId)) { Class xpathClass = null; try { - xpathClass = ClassUtils.forName(IntegrationNamespaceUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", - this.classLoader); + xpathClass = ClassUtils.forName(IntegrationConfigUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", this.classLoader); } catch (ClassNotFoundException e) { logger.debug("SpEL function '#xpath' isn't registered: there is no spring-integration-xml.jar on the classpath."); } if (xpathClass != null) { - IntegrationNamespaceUtils.registerSpelFunctionBean(registry, xpathBeanName, - IntegrationNamespaceUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", "evaluate"); + IntegrationConfigUtils.registerSpelFunctionBean(registry, xpathBeanName, + IntegrationConfigUtils.BASE_PACKAGE + ".xml.xpath.XPathUtils", "evaluate"); } } @@ -252,8 +249,7 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean alreadyRegistered = registry.isBeanNameInUse(IntegrationContextUtils.DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME); } if (!alreadyRegistered) { - BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config.xml.DefaultConfiguringBeanFactoryPostProcessor"); + BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultConfiguringBeanFactoryPostProcessor.class); BeanDefinitionHolder postProcessorHolder = new BeanDefinitionHolder( postProcessorBuilder.getBeanDefinition(), IntegrationContextUtils.DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME); BeanDefinitionReaderUtils.registerBeanDefinition(postProcessorHolder, registry); @@ -317,4 +313,16 @@ public class IntegrationRegistrar implements ImportBeanDefinitionRegistrar, Bean } + /** + * Register {@link IntegrationConfigurationBeanFactoryPostProcessor} to process the external Integration infrastructure. + */ + private void registerIntegrationConfigurationBeanFactoryPostProcessor(BeanDefinitionRegistry registry) { + if (!registry.containsBeanDefinition(IntegrationContextUtils.INTEGRATION_CONFIGURATION_POST_PROCESSOR_BEAN_NAME)) { + BeanDefinitionBuilder postProcessorBuilder = BeanDefinitionBuilder + .genericBeanDefinition(IntegrationConfigurationBeanFactoryPostProcessor.class) + .setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + registry.registerBeanDefinition(IntegrationContextUtils.INTEGRATION_CONFIGURATION_POST_PROCESSOR_BEAN_NAME, postProcessorBuilder.getBeanDefinition()); + } + } + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractCorrelatingMessageHandlerParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractCorrelatingMessageHandlerParser.java index da428f6a29..aca1bee30f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractCorrelatingMessageHandlerParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/AbstractCorrelatingMessageHandlerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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 @@ -12,13 +12,15 @@ */ package org.springframework.integration.config.xml; +import org.w3c.dom.Element; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.util.StringUtils; -import org.w3c.dom.Element; /** * Base class for parsers that create an instance of {@link AbstractCorrelatingMessageHandler} @@ -92,7 +94,7 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo } else if (hasExpression) { BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".aggregator.ExpressionEvaluating" + .genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE + ".aggregator.ExpressionEvaluating" + adapterClass); adapterBuilder.addConstructorArgValue(expression); adapter = adapterBuilder.getBeanDefinition(); @@ -108,7 +110,7 @@ public abstract class AbstractCorrelatingMessageHandlerParser extends AbstractCo private BeanMetadataElement createAdapter(BeanMetadataElement ref, String method, String unqualifiedClassName) { BeanDefinitionBuilder builder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config." + unqualifiedClassName + .genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE + ".config." + unqualifiedClassName + "FactoryBean"); builder.addConstructorArgValue(ref); if (StringUtils.hasText(method)) { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/BridgeParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/BridgeParser.java index 7329727968..0b88c2f651 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/BridgeParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/BridgeParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -20,18 +20,18 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.handler.BridgeHandler; /** * Parser for the <bridge> element. - * + * * @author Mark Fisher */ public class BridgeParser extends AbstractConsumerEndpointParser { @Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.BridgeHandler"); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(BridgeHandler.class); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout"); return builder; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java index b179a94db4..18ccfbba70 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ChainParser.java @@ -33,6 +33,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.handler.MessageHandlerChain; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -88,7 +89,7 @@ public class ChainParser extends AbstractConsumerEndpointParser { } if ("gateway".equals(child.getLocalName())) { BeanDefinitionBuilder gwBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".gateway.RequestReplyMessageHandlerAdapter"); + IntegrationConfigUtils.BASE_PACKAGE + ".gateway.RequestReplyMessageHandlerAdapter"); gwBuilder.addConstructorArgValue(childBeanMetadata); handlerList.add(gwBuilder.getBeanDefinition()); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java index ee676e17ea..d62bf7b05d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckInParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -20,11 +20,12 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.transformer.ClaimCheckInTransformer; import org.springframework.util.Assert; /** * Parser for the <claim-check-in/> element. - * + * * @author Mark Fisher * @since 2.0 */ @@ -32,7 +33,7 @@ public class ClaimCheckInParser extends AbstractTransformerParser { @Override protected String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.ClaimCheckInTransformer"; + return ClaimCheckInTransformer.class.getName(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java index 43c95abf7a..c594bfef75 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ClaimCheckOutParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -20,11 +20,12 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.transformer.ClaimCheckOutTransformer; import org.springframework.util.Assert; /** * Parser for the <claim-check-out/> element. - * + * * @author Mark Fisher * @author Oleg Zhurakousky * @since 2.0 @@ -33,7 +34,7 @@ public class ClaimCheckOutParser extends AbstractTransformerParser { @Override protected String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.ClaimCheckOutTransformer"; + return ClaimCheckOutTransformer.class.getName(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultInboundChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultInboundChannelAdapterParser.java index 2b7afb3beb..1a35a2dc4a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultInboundChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/DefaultInboundChannelAdapterParser.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.ExpressionFactoryBean; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.endpoint.ExpressionEvaluatingMessageSource; import org.springframework.integration.endpoint.MethodInvokingMessageSource; import org.springframework.integration.expression.DynamicExpression; @@ -90,7 +91,7 @@ public class DefaultInboundChannelAdapterParser extends AbstractPollingInboundCh } BeanDefinition scriptBeanDefinition = parserContext.getDelegate().parseCustomElement(scriptElement); BeanDefinitionBuilder sourceBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".scripting.ScriptExecutingMessageSource"); + IntegrationConfigUtils.BASE_PACKAGE + ".scripting.ScriptExecutingMessageSource"); sourceBuilder.addConstructorArgValue(scriptBeanDefinition); this.parseHeaderExpressions(sourceBuilder, element, parserContext); result = sourceBuilder.getBeanDefinition(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java index caaa76d902..c0bd6a6d53 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/EnricherParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -25,6 +25,7 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.ExpressionFactoryBean; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.transformer.ContentEnricher; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -69,7 +70,7 @@ public class EnricherParser extends AbstractConsumerEndpointParser { BeanDefinition expressionDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, subElement, true); BeanDefinitionBuilder valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgValue(expressionDefinition) .addConstructorArgValue(subElement.getAttribute("type")); IntegrationNamespaceUtils.setValueIfAttributeDefined(valueProcessorBuilder, subElement, "overwrite"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java index 5c6acd210e..36a0db027f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/GlobalChannelInterceptorParser.java @@ -18,6 +18,8 @@ package org.springframework.integration.config.xml; import java.util.List; +import org.w3c.dom.Element; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.parsing.BeanComponentDefinition; @@ -27,12 +29,13 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.channel.interceptor.GlobalChannelInterceptorWrapper; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.util.xml.DomUtils; -import org.w3c.dom.Element; /** * Parser for 'channel-interceptor' elements. - * + * * @author Oleg Zhurakousky * @author Mark Fisher * @author David Turanski @@ -40,7 +43,7 @@ import org.w3c.dom.Element; */ public class GlobalChannelInterceptorParser extends AbstractBeanDefinitionParser { - private static final String BASE_PACKAGE = IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.interceptor."; + private static final String BASE_PACKAGE = IntegrationConfigUtils.BASE_PACKAGE + ".channel.interceptor."; private static final String CHANNEL_NAME_PATTERN_ATTRIBUTE = "pattern"; @@ -56,8 +59,7 @@ public class GlobalChannelInterceptorParser extends AbstractBeanDefinitionParser protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { this.createAndRegisterGlobalPostProcessorIfNecessary(parserContext); - BeanDefinitionBuilder globalChannelInterceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - BASE_PACKAGE + "GlobalChannelInterceptorWrapper"); + BeanDefinitionBuilder globalChannelInterceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class); Object childBeanDefinition = getBeanDefinitionBuilderConstructorValue(element, parserContext); globalChannelInterceptorBuilder.addConstructorArgValue(childBeanDefinition); IntegrationNamespaceUtils.setValueIfAttributeDefined(globalChannelInterceptorBuilder, element, "order"); @@ -91,7 +93,7 @@ public class GlobalChannelInterceptorParser extends AbstractBeanDefinitionParser if (element.hasAttribute(REF_ATTRIBUTE)) { beanName = element.getAttribute(REF_ATTRIBUTE); } - else { + else { List els = DomUtils.getChildElements(element); if (els.isEmpty()) { parserContext.getReaderContext().error("child BeanDefinition must not be null", element); @@ -102,7 +104,7 @@ public class GlobalChannelInterceptorParser extends AbstractBeanDefinitionParser beanName = new WireTapParser().parse(child, parserContext); } else { - BeanDefinition beanDef = parserContext.getDelegate().parseCustomElement(child); + BeanDefinition beanDef = parserContext.getDelegate().parseCustomElement(child); beanName = BeanDefinitionReaderUtils.generateBeanName(beanDef, parserContext.getRegistry()); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java index 3c2e05ecca..79cd974066 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderEnricherParserSupport.java @@ -29,6 +29,7 @@ import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.expression.DynamicExpression; import org.springframework.integration.transformer.HeaderEnricher; @@ -216,7 +217,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar Object headerValue = (headerType != null) ? new TypedStringValue(value, headerType) : value; valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgValue(headerValue); } else if (isExpression) { @@ -225,7 +226,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar "The 'method' attribute cannot be used with the 'expression' attribute.", element); } valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); if (expressionElement != null) { BeanDefinitionBuilder dynamicExpressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(DynamicExpression.class); dynamicExpressionBuilder.addConstructorArgValue(expressionElement.getAttribute("key")); @@ -244,7 +245,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar } if (hasMethod || isScript) { valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.MessageProcessingHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.MessageProcessingHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgValue(innerComponentDefinition); if (hasMethod) { valueProcessorBuilder.addConstructorArgValue(method); @@ -252,7 +253,7 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar } else { valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgValue(innerComponentDefinition); } } @@ -263,13 +264,13 @@ public abstract class HeaderEnricherParserSupport extends AbstractTransformerPar } if (hasMethod) { valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.MessageProcessingHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.MessageProcessingHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgReference(ref); valueProcessorBuilder.addConstructorArgValue(method); } else { valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); + IntegrationConfigUtils.BASE_PACKAGE + ".transformer.support.StaticHeaderValueMessageProcessor"); valueProcessorBuilder.addConstructorArgReference(ref); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java index 93f81e4c7f..b19561e1ca 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/HeaderFilterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -20,11 +20,12 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.transformer.HeaderFilter; import org.springframework.util.StringUtils; /** * Parser for the 'header-filter' element. - * + * * @author Mark Fisher * @author Oleg Zhurakousky * @since 2.0 @@ -33,7 +34,7 @@ public class HeaderFilterParser extends AbstractTransformerParser { @Override protected final String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.HeaderFilter"; + return HeaderFilter.class.getName(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java index e0fc3ee718..cb1e34e1fb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/IntegrationNamespaceUtils.java @@ -27,17 +27,14 @@ import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.Conventions; import org.springframework.expression.common.LiteralExpression; -import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.config.ExpressionFactoryBean; -import org.springframework.integration.config.SpelFunctionFactoryBean; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.endpoint.AbstractPollingEndpoint; import org.springframework.transaction.interceptor.DefaultTransactionAttribute; import org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource; @@ -60,7 +57,6 @@ import org.springframework.util.xml.DomUtils; */ public abstract class IntegrationNamespaceUtils { - public static final String BASE_PACKAGE = "org.springframework.integration"; public static final String REF_ATTRIBUTE = "ref"; public static final String METHOD_ATTRIBUTE = "method"; public static final String ORDER = "order"; @@ -479,14 +475,6 @@ public abstract class IntegrationNamespaceUtils { return expressionDef; } - public static void registerSpelFunctionBean(BeanDefinitionRegistry registry, String functionId, String className, - String methodSignature) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(SpelFunctionFactoryBean.class) - .addConstructorArgValue(className) - .addConstructorArgValue(methodSignature); - registry.registerBeanDefinition(functionId, builder.getBeanDefinition()); - } - public static BeanDefinition createExpressionDefIfAttributeDefined(String expressionElementName, Element element) { Assert.hasText(expressionElementName, "'expressionElementName' must no be empty"); @@ -508,15 +496,9 @@ public abstract class IntegrationNamespaceUtils { + "reference has been provided, because that 'id' would be used for the created channel.", element); } - autoCreateDirectChannel(channelId, parserContext.getRegistry()); + IntegrationConfigUtils.autoCreateDirectChannel(channelId, parserContext.getRegistry()); return channelId; } - public static void autoCreateDirectChannel(String channelName, BeanDefinitionRegistry registry) { - BeanDefinitionBuilder channelBuilder = BeanDefinitionBuilder.genericBeanDefinition(DirectChannel.class); - BeanDefinitionHolder holder = new BeanDefinitionHolder(channelBuilder.getBeanDefinition(), channelName); - BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); - } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java index b6ec7af884..6178e0f805 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/LoggingChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2014 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. @@ -21,11 +21,12 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.handler.LoggingHandler; import org.springframework.util.StringUtils; /** * Parser for the 'logging-channel-adapter' element. - * + * * @author Mark Fisher * @since 1.0.1 */ @@ -34,8 +35,7 @@ public class LoggingChannelAdapterParser extends AbstractOutboundChannelAdapterP @Override protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.LoggingHandler"); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(LoggingHandler.class); builder.addConstructorArgValue(element.getAttribute("level")); String expression = element.getAttribute("expression"); String logFullMessage = element.getAttribute("log-full-message"); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadDeserializingTransformerParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadDeserializingTransformerParser.java index 38339907b6..215b613aff 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadDeserializingTransformerParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadDeserializingTransformerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2014 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. @@ -20,17 +20,18 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.transformer.PayloadDeserializingTransformer; /** * Parser for the 'payload-deserializing-transformer' element. - * + * * @author Mark Fisher */ public class PayloadDeserializingTransformerParser extends AbstractTransformerParser { @Override protected String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.PayloadDeserializingTransformer"; + return PayloadDeserializingTransformer.class.getName(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadSerializingTransformerParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadSerializingTransformerParser.java index edaaa2b0ea..213f037c45 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadSerializingTransformerParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/PayloadSerializingTransformerParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2014 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. @@ -20,10 +20,11 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.transformer.PayloadSerializingTransformer; /** * Parser for the 'payload-serializing-transformer' element. - * + * * @author Mark Fisher * @since 1.0.1 */ @@ -31,7 +32,7 @@ public class PayloadSerializingTransformerParser extends AbstractTransformerPars @Override protected String getTransformerClassName() { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.PayloadSerializingTransformer"; + return PayloadSerializingTransformer.class.getName(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResequencerParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResequencerParser.java index d0175b0328..a22c3759c8 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResequencerParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/ResequencerParser.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2011 the original author or authors. - * + * Copyright 2002-2014 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. @@ -13,16 +13,18 @@ package org.springframework.integration.config.xml; +import org.w3c.dom.Element; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor; import org.springframework.integration.aggregator.ResequencingMessageHandler; -import org.w3c.dom.Element; +import org.springframework.integration.store.SimpleMessageStore; /** * Parser for the <resequencer> element. - * + * * @author Marius Bogoevici * @author Dave Syer * @author Iwein Fuld @@ -34,7 +36,7 @@ public class ResequencerParser extends AbstractCorrelatingMessageHandlerParser { private static final String COMPARATOR_REF_ATTRIBUTE = "comparator"; private static final String RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE = "release-partial-sequences"; - + @Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { @@ -51,13 +53,12 @@ public class ResequencerParser extends AbstractCorrelatingMessageHandlerParser { builder.addConstructorArgReference(processorRef); // Message store - builder.addConstructorArgValue(BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".store.SimpleMessageStore").getBeanDefinition()); - + builder.addConstructorArgValue(BeanDefinitionBuilder.genericBeanDefinition(SimpleMessageStore.class).getBeanDefinition()); + this.doParse(builder, element, processorBuilder.getBeanDefinition(), parserContext); - + IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE); - + return builder; } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java index 8e59a7678b..bb56508492 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorChainParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2014 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. @@ -26,25 +26,21 @@ import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.filter.MethodInvokingSelector; +import org.springframework.integration.selector.MessageSelectorChain; import org.springframework.util.StringUtils; /** * Parser for the <selector-chain/> element. - * + * * @author Mark Fisher * @author Iwein Fuld */ public class SelectorChainParser extends AbstractSingleBeanDefinitionParser { - private static final String SELECTOR_CHAIN_CLASSNAME = IntegrationNamespaceUtils.BASE_PACKAGE - + ".selector.MessageSelectorChain"; - - private static final String METHODINVOKING_SELECTOR_CLASSNAME = IntegrationNamespaceUtils.BASE_PACKAGE - + ".filter.MethodInvokingSelector"; - @Override protected String getBeanClassName(Element element) { - return SELECTOR_CHAIN_CLASSNAME; + return MessageSelectorChain.class.getName(); } public void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { @@ -82,7 +78,7 @@ public class SelectorChainParser extends AbstractSingleBeanDefinitionParser { } private RuntimeBeanReference buildSelectorChain(ParserContext parserContext, Node child) { - BeanDefinitionBuilder nestedBuilder = BeanDefinitionBuilder.genericBeanDefinition(SELECTOR_CHAIN_CLASSNAME); + BeanDefinitionBuilder nestedBuilder = BeanDefinitionBuilder.genericBeanDefinition(MessageSelectorChain.class); this.parseSelectorChain(nestedBuilder, (Element) child, parserContext); String nestedBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(nestedBuilder.getBeanDefinition(), parserContext.getRegistry()); @@ -91,8 +87,7 @@ public class SelectorChainParser extends AbstractSingleBeanDefinitionParser { } private RuntimeBeanReference buildMethodInvokingSelector(ParserContext parserContext, String ref, String method) { - BeanDefinitionBuilder methodInvokingSelectorBuilder = BeanDefinitionBuilder - .genericBeanDefinition(METHODINVOKING_SELECTOR_CLASSNAME); + BeanDefinitionBuilder methodInvokingSelectorBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingSelector.class); methodInvokingSelectorBuilder.addConstructorArgValue(new RuntimeBeanReference(ref)); methodInvokingSelectorBuilder.addConstructorArgValue(method); RuntimeBeanReference selector = new RuntimeBeanReference(BeanDefinitionReaderUtils.registerWithGeneratedName( diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorParser.java index 597af53761..8c31a2807a 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SelectorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2014 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. @@ -22,11 +22,12 @@ import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.filter.MethodInvokingSelector; import org.springframework.util.StringUtils; /** * Parser for a top-level <selector/> element. - * + * * @author Mark Fisher * @since 1.0.4 */ @@ -34,7 +35,7 @@ public class SelectorParser extends AbstractSingleBeanDefinitionParser { @Override protected String getBeanClassName(Element element) { - return IntegrationNamespaceUtils.BASE_PACKAGE + ".filter.MethodInvokingSelector"; + return MethodInvokingSelector.class.getName(); } public void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { @@ -52,7 +53,7 @@ public class SelectorParser extends AbstractSingleBeanDefinitionParser { if (!StringUtils.hasText(method)) { parserContext.getReaderContext().error( "The 'method' attribute is required for selector '" + id + "'.", element); - } + } builder.addConstructorArgValue(new RuntimeBeanReference(ref)); builder.addConstructorArgValue(method); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java index 13e355985d..2c496258ea 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/SpelPropertyAccessorsParser.java @@ -30,6 +30,7 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.util.StringUtils; /** @@ -88,7 +89,7 @@ public class SpelPropertyAccessorsParser implements BeanDefinitionParser { private synchronized void initializeSpelPropertyAccessorRegistrarIfNecessary(ParserContext parserContext) { if (!this.initialized) { BeanDefinitionBuilder registrarBuilder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".config.SpelPropertyAccessorRegistrar") + .genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE + ".config.SpelPropertyAccessorRegistrar") .setRole(BeanDefinition.ROLE_INFRASTRUCTURE) .addConstructorArgValue(this.propertyAccessors); BeanDefinitionReaderUtils.registerWithGeneratedName(registrarBuilder.getBeanDefinition(), diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java index 5a5f6e2018..8197a9149c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/StandardHeaderEnricherParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2014 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. @@ -21,6 +21,7 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.IntegrationMessageHeaderAccessor; +import org.springframework.integration.handler.MethodInvokingMessageProcessor; import org.springframework.messaging.MessageHeaders; import org.springframework.util.StringUtils; @@ -55,8 +56,7 @@ public class StandardHeaderEnricherParser extends HeaderEnricherParserSupport { parserContext.extractSource(element)); return; } - BeanDefinitionBuilder processorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - IntegrationNamespaceUtils.BASE_PACKAGE + ".handler.MethodInvokingMessageProcessor"); + BeanDefinitionBuilder processorBuilder = BeanDefinitionBuilder.genericBeanDefinition(MethodInvokingMessageProcessor.class); processorBuilder.addConstructorArgReference(ref); processorBuilder.addConstructorArgValue(method); builder.addPropertyValue("messageProcessor", processorBuilder.getBeanDefinition()); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/WireTapParser.java b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/WireTapParser.java index 13d427db24..adf5bc2992 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/config/xml/WireTapParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/config/xml/WireTapParser.java @@ -1,11 +1,11 @@ /* - * Copyright 2002-2008 the original author or authors. - * + * Copyright 2002-2014 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. @@ -19,18 +19,18 @@ import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.channel.interceptor.WireTap; import org.springframework.util.StringUtils; /** * Parser for the <wire-tap> element. - * + * * @author Mark Fisher */ public class WireTapParser implements BeanDefinitionRegisteringParser { public String parse(Element element, ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder - .genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".channel.interceptor.WireTap"); + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(WireTap.class); String targetRef = element.getAttribute("channel"); if (!StringUtils.hasText(targetRef)) { parserContext.getReaderContext().error("The 'channel' attribute is required.", element); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java index 02d6fde81f..1ddb005f56 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationContextUtils.java @@ -21,7 +21,7 @@ import java.util.Properties; import org.springframework.beans.factory.BeanFactory; import org.springframework.core.convert.ConversionService; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.metadata.MetadataStore; import org.springframework.messaging.MessageChannel; import org.springframework.scheduling.TaskScheduler; @@ -58,13 +58,13 @@ public abstract class IntegrationContextUtils { public static final String DEFAULT_CONFIGURING_POSTPROCESSOR_BEAN_NAME = "DefaultConfiguringBeanFactoryPostProcessor"; - public static final String MESSAGING_ANNOTATION_POSTPROCESSOR_NAME = IntegrationNamespaceUtils.BASE_PACKAGE + public static final String MESSAGING_ANNOTATION_POSTPROCESSOR_NAME = IntegrationConfigUtils.BASE_PACKAGE + ".internalMessagingAnnotationPostProcessor"; - public static final String PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME = IntegrationNamespaceUtils.BASE_PACKAGE + + public static final String PUBLISHER_ANNOTATION_POSTPROCESSOR_NAME = IntegrationConfigUtils.BASE_PACKAGE + ".internalPublisherAnnotationBeanPostProcessor"; -// public static final String FLOW_POST_PROCESSOR_BEAN_NAME = IntegrationFlowBeanFactoryPostProcessor.class.getSimpleName(); + public static final String INTEGRATION_CONFIGURATION_POST_PROCESSOR_BEAN_NAME = "IntegrationConfigurationBeanFactoryPostProcessor"; /** * @param beanFactory BeanFactory for lookup, must not be null. diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/IdGeneratorConfigurerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/IdGeneratorConfigurerTests.java similarity index 99% rename from spring-integration-core/src/test/java/org/springframework/integration/config/xml/IdGeneratorConfigurerTests.java rename to spring-integration-core/src/test/java/org/springframework/integration/config/IdGeneratorConfigurerTests.java index 5dc97e79fe..ca2abbed3b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/IdGeneratorConfigurerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/IdGeneratorConfigurerTests.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.integration.config.xml; +package org.springframework.integration.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests-context.xml index 7cbef70ba3..111a0472c5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/DispatcherMaxSubscribersDontOverrideDefaultTests-context.xml @@ -5,7 +5,7 @@ - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-after-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-after-context.xml index 0dea07557a..34f0ea7d40 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-after-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-after-context.xml @@ -7,7 +7,7 @@ - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-before-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-before-context.xml index 300315ae1e..018f0b2aa4 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-before-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestDisableChannelAutoCreation-before-context.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-after-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-after-context.xml index b177646005..dceb3db4f5 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-after-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-after-context.xml @@ -7,7 +7,7 @@ - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-before-context.xml b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-before-context.xml index ece1f92d91..08e5478b3b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-before-context.xml +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/xml/TestEnableChannelAutoCreation-before-context.xml @@ -5,7 +5,7 @@ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"> - + diff --git a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java index bfb9152288..c177e2da28 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/configuration/EnableIntegrationTests.java @@ -32,7 +32,7 @@ import org.springframework.integration.annotation.Publisher; import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.channel.DirectChannel; import org.springframework.integration.channel.QueueChannel; -import org.springframework.integration.config.annotation.EnableIntegration; +import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.support.MessageBuilder; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java index ef8685dd4d..0ad7faf5ff 100644 --- a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpInboundEndpointParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -22,7 +22,6 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -32,10 +31,8 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.http.inbound.HttpRequestHandlingController; import org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway; -import org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping; import org.springframework.integration.http.inbound.RequestMapping; import org.springframework.integration.http.support.DefaultHttpHeaderMapper; -import org.springframework.integration.http.support.HttpContextUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -45,9 +42,6 @@ import org.springframework.util.xml.DomUtils; * of the 'http' namespace. The constructor's boolean value specifies whether * a reply is to be expected. This value should be 'false' for the * 'inbound-channel-adapter' and 'true' for the 'inbound-gateway'. - * This parser also registers a global Spring-MVC infrastructure bean for - * {@link IntegrationRequestMappingHandlerMapping}; - * see {@link #registerRequestMappingHandlerMappingIfNecessary}. * * @author Mark Fisher * @author Oleg Zhurakousky @@ -182,8 +176,6 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse builder.addPropertyValue("requestMapping", requestMappingDef); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-payload-type", "requestPayloadType"); - - this.registerRequestMappingHandlerMappingIfNecessary(parserContext); } private String getInputChannelAttributeName() { @@ -212,22 +204,4 @@ public class HttpInboundEndpointParser extends AbstractSingleBeanDefinitionParse return requestMappingDefBuilder.getRawBeanDefinition(); } - /** - * This method will auto-register an {@link IntegrationRequestMappingHandlerMapping} - * which could also be overridden by the user by simply registering - * a {@link IntegrationRequestMappingHandlerMapping} {@code } with 'id' - * {@link HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}. - */ - private void registerRequestMappingHandlerMappingIfNecessary(ParserContext parserContext) { - if (!parserContext.getRegistry().containsBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)) { - BeanDefinitionBuilder requestMappingBuilder = - BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class); - requestMappingBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); - requestMappingBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, 0); - BeanComponentDefinition requestMappingComponent = - new BeanComponentDefinition(requestMappingBuilder.getBeanDefinition(), HttpContextUtils.HANDLER_MAPPING_BEAN_NAME); - parserContext.registerBeanComponent(requestMappingComponent); - } - } - } diff --git a/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java new file mode 100644 index 0000000000..d39fcd00b9 --- /dev/null +++ b/spring-integration-http/src/main/java/org/springframework/integration/http/config/HttpIntegrationConfigurationInitializer.java @@ -0,0 +1,68 @@ +/* + * Copyright 2014 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.http.config; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.integration.config.IntegrationConfigurationInitializer; +import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.http.inbound.IntegrationRequestMappingHandlerMapping; +import org.springframework.integration.http.support.HttpContextUtils; + +/** + * The HTTP Integration infrastructure {@code beanFactory} initializer. + * + * @author Artem Bilan + * @since 4.0 + */ +public class HttpIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer { + + private static final Log logger = LogFactory.getLog(HttpIntegrationConfigurationInitializer.class); + + @Override + public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { + if (beanFactory instanceof BeanDefinitionRegistry) { + this.registerRequestMappingHandlerMappingIfNecessary((BeanDefinitionRegistry) beanFactory); + } + else { + logger.warn("'IntegrationRequestMappingHandlerMapping' isn't registered because 'beanFactory' isn't an instance of `BeanDefinitionRegistry`."); + } + } + + /** + * Registers an {@link IntegrationRequestMappingHandlerMapping} + * which could also be overridden by the user by simply registering + * a {@link IntegrationRequestMappingHandlerMapping} {@code } with 'id' + * {@link HttpContextUtils#HANDLER_MAPPING_BEAN_NAME}. + */ + private void registerRequestMappingHandlerMappingIfNecessary(BeanDefinitionRegistry registry) { + if (!registry.containsBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME)) { + BeanDefinitionBuilder requestMappingBuilder = + BeanDefinitionBuilder.genericBeanDefinition(IntegrationRequestMappingHandlerMapping.class); + requestMappingBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); + requestMappingBuilder.addPropertyValue(IntegrationNamespaceUtils.ORDER, 0); + registry.registerBeanDefinition(HttpContextUtils.HANDLER_MAPPING_BEAN_NAME, requestMappingBuilder.getBeanDefinition()); + } + } + +} diff --git a/spring-integration-http/src/main/resources/META-INF/spring.factories b/spring-integration-http/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..314d187963 --- /dev/null +++ b/spring-integration-http/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.integration.config.IntegrationConfigurationInitializer=\ +org.springframework.integration.http.config.HttpIntegrationConfigurationInitializer diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxIntegrationConfigurationInitializer.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxIntegrationConfigurationInitializer.java new file mode 100644 index 0000000000..78225b4594 --- /dev/null +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/JmxIntegrationConfigurationInitializer.java @@ -0,0 +1,48 @@ +/* + * Copyright 2014 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.jmx.config; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.integration.config.IntegrationConfigurationInitializer; +import org.springframework.integration.monitor.IntegrationMBeanExporter; + +/** + * The JMX Integration infrastructure {@code beanFactory} initializer. + * + * @author Artem Bilan + * @since 4.0 + */ +public class JmxIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer { + + private static final String MBEAN_EXPORTER_HELPER_BEAN_NAME = MBeanExporterHelper.class.getName(); + + @Override + public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { + this.registerMBeanExporterHelperIfNecessary(beanFactory); + } + + private void registerMBeanExporterHelperIfNecessary(ConfigurableListableBeanFactory beanFactory) { + if (!beanFactory.getBeansOfType(IntegrationMBeanExporter.class, false, false).isEmpty()) { + MBeanExporterHelper mBeanExporterHelper = new MBeanExporterHelper(); + mBeanExporterHelper.postProcessBeanFactory(beanFactory); + beanFactory.registerSingleton(MBEAN_EXPORTER_HELPER_BEAN_NAME, mBeanExporterHelper); + beanFactory.initializeBean(mBeanExporterHelper, MBEAN_EXPORTER_HELPER_BEAN_NAME); + } + } + +} diff --git a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterParser.java b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterParser.java index e41560c10f..409a1ad6f6 100644 --- a/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterParser.java +++ b/spring-integration-jmx/src/main/java/org/springframework/integration/jmx/config/MBeanExporterParser.java @@ -23,8 +23,6 @@ import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.RuntimeBeanReference; 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.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; @@ -64,12 +62,6 @@ public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser { IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "object-naming-strategy", "namingStrategy"); builder.addPropertyValue("server", mbeanServer); - this.registerMBeanExporterHelper(parserContext.getRegistry()); - } - - private void registerMBeanExporterHelper(BeanDefinitionRegistry registry){ - BeanDefinitionBuilder mBeanExporterHelperBuilder = BeanDefinitionBuilder.rootBeanDefinition(MBeanExporterHelper.class); - BeanDefinitionReaderUtils.registerWithGeneratedName(mBeanExporterHelperBuilder.getBeanDefinition(), registry); } private Object getMBeanServer(Element element, ParserContext parserContext) { diff --git a/spring-integration-jmx/src/main/resources/META-INF/spring.factories b/spring-integration-jmx/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..dfe6d52df5 --- /dev/null +++ b/spring-integration-jmx/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.integration.config.IntegrationConfigurationInitializer=\ +org.springframework.integration.jmx.config.JmxIntegrationConfigurationInitializer diff --git a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutingMessageSource.java b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutingMessageSource.java index 6b782f1f7a..295ce57c7b 100644 --- a/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutingMessageSource.java +++ b/spring-integration-scripting/src/main/java/org/springframework/integration/scripting/ScriptExecutingMessageSource.java @@ -20,7 +20,7 @@ import org.springframework.integration.endpoint.AbstractMessageSource; /** * The {@link org.springframework.integration.core.MessageSource} strategy implementation - * to produce a {@link org.springframework.integration.Message} from underlying + * to produce a {@link org.springframework.messaging.Message} from underlying * {@linkplain #scriptMessageProcessor} for polling endpoints. * * @author Artem Bilan diff --git a/spring-integration-security/src/main/java/org/springframework/integration/security/config/ChannelSecurityInterceptorBeanPostProcessor.java b/spring-integration-security/src/main/java/org/springframework/integration/security/config/ChannelSecurityInterceptorBeanPostProcessor.java index 553f1d8acd..d8851dc033 100644 --- a/spring-integration-security/src/main/java/org/springframework/integration/security/config/ChannelSecurityInterceptorBeanPostProcessor.java +++ b/spring-integration-security/src/main/java/org/springframework/integration/security/config/ChannelSecurityInterceptorBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -16,52 +16,61 @@ package org.springframework.integration.security.config; +import java.util.Collection; import java.util.Set; import java.util.regex.Pattern; +import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; +import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.messaging.MessageChannel; -import org.springframework.integration.security.channel.ChannelSecurityMetadataSource; import org.springframework.integration.security.channel.ChannelSecurityInterceptor; -import org.springframework.util.Assert; +import org.springframework.integration.security.channel.ChannelSecurityMetadataSource; +import org.springframework.messaging.MessageChannel; /** * A {@link BeanPostProcessor} that proxies {@link MessageChannel}s to apply a {@link ChannelSecurityInterceptor}. - * + * * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan */ public class ChannelSecurityInterceptorBeanPostProcessor implements BeanPostProcessor { - private final ChannelSecurityInterceptor interceptor; + private final Collection securityInterceptors; - public ChannelSecurityInterceptorBeanPostProcessor(ChannelSecurityInterceptor interceptor) { - Assert.notNull(interceptor, "interceptor must not be null"); - this.interceptor = interceptor; + public ChannelSecurityInterceptorBeanPostProcessor(Collection securityInterceptors) { + this.securityInterceptors = securityInterceptors; } - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - ChannelSecurityMetadataSource channelSecurityMetadataSource = - (ChannelSecurityMetadataSource) this.interceptor.obtainSecurityMetadataSource(); - if (bean instanceof MessageChannel && - shouldProxy(beanName, (MessageChannel) bean, channelSecurityMetadataSource)) { - ProxyFactory proxyFactory = new ProxyFactory(bean); - proxyFactory.addAdvisor(new DefaultPointcutAdvisor(this.interceptor)); - return proxyFactory.getProxy(); + if (bean instanceof MessageChannel) { + for (ChannelSecurityInterceptor securityInterceptor : securityInterceptors) { + ChannelSecurityMetadataSource channelSecurityMetadataSource = + (ChannelSecurityMetadataSource) securityInterceptor.obtainSecurityMetadataSource(); + if (this.shouldProxy(beanName, channelSecurityMetadataSource)) { + if (AopUtils.isAopProxy(bean) && bean instanceof Advised) { + ((Advised) bean).addAdvisor(new DefaultPointcutAdvisor(securityInterceptor)); + } + else { + ProxyFactory proxyFactory = new ProxyFactory(bean); + proxyFactory.addAdvisor(new DefaultPointcutAdvisor(securityInterceptor)); + bean = proxyFactory.getProxy(); + } + } + } } return bean; } - private boolean shouldProxy(String beanName, MessageChannel channel, ChannelSecurityMetadataSource channelSecurityMetadataSource) { + private boolean shouldProxy(String beanName, ChannelSecurityMetadataSource channelSecurityMetadataSource) { Set patterns = channelSecurityMetadataSource.getPatterns(); for (Pattern pattern : patterns) { if (pattern.matcher(beanName).matches()) { diff --git a/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecuredChannelsParser.java b/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecuredChannelsParser.java index 8ffe029021..6565596af9 100644 --- a/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecuredChannelsParser.java +++ b/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecuredChannelsParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -23,11 +23,13 @@ import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; +import org.springframework.integration.security.channel.ChannelSecurityInterceptor; +import org.springframework.integration.security.channel.ChannelSecurityMetadataSource; +import org.springframework.integration.security.channel.DefaultChannelAccessPolicy; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -36,18 +38,16 @@ import org.springframework.util.xml.DomUtils; * to control send and receive access, and creates a bean post-processor to apply the * interceptor to {@link org.springframework.messaging.MessageChannel}s * whose names match the specified patterns. - * + * * @author Jonas Partner * @author Mark Fisher + * @author Artem Bilan */ public class SecuredChannelsParser extends AbstractSingleBeanDefinitionParser { - private final static String BASE_PACKAGE_NAME = "org.springframework.integration.security"; - - @Override - protected String getBeanClassName(Element element) { - return BASE_PACKAGE_NAME + ".config.ChannelSecurityInterceptorBeanPostProcessor"; + protected Class getBeanClass(Element element) { + return ChannelSecurityInterceptor.class; } @Override @@ -57,23 +57,15 @@ public class SecuredChannelsParser extends AbstractSingleBeanDefinitionParser { @Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { - String securityMetadataSourceBeanName = this.parseSecurityMetadataSource(element, parserContext); - BeanDefinitionBuilder interceptorBuilder = BeanDefinitionBuilder.genericBeanDefinition( - BASE_PACKAGE_NAME + ".channel.ChannelSecurityInterceptor"); - interceptorBuilder.addConstructorArgReference(securityMetadataSourceBeanName); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(interceptorBuilder, element, "authentication-manager"); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(interceptorBuilder, element, "access-decision-manager"); - String interceptorBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName( - interceptorBuilder.getBeanDefinition(), parserContext.getRegistry()); - builder.addConstructorArgReference(interceptorBeanName); + builder.addConstructorArgValue(this.parseSecurityMetadataSource(element, parserContext)); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "authentication-manager"); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "access-decision-manager"); } - @SuppressWarnings({ "unchecked", "rawtypes" }) - private String parseSecurityMetadataSource(Element element, ParserContext parserContext) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( - BASE_PACKAGE_NAME + ".channel.ChannelSecurityMetadataSource"); + private BeanDefinition parseSecurityMetadataSource(Element element, ParserContext parserContext) { + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ChannelSecurityMetadataSource.class); List accessPolicyElements = DomUtils.getChildElementsByTagName(element, "access-policy"); - ManagedMap patternMappings = new ManagedMap(); + ManagedMap patternMappings = new ManagedMap(); for (Element accessPolicyElement : accessPolicyElements) { Pattern pattern = Pattern.compile(accessPolicyElement.getAttribute("pattern")); String sendAccess = accessPolicyElement.getAttribute("send-access"); @@ -82,17 +74,15 @@ public class SecuredChannelsParser extends AbstractSingleBeanDefinitionParser { parserContext.getReaderContext().error( "At least one of 'send-access' or 'receive-access' must be provided.", accessPolicyElement); } - BeanDefinitionBuilder accessPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition( - BASE_PACKAGE_NAME + ".channel.DefaultChannelAccessPolicy"); + BeanDefinitionBuilder accessPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultChannelAccessPolicy.class); accessPolicyBuilder.addConstructorArgValue(sendAccess); accessPolicyBuilder.addConstructorArgValue(receiveAccess); accessPolicyBuilder.getBeanDefinition().setRole(BeanDefinition.ROLE_SUPPORT); patternMappings.put(pattern, accessPolicyBuilder.getBeanDefinition()); } builder.addConstructorArgValue(patternMappings); - builder.setRole(BeanDefinition.ROLE_SUPPORT); - return BeanDefinitionReaderUtils.registerWithGeneratedName( - builder.getBeanDefinition(), parserContext.getRegistry()); + + return builder.getBeanDefinition(); } } diff --git a/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecurityIntegrationConfigurationInitializer.java b/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecurityIntegrationConfigurationInitializer.java new file mode 100644 index 0000000000..fbb745a154 --- /dev/null +++ b/spring-integration-security/src/main/java/org/springframework/integration/security/config/SecurityIntegrationConfigurationInitializer.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 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.security.config; + +import java.util.Collection; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.integration.config.IntegrationConfigurationInitializer; +import org.springframework.integration.security.channel.ChannelSecurityInterceptor; + +/** + * The Integration Security infrastructure {@code beanFactory} initializer. + * + * @author Artem Bilan + * @since 4.0 + */ +public class SecurityIntegrationConfigurationInitializer implements IntegrationConfigurationInitializer { + + @Override + public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException { + Collection securityInterceptors = beanFactory.getBeansOfType(ChannelSecurityInterceptor.class).values(); + beanFactory.addBeanPostProcessor(new ChannelSecurityInterceptorBeanPostProcessor(securityInterceptors)); + } + +} diff --git a/spring-integration-security/src/main/resources/META-INF/spring.factories b/spring-integration-security/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..1e50c2c7cc --- /dev/null +++ b/spring-integration-security/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.integration.config.IntegrationConfigurationInitializer=\ +org.springframework.integration.security.config.SecurityIntegrationConfigurationInitializer diff --git a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests-context.xml b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests-context.xml index 7fc63de88a..50d3ad0f7d 100644 --- a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests-context.xml +++ b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests-context.xml @@ -26,6 +26,8 @@ + + - \ No newline at end of file + diff --git a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests.java b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests.java index ab1e091697..6f8df4a552 100644 --- a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests.java +++ b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelAdapterSecurityIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2014 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. @@ -37,6 +37,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; /** * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan */ @ContextConfiguration public class ChannelAdapterSecurityIntegrationTests extends AbstractJUnit4SpringContextTests { @@ -45,6 +46,10 @@ public class ChannelAdapterSecurityIntegrationTests extends AbstractJUnit4Spring @Qualifier("securedChannelAdapter") MessageChannel securedChannelAdapter; + @Autowired + @Qualifier("securedChannelAdapter") + MessageChannel securedChannelAdapter2; + @Autowired @Qualifier("unsecuredChannelAdapter") MessageChannel unsecuredChannelAdapter; @@ -65,13 +70,14 @@ public class ChannelAdapterSecurityIntegrationTests extends AbstractJUnit4Spring login("bob", "bobspassword", "ROLE_ADMINA"); securedChannelAdapter.send(new GenericMessage("test")); } - + @Test @DirtiesContext public void testSecuredWithPermission() { login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT"); securedChannelAdapter.send(new GenericMessage("test")); - assertEquals("Wrong size of message list in target", 1, testConsumer.sentMessages.size()); + securedChannelAdapter2.send(new GenericMessage("test")); + assertEquals("Wrong size of message list in target", 2, testConsumer.sentMessages.size()); } @Test(expected = AccessDeniedException.class) @@ -81,6 +87,13 @@ public class ChannelAdapterSecurityIntegrationTests extends AbstractJUnit4Spring securedChannelAdapter.send(new GenericMessage("test")); } + @Test(expected = AccessDeniedException.class) + @DirtiesContext + public void testSecured2WithoutPermision() { + login("bob", "bobspassword", "ROLE_USER"); + securedChannelAdapter2.send(new GenericMessage("test")); + } + @Test(expected = AuthenticationException.class) @DirtiesContext public void testSecuredWithoutAuthenticating() { diff --git a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelSecurityInterceptorBeanPostProcessorTests.java b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelSecurityInterceptorBeanPostProcessorTests.java index 0a02f84a83..3438b4ea58 100644 --- a/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelSecurityInterceptorBeanPostProcessorTests.java +++ b/spring-integration-security/src/test/java/org/springframework/integration/security/channel/ChannelSecurityInterceptorBeanPostProcessorTests.java @@ -19,6 +19,7 @@ package org.springframework.integration.security.channel; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.util.Collections; import java.util.regex.Pattern; import org.junit.Test; @@ -38,7 +39,7 @@ public class ChannelSecurityInterceptorBeanPostProcessorTests { ChannelSecurityMetadataSource securityMetadataSource = new ChannelSecurityMetadataSource(); securityMetadataSource.addPatternMapping(Pattern.compile("secured.*"), new DefaultChannelAccessPolicy("ROLE_ADMIN", null)); ChannelSecurityInterceptor interceptor = new ChannelSecurityInterceptor(securityMetadataSource); - ChannelSecurityInterceptorBeanPostProcessor postProcessor = new ChannelSecurityInterceptorBeanPostProcessor(interceptor); + ChannelSecurityInterceptorBeanPostProcessor postProcessor = new ChannelSecurityInterceptorBeanPostProcessor(Collections.singletonList(interceptor)); QueueChannel securedChannel = new QueueChannel(); securedChannel.setBeanName("securedChannel"); MessageChannel postProcessedChannel = (MessageChannel) postProcessor.postProcessAfterInitialization(securedChannel, "securedChannel"); @@ -50,7 +51,7 @@ public class ChannelSecurityInterceptorBeanPostProcessorTests { ChannelSecurityMetadataSource securityMetadataSource = new ChannelSecurityMetadataSource(); securityMetadataSource.addPatternMapping(Pattern.compile("secured.*"), new DefaultChannelAccessPolicy("ROLE_ADMIN", null)); ChannelSecurityInterceptor interceptor = new ChannelSecurityInterceptor(securityMetadataSource); - ChannelSecurityInterceptorBeanPostProcessor postProcessor = new ChannelSecurityInterceptorBeanPostProcessor(interceptor); + ChannelSecurityInterceptorBeanPostProcessor postProcessor = new ChannelSecurityInterceptorBeanPostProcessor(Collections.singletonList(interceptor)); QueueChannel channel = new QueueChannel(); channel.setBeanName("testChannel"); MessageChannel postProcessedChannel = (MessageChannel) postProcessor.postProcessAfterInitialization(channel, "testChannel"); diff --git a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathHeaderEnricherParser.java b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathHeaderEnricherParser.java index 1ae830f95b..dd2591abe0 100644 --- a/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathHeaderEnricherParser.java +++ b/spring-integration-xml/src/main/java/org/springframework/integration/xml/config/XPathHeaderEnricherParser.java @@ -23,6 +23,7 @@ import org.w3c.dom.NodeList; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.integration.config.IntegrationConfigUtils; import org.springframework.integration.config.xml.AbstractTransformerParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.integration.xml.transformer.XPathHeaderEnricher; @@ -60,7 +61,7 @@ public class XPathHeaderEnricherParser extends AbstractTransformerParser { Element headerElement = (Element) node; String elementName = node.getLocalName(); if ("header".equals(elementName)) { - BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE + ".xml.transformer.XPathHeaderEnricher$XPathExpressionEvaluatingHeaderValueMessageProcessor"); String expressionString = headerElement.getAttribute("xpath-expression"); String expressionRef = headerElement.getAttribute("xpath-expression-ref");