From 9174a0b60c50e772f2c5ae53af418d04eec7bdba Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 27 Feb 2015 17:06:47 +0200 Subject: [PATCH 1/4] INT-3661: Fix the eager BF access from BPPs (P I) JIRA: https://jira.spring.io/browse/INT-3661 ##Status Quo Previously there were a lot of noise from the `PostProcessorRegistrationDelegate$BeanPostProcessorChecker` for early access for beans. That may produce some side-effects when some of `BeanFactoryPostProcessor`s won't adjust those beans. The issue is based on two facts: 1. Loading beans from `BPP`, e.g. `IntegrationEvaluationContextAwareBeanPostProcessor` (or `ChannelSecurityInterceptorBeanPostProcessor` - https://jira.spring.io/browse/INT-3663) 2. Loading beans from `setBeanFactory()/setApplicationContext()` container methods ## The fix * Move all stuff from `setBeanFactory()` with access to the `BeanFactory` (e.g. `this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory);`) to some other lazy-load methods like `getMessageBuilderFactory()` * Fix parser tests to `assertNotSame` for `messageBuilderFactory` since there is no activity for target components to lazy-load the stuff * Polish some test according the new lazy-load logic * Rework `IntegrationEvaluationContextAwareBeanPostProcessor` to the `SmartInitializingSingleton` and make it `Ordered` * Populate `beanFactory` for the internal instance of `connectionFactory` in the `TcpSyslogReceivingChannelAdapter` * Populate `beanFactory` for the internal `UnicastReceivingChannelAdapter` in the `UdpSyslogReceivingChannelAdapter` * Add `log.info` that `UdpSyslogReceivingChannelAdapter` overrides `outputChannel` for the provided `UnicastReceivingChannelAdapter` * Change the internal `MessageChannel` in the `UdpSyslogReceivingChannelAdapter` to the `FixedSubscriberChannel` for better performance --- .../amqp/config/AmqpChannelParserTests.java | 5 +- ...tractAggregatingMessageGroupProcessor.java | 25 ++++++++-- .../MethodInvokingMessageListProcessor.java | 12 ++++- .../aop/MessagePublishingInterceptor.java | 25 +++++++--- .../context/IntegrationObjectSupport.java | 11 +++-- .../integration/core/MessagingTemplate.java | 35 ++++++++++++-- .../dispatcher/BroadcastingDispatcher.java | 22 +++++++-- ...aluationContextAwareBeanPostProcessor.java | 30 ++++++++++-- .../handler/MethodInvokingMessageHandler.java | 7 +++ .../advice/IdempotentReceiverInterceptor.java | 22 +++++++-- .../store/AbstractMessageGroupStore.java | 14 ++++-- .../channel/BeanFactoryChannelResolver.java | 43 +++++++++-------- .../converter/MapMessageConverter.java | 21 ++++++--- .../converter/SimpleMessageConverter.java | 42 +++++++++++++---- .../AbstractJacksonJsonMessageParser.java | 18 +++++-- .../AbstractMessageProcessingTransformer.java | 28 ++++++----- ...ProcessingHeaderValueMessageProcessor.java | 13 ++++- .../util/AbstractExpressionEvaluator.java | 13 +++-- .../util/MessagingMethodInvokerHelper.java | 47 +++++++++++++------ .../MethodInvokingReleaseStrategyTests.java | 17 +++++-- .../config/AggregatorParserTests.java | 11 +++-- .../PublishSubscribeChannelParserTests.java | 19 +++++++- .../gateway/GatewayInterfaceTests.java | 5 +- .../AbstractInboundFileSynchronizer.java | 1 - .../AbstractFilePayloadTransformer.java | 23 +++++++-- .../FileToStringTransformerParserTests.java | 3 +- .../ip/tcp/connection/TcpMessageMapper.java | 20 ++++++-- .../ip/udp/DatagramPacketMessageMapper.java | 23 +++++++-- .../ip/config/ParserUnitTests.java | 14 +++--- .../connection/TcpNioConnectionReadTests.java | 5 +- .../jdbc/store/JdbcChannelMessageStore.java | 7 ++- .../jms/config/JmsChannelParserTests.java | 7 ++- .../mail/MailReceivingMessageSource.java | 16 +++++-- .../AbstractMailMessageTransformer.java | 12 ++++- ...stractConfigurableMongoDbMessageStore.java | 22 +++++---- ...stractMqttMessageDrivenChannelAdapter.java | 6 ++- .../support/DefaultPahoMessageConverter.java | 19 ++++++-- .../redis/config/RedisChannelParserTests.java | 4 +- ...RedisInboundChannelAdapterParserTests.java | 5 +- ...edisOutboundChannelAdapterParserTests.java | 4 +- .../syslog/DefaultMessageConverter.java | 18 +++++-- .../TcpSyslogReceivingChannelAdapter.java | 6 ++- .../UdpSyslogReceivingChannelAdapter.java | 26 +++++++--- 43 files changed, 543 insertions(+), 183 deletions(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java index 3049c2fbe8c..503fac8b13b 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -57,7 +58,7 @@ public void interceptor() { TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue()); channel = context.getBean("pubSub", MessageChannel.class); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(channel, "dispatcher.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(channel, "dispatcher.messageBuilderFactory")); assertSame(mbf, TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory")); assertTrue(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class)); assertFalse(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class)); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java index a4cd5acc8d4..52068949e8e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java @@ -43,6 +43,7 @@ * @author Mark Fisher * @author Dave Syer * @author Gary Russell + * @author Artem Bilan * @since 2.0 */ public abstract class AbstractAggregatingMessageGroupProcessor implements MessageGroupProcessor, @@ -52,9 +53,23 @@ public abstract class AbstractAggregatingMessageGroupProcessor implements Messag private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; + @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -64,11 +79,12 @@ public final Object processMessageGroup(MessageGroup group) { Map headers = this.aggregateHeaders(group); Object payload = this.aggregatePayloads(group, headers); AbstractIntegrationMessageBuilder builder; + MessageBuilderFactory messageBuilderFactory = getMessageBuilderFactory(); if (payload instanceof Message) { - builder = this.messageBuilderFactory.fromMessage((Message) payload).copyHeadersIfAbsent(headers); + builder = messageBuilderFactory.fromMessage((Message) payload).copyHeadersIfAbsent(headers); } else { - builder = this.messageBuilderFactory.withPayload(payload).copyHeadersIfAbsent(headers); + builder = messageBuilderFactory.withPayload(payload).copyHeadersIfAbsent(headers); } return builder.popSequenceDetails().build(); @@ -89,7 +105,8 @@ protected Map aggregateHeaders(MessageGroup group) { for (Entry entry : message.getHeaders().entrySet()) { String key = entry.getKey(); if (MessageHeaders.ID.equals(key) || MessageHeaders.TIMESTAMP.equals(key) - || IntegrationMessageHeaderAccessor.SEQUENCE_SIZE.equals(key) || IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER.equals(key)) { + || IntegrationMessageHeaderAccessor.SEQUENCE_SIZE.equals(key) + || IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER.equals(key)) { continue; } Object value = entry.getValue(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java index 89872231aef..2d24a589faa 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/MethodInvokingMessageListProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,14 +22,16 @@ import java.util.Collection; import java.util.Map; +import org.springframework.beans.factory.BeanFactory; import org.springframework.messaging.Message; import org.springframework.integration.util.AbstractExpressionEvaluator; import org.springframework.integration.util.MessagingMethodInvokerHelper; /** * A MessageListProcessor implementation that invokes a method on a target POJO. - * + * * @author Dave Syer + * @author Artem Bilan * @since 2.0 */ public class MethodInvokingMessageListProcessor extends AbstractExpressionEvaluator { @@ -57,6 +59,12 @@ public MethodInvokingMessageListProcessor(Object targetObject, Class(targetObject, annotationType, Object.class, true); } + @Override + public void setBeanFactory(BeanFactory beanFactory) { + super.setBeanFactory(beanFactory); + this.delegate.setBeanFactory(beanFactory); + } + public String toString() { return delegate.toString(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java index d8aa321ff10..54af9efb62f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,6 @@ import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; import org.springframework.expression.ParseException; -import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.integration.core.MessagingTemplate; @@ -63,9 +62,9 @@ public class MessagePublishingInterceptor implements MethodInterceptor, BeanFact private final MessagingTemplate messagingTemplate = new MessagingTemplate(); - private volatile PublisherMetadataSource metadataSource; + private final ExpressionParser parser = new SpelExpressionParser(); - private final ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); + private volatile PublisherMetadataSource metadataSource; private volatile DestinationResolver channelResolver; @@ -75,6 +74,8 @@ public class MessagePublishingInterceptor implements MethodInterceptor, BeanFact private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + private volatile String defaultChannelName; public MessagePublishingInterceptor(PublisherMetadataSource metadataSource) { @@ -114,7 +115,16 @@ public void setChannelResolver(DestinationResolver channelResolv public void setBeanFactory(BeanFactory beanFactory) throws BeansException { this.beanFactory = beanFactory; this.messagingTemplate.setBeanFactory(beanFactory); - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -163,9 +173,10 @@ private void publishMessage(Method method, StandardEvaluationContext context) th Expression expression = this.parser.parseExpression(payloadExpressionString); Object result = expression.getValue(context); if (result != null) { + MessageBuilderFactory messageBuilderFactory = getMessageBuilderFactory(); AbstractIntegrationMessageBuilder builder = (result instanceof Message) - ? this.messageBuilderFactory.fromMessage((Message) result) - : this.messageBuilderFactory.withPayload(result); + ? messageBuilderFactory.fromMessage((Message) result) + : messageBuilderFactory.withPayload(result); Map headers = this.evaluateHeaders(method, context); if (headers != null) { builder.copyHeaders(headers); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java index 082588853dc..2c566fcb3bd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/context/IntegrationObjectSupport.java @@ -119,10 +119,9 @@ public String getComponentType() { } @Override - public final void setBeanFactory(BeanFactory beanFactory) { + public void setBeanFactory(BeanFactory beanFactory) { Assert.notNull(beanFactory, "'beanFactory' must not be null"); this.beanFactory = beanFactory; - this.integrationProperties = IntegrationContextUtils.getIntegrationProperties(this.beanFactory); } @Override @@ -143,9 +142,15 @@ public void setChannelResolver(DestinationResolver channelResolv @Override public final void afterPropertiesSet() { + this.integrationProperties = IntegrationContextUtils.getIntegrationProperties(this.beanFactory); try { if (this.messageBuilderFactory == null) { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + else { + this.messageBuilderFactory = new DefaultMessageBuilderFactory(); + } } this.onInit(); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java b/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java index f287e03394f..8ccf34a60e7 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/core/MessagingTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.core; import java.util.Properties; @@ -22,6 +23,7 @@ import org.springframework.integration.context.IntegrationContextUtils; import org.springframework.integration.context.IntegrationProperties; import org.springframework.integration.support.channel.BeanFactoryChannelResolver; +import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.core.GenericMessagingTemplate; @@ -35,6 +37,10 @@ */ public class MessagingTemplate extends GenericMessagingTemplate { + private BeanFactory beanFactory; + + private volatile boolean throwExceptionOnLateReplySet; + /** * Create a MessagingTemplate with no default channel. Note, that one * may be provided by invoking {@link #setDefaultChannel(MessageChannel)}. @@ -55,10 +61,14 @@ public MessagingTemplate(MessageChannel defaultChannel) { */ @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + this.beanFactory = beanFactory; super.setDestinationResolver(new BeanFactoryChannelResolver(beanFactory)); - Properties integrationProperties = IntegrationContextUtils.getIntegrationProperties(beanFactory); - Boolean throwExceptionOnLateReply = Boolean.valueOf(integrationProperties.getProperty(IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY)); - this.setThrowExceptionOnLateReply(throwExceptionOnLateReply); + } + + @Override + public void setThrowExceptionOnLateReply(boolean throwExceptionOnLateReply) { + super.setThrowExceptionOnLateReply(throwExceptionOnLateReply); + this.throwExceptionOnLateReplySet = true; } /** @@ -70,4 +80,21 @@ public void setDefaultChannel(MessageChannel channel) { super.setDefaultDestination(channel); } + @Override + public Message sendAndReceive(MessageChannel destination, Message requestMessage) { + if (!this.throwExceptionOnLateReplySet) { + synchronized (this) { + if (!this.throwExceptionOnLateReplySet) { + Properties integrationProperties = + IntegrationContextUtils.getIntegrationProperties(this.beanFactory); + Boolean throwExceptionOnLateReply = Boolean.valueOf(integrationProperties + .getProperty(IntegrationProperties.THROW_EXCEPTION_ON_LATE_REPLY)); + super.setThrowExceptionOnLateReply(throwExceptionOnLateReply); + this.throwExceptionOnLateReplySet = true; + } + } + } + return super.sendAndReceive(destination, requestMessage); + } + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java index ce5fc0951aa..c9848251401 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dispatcher/BroadcastingDispatcher.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ * @author Iwein Fuld * @author Gary Russell * @author Oleg Zhurakousky + * @author Artem Bilan */ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFactoryAware { @@ -59,6 +60,10 @@ public class BroadcastingDispatcher extends AbstractDispatcher implements BeanFa private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; + public BroadcastingDispatcher() { this(null, false); @@ -114,7 +119,17 @@ public void setMinSubscribers(int minSubscribers) { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -127,7 +142,7 @@ public boolean dispatch(Message message) { } int sequenceSize = handlers.size(); for (final MessageHandler handler : handlers) { - final Message messageToSend = (!this.applySequence) ? message : this.messageBuilderFactory.fromMessage(message) + final Message messageToSend = (!this.applySequence) ? message : getMessageBuilderFactory().fromMessage(message) .pushSequenceDetails(message.getHeaders().getId(), sequenceNumber++, sequenceSize).build(); if (this.executor != null) { this.executor.execute(new Runnable() { @@ -174,5 +189,4 @@ else if (this.logger.isWarnEnabled()) { } } - } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAwareBeanPostProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAwareBeanPostProcessor.java index e93451f0e1b..f7026e475d9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAwareBeanPostProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAwareBeanPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,15 @@ package org.springframework.integration.expression; +import java.util.ArrayList; +import java.util.List; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; +import org.springframework.beans.factory.SmartInitializingSingleton; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.core.Ordered; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.integration.context.IntegrationContextUtils; @@ -28,7 +33,11 @@ * @author Gary Russell * @since 3.0 */ -public class IntegrationEvaluationContextAwareBeanPostProcessor implements BeanPostProcessor, BeanFactoryAware { +public class IntegrationEvaluationContextAwareBeanPostProcessor + implements BeanPostProcessor, Ordered, BeanFactoryAware, SmartInitializingSingleton { + + private final List evaluationContextAwares = + new ArrayList(); private volatile BeanFactory beanFactory; @@ -40,8 +49,7 @@ public void setBeanFactory(BeanFactory beanFactory) throws BeansException { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof IntegrationEvaluationContextAware) { - StandardEvaluationContext evaluationContext = IntegrationContextUtils.getEvaluationContext(this.beanFactory); - ((IntegrationEvaluationContextAware) bean).setIntegrationEvaluationContext(evaluationContext); + this.evaluationContextAwares.add((IntegrationEvaluationContextAware) bean); } return bean; } @@ -50,4 +58,18 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { return bean; } + + @Override + public void afterSingletonsInstantiated() { + StandardEvaluationContext evaluationContext = IntegrationContextUtils.getEvaluationContext(this.beanFactory); + for (IntegrationEvaluationContextAware evaluationContextAware : this.evaluationContextAwares) { + evaluationContextAware.setIntegrationEvaluationContext(evaluationContext); + } + } + + @Override + public int getOrder() { + return LOWEST_PRECEDENCE; + } + } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java index 144bf94cfce..6a026dcd3e4 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageHandler.java @@ -18,6 +18,7 @@ import java.lang.reflect.Method; +import org.springframework.beans.factory.BeanFactory; import org.springframework.context.Lifecycle; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -47,6 +48,12 @@ public MethodInvokingMessageHandler(Object object, String methodName) { processor = new MethodInvokingMessageProcessor(object, methodName); } + @Override + public void setBeanFactory(BeanFactory beanFactory) { + super.setBeanFactory(beanFactory); + this.processor.setBeanFactory(beanFactory); + } + public void setComponentType(String componentType) { this.componentType = componentType; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java index cb4eb8f4c3b..eafe0d82602 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/IdempotentReceiverInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +71,11 @@ public class IdempotentReceiverInterceptor implements MethodInterceptor, BeanFac private volatile boolean throwExceptionOnRejection; - private MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; public IdempotentReceiverInterceptor(MessageSelector messageSelector) { Assert.notNull(messageSelector); @@ -124,7 +128,17 @@ public void setDiscardChannel(MessageChannel discardChannel) { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -161,7 +175,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable { } if (!discarded) { - arguments[0] = this.messageBuilderFactory.fromMessage(message) + arguments[0] = getMessageBuilderFactory().fromMessage(message) .setHeader(IntegrationMessageHeaderAccessor.DUPLICATE_MESSAGE, true).build(); } else { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java index 84c0c24e43c..432c38b62b2 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/store/AbstractMessageGroupStore.java @@ -33,9 +33,9 @@ * @author Dave Syer * @author Oleg Zhurakousky * @author Gary Russell + * @author Artem Bilan * * @since 2.0 - * */ @ManagedResource @IntegrationManagedResource @@ -52,6 +52,8 @@ public abstract class AbstractMessageGroupStore implements MessageGroupStore, It private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + public AbstractMessageGroupStore() { super(); } @@ -59,11 +61,17 @@ public AbstractMessageGroupStore() { @Override public final void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } /** diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java b/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java index 91935bd058d..0afe61c6c33 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/channel/BeanFactoryChannelResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,6 +38,7 @@ * * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan * * @see org.springframework.beans.factory.BeanFactory */ @@ -49,6 +50,8 @@ public class BeanFactoryChannelResolver implements DestinationResolverThe BeanFactory to access must be set via setBeanFactory. @@ -66,30 +69,16 @@ public BeanFactoryChannelResolver() { * replaced by the {@link BeanFactory} that creates it (c.f. the * {@link BeanFactoryAware} contract). So only use this constructor if you * are instantiating this object explicitly rather than defining a bean. - * * @param beanFactory the bean factory to be used to lookup {@link MessageChannel}s. */ public BeanFactoryChannelResolver(BeanFactory beanFactory) { Assert.notNull(beanFactory, "BeanFactory must not be null"); - this.lookupHeaderChannelRegistry(beanFactory); + this.beanFactory = beanFactory; } @Override public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; - this.lookupHeaderChannelRegistry(beanFactory); - } - - private void lookupHeaderChannelRegistry(BeanFactory beanFactory) { - this.beanFactory = beanFactory; - try { - this.replyChannelRegistry = beanFactory.getBean( - IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, - HeaderChannelRegistry.class); - } - catch (Exception e) { - logger.debug("No HeaderChannelRegistry found"); - } } @Override @@ -99,15 +88,31 @@ public MessageChannel resolveDestination(String name) { return this.beanFactory.getBean(name, MessageChannel.class); } catch (BeansException e) { + if (!this.initialized) { + synchronized (this) { + if (!this.initialized) { + try { + this.replyChannelRegistry = this.beanFactory.getBean( + IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, + HeaderChannelRegistry.class); + } + catch (Exception ex) { + logger.debug("No HeaderChannelRegistry found"); + } + this.initialized = true; + } + } + } if (this.replyChannelRegistry != null) { MessageChannel channel = this.replyChannelRegistry.channelNameToChannel(name); if (channel != null) { return channel; } } - throw new DestinationResolutionException( - "failed to look up MessageChannel with name '" + name + "' in the BeanFactory" - + (this.replyChannelRegistry == null ? " (and there is no HeaderChannelRegistry present)." : "."), e); + throw new DestinationResolutionException("failed to look up MessageChannel with name '" + name + + "' in the BeanFactory" + + (this.replyChannelRegistry == null ? " (and there is no HeaderChannelRegistry present)." : "."), + e); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/MapMessageConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/MapMessageConverter.java index 8cb7971ebe2..f0f26c3ef0f 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/MapMessageConverter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/MapMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.support.converter; import java.util.Arrays; @@ -32,7 +33,9 @@ /** * Converts to/from a Map with 2 keys ('headers' and 'payload'). + * * @author Gary Russell + * @author Artem Bilan * @since 3.0 * */ @@ -46,15 +49,22 @@ public class MapMessageConverter implements MessageConverter, BeanFactoryAware { private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + @Override public final void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } /** @@ -87,7 +97,7 @@ public Message toMessage(Object object, MessageHeaders messageHeaders) { Map map = (Map) object; Object payload = map.get("payload"); Assert.notNull(payload, "'payload' entry cannot be null"); - AbstractIntegrationMessageBuilder messageBuilder = this.messageBuilderFactory.withPayload(payload); + AbstractIntegrationMessageBuilder messageBuilder = getMessageBuilderFactory().withPayload(payload); @SuppressWarnings("unchecked") Map headers = (Map) map.get("headers"); if (headers != null) { @@ -96,8 +106,7 @@ public Message toMessage(Object object, MessageHeaders messageHeaders) { } messageBuilder.copyHeaders(headers); } - Message convertedMessage = messageBuilder.build(); - return convertedMessage; + return messageBuilder.build(); } @Override diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java index c835c30345e..dfab8f14c20 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/converter/SimpleMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,7 @@ /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan * @since 2.0 */ @SuppressWarnings({"unchecked", "rawtypes"}) @@ -43,37 +44,60 @@ public class SimpleMessageConverter implements MessageConverter, BeanFactoryAwar private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; + public SimpleMessageConverter() { this(null, null); } public SimpleMessageConverter(InboundMessageMapper inboundMessageMapper) { this(inboundMessageMapper, - (inboundMessageMapper instanceof OutboundMessageMapper ? (OutboundMessageMapper) inboundMessageMapper : null)); + (inboundMessageMapper instanceof OutboundMessageMapper + ? (OutboundMessageMapper) inboundMessageMapper + : null)); } public SimpleMessageConverter(OutboundMessageMapper outboundMessageMapper) { - this(outboundMessageMapper instanceof InboundMessageMapper ? (InboundMessageMapper) outboundMessageMapper : null, + this(outboundMessageMapper instanceof InboundMessageMapper + ? (InboundMessageMapper) outboundMessageMapper + : null, outboundMessageMapper); } - public SimpleMessageConverter(InboundMessageMapper inboundMessageMapper, OutboundMessageMapper outboundMessageMapper) { + public SimpleMessageConverter(InboundMessageMapper inboundMessageMapper, + OutboundMessageMapper outboundMessageMapper) { this.setInboundMessageMapper(inboundMessageMapper); this.setOutboundMessageMapper(outboundMessageMapper); } public void setInboundMessageMapper(InboundMessageMapper inboundMessageMapper) { - this.inboundMessageMapper = (inboundMessageMapper != null) ? inboundMessageMapper : new DefaultInboundMessageMapper(); + this.inboundMessageMapper = (inboundMessageMapper != null) + ? inboundMessageMapper + : new DefaultInboundMessageMapper(); } public void setOutboundMessageMapper(OutboundMessageMapper outboundMessageMapper) { - this.outboundMessageMapper = (outboundMessageMapper != null) ? outboundMessageMapper : new DefaultOutboundMessageMapper(); + this.outboundMessageMapper = (outboundMessageMapper != null + ? outboundMessageMapper + : new DefaultOutboundMessageMapper()); } @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -107,8 +131,9 @@ public Message toMessage(Object object) throws Exception { if (object instanceof Message) { return (Message) object; } - return messageBuilderFactory.withPayload(object).build(); + return getMessageBuilderFactory().withPayload(object).build(); } + } @@ -118,6 +143,7 @@ private class DefaultOutboundMessageMapper implements OutboundMessageMapper message) throws Exception { return (message != null) ? message.getPayload() : null; } + } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java index 526bc6a9fa7..2138fc978d1 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,17 +42,27 @@ abstract class AbstractJacksonJsonMessageParser

implements JsonInboundMessage private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private BeanFactory beanFactory; + + private volatile boolean messageBuilderFactorySet; + protected AbstractJacksonJsonMessageParser(JsonObjectMapper objectMapper) { this.objectMapper = objectMapper; } @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -64,7 +74,7 @@ public Message doInParser(JsonInboundMessageMapper messageMapper, String json if (messageMapper.isMapToPayload()) { Object payload = this.readPayload(parser, jsonMessage); - return this.messageBuilderFactory.withPayload(payload).build(); + return getMessageBuilderFactory().withPayload(payload).build(); } else { return this.parseWithHeaders(parser, jsonMessage); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java index ea0579cd816..ed5f4b1bd16 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/AbstractMessageProcessingTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.context.Lifecycle; -import org.springframework.core.convert.ConversionService; -import org.springframework.integration.handler.AbstractMessageProcessor; import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.support.DefaultMessageBuilderFactory; import org.springframework.integration.support.MessageBuilderFactory; @@ -41,25 +39,31 @@ public abstract class AbstractMessageProcessingTransformer private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; + protected AbstractMessageProcessingTransformer(MessageProcessor messageProcessor) { Assert.notNull(messageProcessor, "messageProcessor must not be null"); this.messageProcessor = messageProcessor; } - protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; - } - @Override public void setBeanFactory(BeanFactory beanFactory) { + this.beanFactory = beanFactory; if (this.messageProcessor instanceof BeanFactoryAware) { ((BeanFactoryAware) this.messageProcessor).setBeanFactory(beanFactory); } - ConversionService conversionService = IntegrationUtils.getConversionService(beanFactory); - if (conversionService != null && this.messageProcessor instanceof AbstractMessageProcessor) { - ((AbstractMessageProcessor) this.messageProcessor).setConversionService(conversionService); + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; } - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + return this.messageBuilderFactory; } @Override @@ -90,7 +94,7 @@ public final Message transform(Message message) { if (result instanceof Message) { return (Message) result; } - return this.messageBuilderFactory.withPayload(result).copyHeaders(message.getHeaders()).build(); + return getMessageBuilderFactory().withPayload(result).copyHeaders(message.getHeaders()).build(); } } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/MessageProcessingHeaderValueMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/MessageProcessingHeaderValueMessageProcessor.java index 1729cc08c67..92100807406 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/MessageProcessingHeaderValueMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/transformer/support/MessageProcessingHeaderValueMessageProcessor.java @@ -16,6 +16,9 @@ package org.springframework.integration.transformer.support; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.integration.handler.MessageProcessor; import org.springframework.integration.handler.MethodInvokingMessageProcessor; import org.springframework.messaging.Message; @@ -25,7 +28,8 @@ * @author Artem Bilan * @since 3.0 */ -public class MessageProcessingHeaderValueMessageProcessor extends AbstractHeaderValueMessageProcessor { +public class MessageProcessingHeaderValueMessageProcessor extends AbstractHeaderValueMessageProcessor + implements BeanFactoryAware { private final MessageProcessor targetProcessor; @@ -41,6 +45,13 @@ public MessageProcessingHeaderValueMessageProcessor(Object targetObject, String this.targetProcessor = new MethodInvokingMessageProcessor(targetObject, method); } + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + if (this.targetProcessor instanceof BeanFactoryAware) { + ((BeanFactoryAware) this.targetProcessor).setBeanFactory(beanFactory); + } + } + public Object processMessage(Message message) { return this.targetProcessor.processMessage(message); } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java b/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java index b4fba6ca59a..0eed9e99957 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -54,7 +54,9 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I private volatile BeanFactory beanFactory; - private volatile MessageBuilderFactory messageBuilderFactory; + private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + + private volatile boolean messageBuilderFactorySet; /** * Specify a BeanFactory in order to enable resolution via @beanName in the expression. @@ -67,7 +69,6 @@ public void setBeanFactory(final BeanFactory beanFactory) { if (this.evaluationContext != null && this.evaluationContext.getBeanResolver() == null) { this.evaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory)); } - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); } } @@ -114,6 +115,12 @@ protected final StandardEvaluationContext getEvaluationContext(boolean beanFacto this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory); } this.evaluationContext.setTypeConverter(this.typeConverter); + if (this.beanFactory != null) { + ConversionService conversionService = IntegrationUtils.getConversionService(beanFactory); + if (conversionService != null) { + this.typeConverter.setConversionService(conversionService); + } + } } return this.evaluationContext; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java index f453a2b2b77..1d6ea38f217 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,6 +112,14 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator private final boolean canProcessMessageList; + private Class annotationType; + + private volatile boolean initialized; + + private String methodName; + + private Method method; + public MessagingMethodInvokerHelper(Object targetObject, Method method, Class expectedType, boolean canProcessMessageList) { @@ -184,6 +192,7 @@ private MessagingMethodInvokerHelper(Object targetObject, Class expectedType, boolean canProcessMessageList) { this.canProcessMessageList = canProcessMessageList; Assert.notNull(method, "method must not be null"); + this.method = method; this.expectedType = expectedType; this.requiresReply = expectedType != null; if (expectedType != null) { @@ -201,12 +210,13 @@ private MessagingMethodInvokerHelper(Object targetObject, Class annotationType, String methodName, Class expectedType, boolean canProcessMessageList) { + this.annotationType = annotationType; + this.methodName = methodName; this.canProcessMessageList = canProcessMessageList; Assert.notNull(targetObject, "targetObject must not be null"); this.expectedType = expectedType; @@ -238,7 +248,6 @@ private MessagingMethodInvokerHelper(Object targetObject, Class annotationType) { + private void prepareEvaluationContext() { + StandardEvaluationContext context = getEvaluationContext(false); Class targetType = AopUtils.getTargetClass(this.targetObject); - if (method instanceof Method) { - context.registerMethodFilter(targetType, new FixedMethodFilter((Method) method)); - if (expectedType != null) { + if (this.method != null) { + context.registerMethodFilter(targetType, new FixedMethodFilter(this.method)); + if (this.expectedType != null) { Assert.state(context.getTypeConverter() - .canConvert(TypeDescriptor.valueOf(((Method) method).getReturnType()), - TypeDescriptor.valueOf(expectedType)), - "Cannot convert to expected type (" + expectedType + ") from " + method); + .canConvert(TypeDescriptor.valueOf((this.method).getReturnType()), + TypeDescriptor.valueOf(this.expectedType)), + "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); } } - else if (method == null || method instanceof String) { - AnnotatedMethodFilter filter = new AnnotatedMethodFilter(annotationType, (String) method, + else { + AnnotatedMethodFilter filter = new AnnotatedMethodFilter(this.annotationType, this.methodName, this.requiresReply); Assert.state(canReturnExpectedType(filter, targetType, context.getTypeConverter()), - "Cannot convert to expected type (" + expectedType + ") from " + method); + "Cannot convert to expected type (" + this.expectedType + ") from " + this.method); context.registerMethodFilter(targetType, filter); } - context.setVariable("target", targetObject); + context.setVariable("target", this.targetObject); } private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class targetType, @@ -291,6 +300,14 @@ private boolean canReturnExpectedType(AnnotatedMethodFilter filter, Class tar } private T processInternal(ParametersWrapper parameters) throws Exception { + if (!this.initialized) { + synchronized (this) { + if (!this.initialized) { + prepareEvaluationContext(); + this.initialized = true; + } + } + } HandlerMethod candidate = this.findHandlerMethodForParameters(parameters); Assert.notNull(candidate, "No candidate methods found for messages."); Expression expression = candidate.getExpression(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategyTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategyTests.java index 2a5423e925e..09987e19981 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategyTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aggregator/MethodInvokingReleaseStrategyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.integration.aggregator; +import static org.mockito.Mockito.mock; + import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; @@ -23,16 +25,18 @@ import org.junit.Assert; import org.junit.Test; + import org.springframework.core.convert.ConversionFailedException; import org.springframework.integration.IntegrationMessageHeaderAccessor; -import org.springframework.messaging.support.GenericMessage; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.messaging.Message; +import org.springframework.messaging.support.GenericMessage; /** * @author Marius Bogoevici * @author Dave Syer + * @author Artem Bilan */ public class MethodInvokingReleaseStrategyTests { @@ -248,13 +252,18 @@ public boolean listSubclassParameter(LinkedList l1) { @Test(expected = IllegalStateException.class) public void testWrongReturnTypeUsingMethodObject() throws SecurityException, NoSuchMethodException { class TestReleaseStrategy { + @SuppressWarnings("unused") public int wrongReturnType(List> message) { return 0; } + } - new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), TestReleaseStrategy.class.getMethod( - "wrongReturnType", new Class[] { List.class })); + + MethodInvokingReleaseStrategy wrongReturnType = + new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), TestReleaseStrategy.class.getMethod( + "wrongReturnType", new Class[] {List.class})); + wrongReturnType.canRelease(mock(MessageGroup.class)); } private static MessageGroup createListOfMessages(int size) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java index 18582acbc77..bfeaac96653 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; @@ -94,7 +95,7 @@ public void testAggregation() { Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithReference.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); } @Test @@ -121,7 +122,7 @@ public void handleMessage(Message message) throws MessageRejectedException, M Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithExpressions.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); assertTrue(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class)); } @@ -175,7 +176,7 @@ public void testSimpleJavaBeanAggregator() { Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); } @Test(expected = BeanCreationException.class) @@ -249,7 +250,7 @@ public void testAggregationWithExpressionsAndPojoAggregator() { AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) TestUtils.getPropertyValue(aggregatorConsumer, "handler"); MethodInvokingMessageGroupProcessor messageGroupProcessor = (MethodInvokingMessageGroupProcessor) TestUtils.getPropertyValue(aggregatingMessageHandler, "outputProcessor"); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(messageGroupProcessor, "messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(messageGroupProcessor, "messageBuilderFactory")); Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor.delegate.targetObject"); assertSame(context.getBean("aggregatorBean"), messageGroupProcessorTargetObject); ReleaseStrategy releaseStrategy = (ReleaseStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "releaseStrategy"); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java index d0c4864fab3..a8cb2c01268 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/PublishSubscribeChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,11 +33,16 @@ import org.springframework.integration.dispatcher.BroadcastingDispatcher; import org.springframework.integration.support.utils.IntegrationUtils; import org.springframework.integration.util.ErrorHandlingTaskExecutor; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessageHandler; +import org.springframework.messaging.MessagingException; +import org.springframework.messaging.support.GenericMessage; import org.springframework.util.ErrorHandler; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ public class PublishSubscribeChannelParserTests { @@ -50,10 +55,20 @@ public void defaultChannel() { DirectFieldAccessor accessor = new DirectFieldAccessor(channel); BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher"); + dispatcher.setApplySequence(true); + dispatcher.addHandler(new MessageHandler() { + + @Override + public void handleMessage(Message message) throws MessagingException { + + } + + }); + dispatcher.dispatch(new GenericMessage("foo")); DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher); assertNull(dispatcherAccessor.getPropertyValue("executor")); assertFalse((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures")); - assertFalse((Boolean) dispatcherAccessor.getPropertyValue("applySequence")); + assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence")); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); assertSame(mbf, dispatcherAccessor.getPropertyValue("messageBuilderFactory")); context.close(); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java index beff7d1c0c0..833cfe6364b 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; @@ -134,7 +135,7 @@ public void handleMessage(Message message) throws MessagingException { assertTrue(called.get()); Map gateways = TestUtils.getPropertyValue(ac.getBean("&sampleGateway"), "gatewayMap", Map.class); Object mbf = ac.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(gateways.values().iterator().next(), + assertNotSame(mbf, TestUtils.getPropertyValue(gateways.values().iterator().next(), "messageConverter.messageBuilderFactory")); ac.close(); } diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java index c38e1c15be7..e35b5a5ae05 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/remote/synchronizer/AbstractInboundFileSynchronizer.java @@ -151,7 +151,6 @@ public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) @Override public final void afterPropertiesSet() { Assert.notNull(this.remoteDirectory, "remoteDirectory must not be null"); - Assert.notNull(this.evaluationContext, "evaluationContext must not be null"); } protected final List filterFiles(F[] files) { diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformer.java b/spring-integration-file/src/main/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformer.java index f701fa67332..48b724c6f07 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformer.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/transformer/AbstractFilePayloadTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ * Base class for transformers that convert a File payload. * * @author Mark Fisher + * @author Artem Bilan */ public abstract class AbstractFilePayloadTransformer implements Transformer, BeanFactoryAware { @@ -46,6 +47,10 @@ public abstract class AbstractFilePayloadTransformer implements Transformer, private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private boolean messageBuilderFactorySet; + + private volatile BeanFactory beanFactory; + /** * Specify whether to delete the File after transformation. * Default is false. @@ -58,7 +63,17 @@ public void setDeleteFiles(boolean deleteFiles) { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; + } + + protected MessageBuilderFactory getMessageBuilderFactory() { + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -66,11 +81,11 @@ public final Message transform(Message message) { try { Assert.notNull(message, "Message must not be null"); Object payload = message.getPayload(); - Assert.notNull(payload, "Mesasge payload must not be null"); + Assert.notNull(payload, "Message payload must not be null"); Assert.isInstanceOf(File.class, payload, "Message payload must be of type [java.io.File]"); File file = (File) payload; T result = this.transformFile(file); - Message transformedMessage = this.messageBuilderFactory.withPayload(result) + Message transformedMessage = getMessageBuilderFactory().withPayload(result) .copyHeaders(message.getHeaders()) .setHeaderIfAbsent(FileHeaders.ORIGINAL_FILE, file) .setHeaderIfAbsent(FileHeaders.FILENAME, file.getName()) diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java index a6a51ff0227..d52468fd05e 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java @@ -17,6 +17,7 @@ package org.springframework.integration.file.config; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import org.junit.Test; @@ -57,7 +58,7 @@ public void checkDeleteFilesValue() { handlerAccessor.getPropertyValue("transformer"); DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer); assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles")); - assertSame(this.messageBuilderFactory, transformerAccessor.getPropertyValue("messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, transformerAccessor.getPropertyValue("messageBuilderFactory")); } } diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java index 687a3971d04..ef66ab40c1a 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpMessageMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,9 @@ * to correlate which connection to send a reply. If applySequence is set, adds * standard correlationId/sequenceNumber headers allowing for downstream (unbounded) * resequencing. + * * * @author Gary Russell + * @author Artem Bilan * @since 2.0 * */ @@ -63,6 +65,10 @@ public class TcpMessageMapper implements private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + + private BeanFactory beanFactory; + /** * @param charset the charset to set */ @@ -88,11 +94,17 @@ public void setApplySequence(boolean applySequence) { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -100,7 +112,7 @@ public Message toMessage(TcpConnection connection) throws Exception { Message message = null; Object payload = connection.getPayload(); if (payload != null) { - AbstractIntegrationMessageBuilder messageBuilder = this.messageBuilderFactory.withPayload(payload); + AbstractIntegrationMessageBuilder messageBuilder = getMessageBuilderFactory().withPayload(payload); this.addStandardHeaders(connection, messageBuilder); this.addCustomHeaders(connection, messageBuilder); message = messageBuilder.build(); diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java index 4bfd2d1c061..9d5bc610cae 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/udp/DatagramPacketMessageMapper.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. @@ -59,6 +59,7 @@ * @author Mark Fisher * @author Gary Russell * @author Dave Syer + * @author Artem Bilan * @since 2.0 */ public class DatagramPacketMessageMapper implements InboundMessageMapper, OutboundMessageMapper, @@ -76,12 +77,16 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper toMessage(DatagramPacket packet) throws Exception { length = length - matcher.end(); payload = new byte[length]; System.arraycopy(packet.getData(), offset + matcher.end(), payload, 0, length); - message = this.messageBuilderFactory.withPayload(payload) + message = getMessageBuilderFactory().withPayload(payload) .setHeader(IpHeaders.ACK_ID, UUID.fromString(matcher.group(2))) .setHeader(IpHeaders.ACK_ADDRESS, matcher.group(1)) .setHeader(IpHeaders.HOSTNAME, hostName) @@ -230,7 +245,7 @@ public Message toMessage(DatagramPacket packet) throws Exception { payload = new byte[length]; System.arraycopy(packet.getData(), offset, payload, 0, length); if (payload.length > 0) { - message = this.messageBuilderFactory.withPayload(payload) + message = getMessageBuilderFactory().withPayload(payload) .setHeader(IpHeaders.HOSTNAME, hostName) .setHeader(IpHeaders.IP_ADDRESS, hostAddress) .setHeader(IpHeaders.PORT, port) diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index be563777805..f995f22cf99 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -299,7 +299,7 @@ public void testInUdp() { assertFalse((Boolean)mapperAccessor.getPropertyValue("lookupHost")); assertFalse(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class)); assertEquals(1234, dfa.getPropertyValue("phase")); - assertSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); } @Test @@ -318,14 +318,14 @@ public void testInUdpMulticast() { DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper"); DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper); assertTrue((Boolean)mapperAccessor.getPropertyValue("lookupHost")); - assertSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); } @Test public void testInTcp() { DirectFieldAccessor dfa = new DirectFieldAccessor(tcpIn); assertSame(cfS1, dfa.getPropertyValue("serverConnectionFactory")); - assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1, "mapper.messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1, "mapper.messageBuilderFactory")); assertEquals("testInTcp",tcpIn.getComponentName()); assertEquals("ip:tcp-inbound-channel-adapter", tcpIn.getComponentType()); assertEquals(errorChannel, dfa.getPropertyValue("errorChannel")); @@ -353,7 +353,7 @@ public void testInTcp() { public void testInTcpNioSSLDefaultConfig() { assertFalse(cfS1Nio.isLookupHost()); assertTrue((Boolean) TestUtils.getPropertyValue(cfS1Nio, "mapper.applySequence")); - assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1Nio, "mapper.messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1Nio, "mapper.messageBuilderFactory")); Object connectionSupport = TestUtils.getPropertyValue(cfS1Nio, "tcpNioConnectionSupport"); assertTrue(connectionSupport instanceof DefaultTcpNioSSLConnectionSupport); assertNotNull(TestUtils.getPropertyValue(connectionSupport, "sslContext")); @@ -381,7 +381,7 @@ public void testOutUdp() { assertEquals(23, dfa.getPropertyValue("order")); assertEquals("testOutUdp",udpOut.getComponentName()); assertEquals("ip:udp-outbound-channel-adapter", udpOut.getComponentType()); - assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); } @Test @@ -403,7 +403,7 @@ public void testOutUdpMulticast() { assertEquals(54, dfa.getPropertyValue("soTimeout")); assertEquals(55, dfa.getPropertyValue("timeToLive")); assertEquals(12, dfa.getPropertyValue("order")); - assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); } @Test diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionReadTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionReadTests.java index 848e180b0b4..6b7f10db7cc 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionReadTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionReadTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -166,9 +166,6 @@ public boolean onMessage(Message message) { done.countDown(); } - /** - * Test method for {@link org.springframework.integration.ip.tcp.NioSocketReader}. - */ @SuppressWarnings("unchecked") @Test public void testReadCrLf() throws Exception { diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java index 94810f81a7c..1147c0e60e0 100644 --- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java +++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/store/JdbcChannelMessageStore.java @@ -157,6 +157,8 @@ public class JdbcChannelMessageStore implements PriorityCapableChannelMessageSto private boolean priorityEnabled; + private BeanFactory beanFactory; + /** * Convenient constructor for configuration use. */ @@ -362,7 +364,7 @@ public boolean isPriorityEnabled() { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; } /** @@ -392,6 +394,9 @@ public void afterPropertiesSet() throws Exception { logger.warn("The jdbcTemplate's fetchsize is not 1. This may cause FIFO issues with Oracle databases."); } + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } this.jdbcTemplate.afterPropertiesSet(); } diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java index 04a7afbff80..cd581ca1e5d 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ package org.springframework.integration.jms.config; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import java.util.List; @@ -168,7 +170,8 @@ public void topicReferenceChannel() { AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) accessor.getPropertyValue("container"); assertEquals(topic, jmsTemplate.getDefaultDestination()); assertEquals(topic, container.getDestination()); - assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(channel, "dispatcher.messageBuilderFactory")); + assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(channel, "dispatcher" + + ".messageBuilderFactory")); assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory")); } diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java index 9dd110e55b4..ce8382f71c4 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/MailReceivingMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ * @author Mark Fisher * @author Gary Russell * @author Oleg Zhurakousky + * @author Artem Bilan */ public class MailReceivingMessageSource implements MessageSource, BeanFactoryAware, BeanNameAware, NamedComponent { @@ -58,6 +59,8 @@ public class MailReceivingMessageSource implements MessageSource receive() { if (logger.isDebugEnabled()) { logger.debug("received mail message [" + mailMessage + "]"); } - return this.messageBuilderFactory.withPayload(mailMessage).build(); + return getMessageBuilderFactory().withPayload(mailMessage).build(); } } catch (Exception e) { diff --git a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java index 4d4f41a5246..eded654b7f7 100644 --- a/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java +++ b/spring-integration-mail/src/main/java/org/springframework/integration/mail/transformer/AbstractMailMessageTransformer.java @@ -44,6 +44,7 @@ * * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ public abstract class AbstractMailMessageTransformer implements Transformer, BeanFactoryAware { @@ -54,15 +55,22 @@ public abstract class AbstractMailMessageTransformer implements Transformer, private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + @Override public final void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override diff --git a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java index fbc6954eb61..01c5f926e00 100644 --- a/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java +++ b/spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/AbstractConfigurableMongoDbMessageStore.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,6 @@ import java.util.Set; import java.util.UUID; -import com.mongodb.DB; -import com.mongodb.MongoException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -61,6 +59,9 @@ import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; +import com.mongodb.DB; +import com.mongodb.MongoException; + /** * The abstract MongoDB {@link BasicMessageGroupStore} implementation to provide configuration for common options * for implementations of this class. @@ -111,7 +112,8 @@ public AbstractConfigurableMongoDbMessageStore(MongoDbFactory mongoDbFactory, St this(mongoDbFactory, null, collectionName); } - public AbstractConfigurableMongoDbMessageStore(MongoDbFactory mongoDbFactory, MappingMongoConverter mappingMongoConverter, String collectionName) { + public AbstractConfigurableMongoDbMessageStore(MongoDbFactory mongoDbFactory, + MappingMongoConverter mappingMongoConverter, String collectionName) { Assert.notNull("'mongoDbFactory' must not be null"); Assert.hasText("'collectionName' must not be empty"); this.collectionName = collectionName; @@ -122,7 +124,6 @@ public AbstractConfigurableMongoDbMessageStore(MongoDbFactory mongoDbFactory, Ma @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.applicationContext); } @Override @@ -142,7 +143,9 @@ public void afterPropertiesSet() throws Exception { this.mongoTemplate.setApplicationContext(this.applicationContext); } } - + + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.applicationContext); + IndexOperations indexOperations = this.mongoTemplate.indexOps(this.collectionName); indexOperations.ensureIndex(new Index(MessageDocumentFields.MESSAGE_ID, Sort.Direction.ASC)); @@ -201,13 +204,16 @@ public Void doInDB(DB db) throws MongoException, DataAccessException { } } - final long createdDate = document.getCreatedTime() == 0 ? System.currentTimeMillis() : document.getCreatedTime(); + final long createdDate = document.getCreatedTime() == 0 + ? System.currentTimeMillis() + : document.getCreatedTime(); Message result = messageBuilderFactory.fromMessage(message).setHeader(SAVED_KEY, Boolean.TRUE) .setHeader(CREATED_DATE_KEY, createdDate).build(); @SuppressWarnings("unchecked") - Map innerMap = (Map) new DirectFieldAccessor(result.getHeaders()).getPropertyValue("headers"); + Map innerMap = (Map) new DirectFieldAccessor(result.getHeaders()) + .getPropertyValue("headers"); // using reflection to set ID since it is immutable through MessageHeaders innerMap.put(MessageHeaders.ID, message.getHeaders().get(MessageHeaders.ID)); innerMap.put(MessageHeaders.TIMESTAMP, message.getHeaders().get(MessageHeaders.TIMESTAMP)); diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java index 1b8a8216c8f..e6b56cd1e49 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/AbstractMqttMessageDrivenChannelAdapter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.mqtt.inbound; import java.util.LinkedHashSet; @@ -240,7 +241,10 @@ public void removeTopic(String... topic) { protected void onInit() { super.onInit(); if (this.converter == null) { - this.converter = new DefaultPahoMessageConverter(); + DefaultPahoMessageConverter pahoMessageConverter = new DefaultPahoMessageConverter(); + pahoMessageConverter.setBeanFactory(getBeanFactory()); + this.converter = pahoMessageConverter; + } } diff --git a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java index 73be05afec4..fbe95410e88 100644 --- a/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java +++ b/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/support/DefaultPahoMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.mqtt.support; import org.eclipse.paho.client.mqttv3.MqttMessage; @@ -33,6 +34,7 @@ * Default implementation for mapping to/from Messages. * * @author Gary Russell + * @author Artem Bilan * @since 4.0 * */ @@ -50,6 +52,8 @@ public class DefaultPahoMessageConverter implements MqttMessageConverter, BeanFa private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + /** * Construct a converter with default options (qos=0, retain=false, charset=UTF-8). @@ -60,7 +64,7 @@ public DefaultPahoMessageConverter() { /** * Construct a converter to create outbound messages with the supplied default qos and retain settings and - * a UTF-8 charset for converting outbound String paylaods to {@code byte[]} and inbound + * a UTF-8 charset for converting outbound String payloads to {@code byte[]} and inbound * {@code byte[]} to String (unless {@link #setPayloadAsBytes(boolean) payloadAdBytes} is true). * @param defaultQos the default qos. * @param defaultRetain the default retain. @@ -97,7 +101,6 @@ public DefaultPahoMessageConverter(int defaultQos, boolean defaultRetained, Stri @Override public final void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); } protected BeanFactory getBeanFactory() { @@ -105,7 +108,13 @@ protected BeanFactory getBeanFactory() { } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } /** @@ -130,7 +139,7 @@ public Message toMessage(Object mqttMessage, MessageHeaders headers) { @Override public Message toMessage(String topic, MqttMessage mqttMessage) { try { - AbstractIntegrationMessageBuilder messageBuilder = this.messageBuilderFactory + AbstractIntegrationMessageBuilder messageBuilder = getMessageBuilderFactory() .withPayload(mqttBytesToPayload(mqttMessage)) .setHeader(MqttHeaders.QOS, mqttMessage.getQos()) .setHeader(MqttHeaders.DUPLICATE, mqttMessage.isDuplicate()) diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java index 5fbfe8e4bb1..77de95912af 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,7 @@ public void testPubSubChannelConfig(){ redisChannel = context.getBean("redisChannelWithSubLimit", SubscribableChannel.class); assertEquals(1, TestUtils.getPropertyValue(redisChannel, "dispatcher.maxSubscribers", Integer.class).intValue()); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(redisChannel, "dispatcher.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(redisChannel, "dispatcher.messageBuilderFactory")); assertSame(mbf, TestUtils.getPropertyValue(redisChannel, "messageBuilderFactory")); context.close(); } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java index 9d5ce12f60f..86f644f8fbc 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; @@ -79,7 +80,7 @@ public void validateConfiguration() { assertNotNull(bean); assertNull(TestUtils.getPropertyValue(bean, "serializer")); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(bean, "messageConverter.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(bean, "messageConverter.messageBuilderFactory")); } @Test diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java index feb4f20fa4d..9d45f4cff6f 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,7 +78,7 @@ public void validateConfiguration() { assertEquals(converterBean, accessor.getPropertyValue("messageConverter")); assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer")); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertSame(mbf, TestUtils.getPropertyValue(handler, "messageConverter.messageBuilderFactory")); + assertNotSame(mbf, TestUtils.getPropertyValue(handler, "messageConverter.messageBuilderFactory")); Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler"); diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java index 2f6deb8fa24..54f64dc312d 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/DefaultMessageConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,12 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); + private volatile boolean messageBuilderFactorySet; + private volatile boolean asMap = true; + private BeanFactory beanFactory; + /** * Set false will leave the payload as the original complete syslog. * @param asMap boolean flag. @@ -65,11 +69,17 @@ protected boolean asMap() { @Override public final void setBeanFactory(BeanFactory beanFactory) { - this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(beanFactory); + this.beanFactory = beanFactory; } protected MessageBuilderFactory getMessageBuilderFactory() { - return messageBuilderFactory; + if (!this.messageBuilderFactorySet) { + if (this.beanFactory != null) { + this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); + } + this.messageBuilderFactorySet = true; + } + return this.messageBuilderFactory; } @Override @@ -82,7 +92,7 @@ public Message fromSyslog(Message message) throws Exception { out.put(SyslogHeaders.PREFIX + entry.getKey(), entry.getValue()); } } - return this.messageBuilderFactory.withPayload(this.asMap ? map : message.getPayload()) + return getMessageBuilderFactory().withPayload(this.asMap ? map : message.getPayload()) .copyHeaders(out) .build(); } diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/TcpSyslogReceivingChannelAdapter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/TcpSyslogReceivingChannelAdapter.java index 9ae37eba899..bb63ceb0642 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/TcpSyslogReceivingChannelAdapter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/TcpSyslogReceivingChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.syslog.inbound; @@ -28,6 +29,7 @@ * TCP implementation of a syslog inbound channel adapter. * * @author Gary Russell + * @author Artem Bilan * @since 3.0 * */ @@ -61,9 +63,11 @@ protected void onInit() { if (this.connectionFactory == null) { this.connectionFactory = new TcpNioServerConnectionFactory(this.getPort()); this.connectionFactory.setDeserializer(new ByteArrayLfSerializer()); + this.connectionFactory.setBeanFactory(getBeanFactory()); if (this.applicationEventPublisher != null) { this.connectionFactory.setApplicationEventPublisher(this.applicationEventPublisher); } + this.connectionFactory.afterPropertiesSet(); } this.connectionFactory.registerListener(this); } diff --git a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/UdpSyslogReceivingChannelAdapter.java b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/UdpSyslogReceivingChannelAdapter.java index 1d42b21aaf2..659f91a406d 100644 --- a/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/UdpSyslogReceivingChannelAdapter.java +++ b/spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/UdpSyslogReceivingChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.syslog.inbound; -import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.FixedSubscriberChannel; import org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; @@ -25,6 +26,7 @@ * UDP implementation of a syslog inbound channel adapter. * * @author Gary Russell + * @author Artem Bilan * @since 3.0 * */ @@ -32,8 +34,11 @@ public class UdpSyslogReceivingChannelAdapter extends SyslogReceivingChannelAdap private volatile UnicastReceivingChannelAdapter udpAdapter; + private volatile boolean udpAdapterSet; + public void setUdpAdapter(UnicastReceivingChannelAdapter udpAdpter) { this.udpAdapter = udpAdpter; + this.udpAdapterSet = true; } @Override @@ -43,18 +48,27 @@ public String getComponentType() { @Override protected void onInit() { + super.onInit(); if (this.udpAdapter == null) { this.udpAdapter = new UnicastReceivingChannelAdapter(this.getPort()); + this.udpAdapter.setBeanFactory(getBeanFactory()); + } + else { + logger.info("The 'UdpSyslogReceivingChannelAdapter' overrides an 'outputChannel' " + + "of the provided 'UnicastReceivingChannelAdapter' to support Syslog conversion " + + "for the incoming UDP packets"); } - DirectChannel outputChannel = new DirectChannel(); - outputChannel.subscribe(new MessageHandler() { + this.udpAdapter.setOutputChannel(new FixedSubscriberChannel(new MessageHandler() { @Override public void handleMessage(Message message) throws MessagingException { convertAndSend(message); } - }); - this.udpAdapter.setOutputChannel(outputChannel); + + })); + if (!this.udpAdapterSet) { + this.udpAdapter.afterPropertiesSet(); + } } @Override From 9da8e5fda13b98f88877b086a81c3516fc521763 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 2 Mar 2015 13:33:31 +0200 Subject: [PATCH 2/4] * Fix `AbstractExpressionEvaluator` * Add JavaDocs for the `IntegrationEvaluationContextAware` --- .../IntegrationEvaluationContextAware.java | 13 +++++++++++++ .../util/AbstractExpressionEvaluator.java | 7 +------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAware.java b/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAware.java index 8c7663fced8..df6e6934504 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAware.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/expression/IntegrationEvaluationContextAware.java @@ -19,8 +19,21 @@ import org.springframework.expression.EvaluationContext; /** + * Interface to be implemented by beans that wish to be aware of their + * owning integration {@link EvaluationContext}, which is the result of + * {@link org.springframework.integration.config.IntegrationEvaluationContextFactoryBean} + *

+ * The {@link #setIntegrationEvaluationContext} is invoked from + * the {@link IntegrationEvaluationContextAwareBeanPostProcessor#afterSingletonsInstantiated()}, + * not during standard {@code postProcessBefore(After)Initialization} to avoid any + * {@code BeanFactory} early access during integration {@link EvaluationContext} retrieval. + * Therefore, if it is necessary to use {@link EvaluationContext} in the {@code afterPropertiesSet()}, + * the {@code IntegrationContextUtils.getEvaluationContext(this.beanFactory)} should be used instead + * of this interface implementation. + * * @author Artem Bilan * @since 3.0 + * @see IntegrationEvaluationContextAwareBeanPostProcessor */ public interface IntegrationEvaluationContextAware { diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java b/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java index 0eed9e99957..86eea874f69 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/AbstractExpressionEvaluator.java @@ -56,8 +56,6 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory(); - private volatile boolean messageBuilderFactorySet; - /** * Specify a BeanFactory in order to enable resolution via @beanName in the expression. */ @@ -83,16 +81,13 @@ public void setConversionService(ConversionService conversionService) { } protected MessageBuilderFactory getMessageBuilderFactory() { - if (this.messageBuilderFactory == null) { - this.messageBuilderFactory = new DefaultMessageBuilderFactory(); - } return this.messageBuilderFactory; } @Override public void afterPropertiesSet() throws Exception { getEvaluationContext(); - if (this.messageBuilderFactory == null) { + if (this.beanFactory != null) { this.messageBuilderFactory = IntegrationUtils.getMessageBuilderFactory(this.beanFactory); } } From e0783f39e04c42332f6e17f270e28fe253336250 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 2 Mar 2015 17:55:32 +0200 Subject: [PATCH 3/4] Fix `MongoDbMessageStoreClaimCheckIntegrationTests` --- ...oDbMessageStoreClaimCheckIntegrationTests.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreClaimCheckIntegrationTests.java b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreClaimCheckIntegrationTests.java index 49858f6addf..69cd8819ed1 100644 --- a/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreClaimCheckIntegrationTests.java +++ b/spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/MongoDbMessageStoreClaimCheckIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,22 +16,25 @@ package org.springframework.integration.mongodb.store; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import java.io.Serializable; -import com.mongodb.MongoClient; import org.junit.Test; +import org.springframework.context.support.GenericApplicationContext; import org.springframework.data.mongodb.MongoDbFactory; import org.springframework.data.mongodb.core.SimpleMongoDbFactory; import org.springframework.integration.mongodb.rules.MongoDbAvailable; import org.springframework.integration.mongodb.rules.MongoDbAvailableTests; import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.test.util.TestUtils; import org.springframework.integration.transformer.ClaimCheckInTransformer; import org.springframework.integration.transformer.ClaimCheckOutTransformer; import org.springframework.messaging.Message; +import com.mongodb.MongoClient; + /** * @author Mark Fisher * @author Artem Bilan @@ -81,6 +84,9 @@ public void objectPayload() throws Exception { public void stringPayloadConfigurable() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test"); ConfigurableMongoDbMessageStore messageStore = new ConfigurableMongoDbMessageStore(mongoDbFactory); + GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext(); + testApplicationContext.refresh(); + messageStore.setApplicationContext(testApplicationContext); messageStore.afterPropertiesSet(); ClaimCheckInTransformer checkin = new ClaimCheckInTransformer(messageStore); ClaimCheckOutTransformer checkout = new ClaimCheckOutTransformer(messageStore); @@ -98,6 +104,9 @@ public void stringPayloadConfigurable() throws Exception { public void objectPayloadConfigurable() throws Exception { MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test"); ConfigurableMongoDbMessageStore messageStore = new ConfigurableMongoDbMessageStore(mongoDbFactory); + GenericApplicationContext testApplicationContext = TestUtils.createTestApplicationContext(); + testApplicationContext.refresh(); + messageStore.setApplicationContext(testApplicationContext); messageStore.afterPropertiesSet(); ClaimCheckInTransformer checkin = new ClaimCheckInTransformer(messageStore); ClaimCheckOutTransformer checkout = new ClaimCheckOutTransformer(messageStore); From 1d274fb66f1b64ff66e9ed9e6345863cf2babb6d Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 2 Mar 2015 22:27:53 +0200 Subject: [PATCH 4/4] Addressing PR comments --- .../integration/amqp/config/AmqpChannelParserTests.java | 2 -- .../AbstractAggregatingMessageGroupProcessor.java | 5 ++--- .../integration/aop/MessagePublishingInterceptor.java | 5 ++--- .../integration/config/AggregatorParserTests.java | 7 +------ .../integration/gateway/GatewayInterfaceTests.java | 3 --- .../file/config/FileToStringTransformerParserTests.java | 4 ---- .../integration/ip/config/ParserUnitTests.java | 9 --------- .../integration/jms/config/JmsChannelParserTests.java | 2 -- .../redis/config/RedisChannelParserTests.java | 1 - .../config/RedisInboundChannelAdapterParserTests.java | 2 -- .../config/RedisOutboundChannelAdapterParserTests.java | 2 -- 11 files changed, 5 insertions(+), 37 deletions(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java index 503fac8b13b..152e2d5f3df 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/config/AmqpChannelParserTests.java @@ -18,7 +18,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; @@ -58,7 +57,6 @@ public void interceptor() { TestUtils.getPropertyValue(channel, "dispatcher"), "maxSubscribers", Integer.class).intValue()); channel = context.getBean("pubSub", MessageChannel.class); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(channel, "dispatcher.messageBuilderFactory")); assertSame(mbf, TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory")); assertTrue(TestUtils.getPropertyValue(channel, "container.missingQueuesFatal", Boolean.class)); assertFalse(TestUtils.getPropertyValue(channel, "container.transactional", Boolean.class)); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java index 52068949e8e..2316e634f2d 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aggregator/AbstractAggregatingMessageGroupProcessor.java @@ -79,12 +79,11 @@ public final Object processMessageGroup(MessageGroup group) { Map headers = this.aggregateHeaders(group); Object payload = this.aggregatePayloads(group, headers); AbstractIntegrationMessageBuilder builder; - MessageBuilderFactory messageBuilderFactory = getMessageBuilderFactory(); if (payload instanceof Message) { - builder = messageBuilderFactory.fromMessage((Message) payload).copyHeadersIfAbsent(headers); + builder = getMessageBuilderFactory().fromMessage((Message) payload).copyHeadersIfAbsent(headers); } else { - builder = messageBuilderFactory.withPayload(payload).copyHeadersIfAbsent(headers); + builder = getMessageBuilderFactory().withPayload(payload).copyHeadersIfAbsent(headers); } return builder.popSequenceDetails().build(); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java index 54af9efb62f..71c29464199 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MessagePublishingInterceptor.java @@ -173,10 +173,9 @@ private void publishMessage(Method method, StandardEvaluationContext context) th Expression expression = this.parser.parseExpression(payloadExpressionString); Object result = expression.getValue(context); if (result != null) { - MessageBuilderFactory messageBuilderFactory = getMessageBuilderFactory(); AbstractIntegrationMessageBuilder builder = (result instanceof Message) - ? messageBuilderFactory.fromMessage((Message) result) - : messageBuilderFactory.withPayload(result); + ? getMessageBuilderFactory().fromMessage((Message) result) + : getMessageBuilderFactory().withPayload(result); Map headers = this.evaluateHeaders(method, context); if (headers != null) { builder.copyHeaders(headers); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java index bfeaac96653..7079b385ae6 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/config/AggregatorParserTests.java @@ -20,7 +20,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; @@ -95,7 +94,6 @@ public void testAggregation() { Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithReference.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); } @Test @@ -122,7 +120,6 @@ public void handleMessage(Message message) throws MessageRejectedException, M Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithExpressions.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); assertTrue(TestUtils.getPropertyValue(handler, "expireGroupsUponTimeout", Boolean.class)); } @@ -176,7 +173,6 @@ public void testSimpleJavaBeanAggregator() { Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); Object handler = context.getBean("aggregatorWithReferenceAndMethod.handler"); assertSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.messageBuilderFactory")); - assertNotSame(mbf, TestUtils.getPropertyValue(handler, "outputProcessor.processor.messageBuilderFactory")); } @Test(expected = BeanCreationException.class) @@ -249,8 +245,6 @@ public void testAggregationWithExpressionsAndPojoAggregator() { EventDrivenConsumer aggregatorConsumer = (EventDrivenConsumer) context.getBean("aggregatorWithExpressionsAndPojoAggregator"); AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) TestUtils.getPropertyValue(aggregatorConsumer, "handler"); MethodInvokingMessageGroupProcessor messageGroupProcessor = (MethodInvokingMessageGroupProcessor) TestUtils.getPropertyValue(aggregatingMessageHandler, "outputProcessor"); - Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(messageGroupProcessor, "messageBuilderFactory")); Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor.delegate.targetObject"); assertSame(context.getBean("aggregatorBean"), messageGroupProcessorTargetObject); ReleaseStrategy releaseStrategy = (ReleaseStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "releaseStrategy"); @@ -272,4 +266,5 @@ private static Message createMessage(T payload, Object correlationId, int return MessageBuilder.withPayload(payload).setCorrelationId(correlationId).setSequenceSize(sequenceSize) .setSequenceNumber(sequenceNumber).setReplyChannel(outputChannel).build(); } + } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java index 833cfe6364b..ac0a7534caf 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/gateway/GatewayInterfaceTests.java @@ -134,9 +134,6 @@ public void handleMessage(Message message) throws MessagingException { bar.foo("hello"); assertTrue(called.get()); Map gateways = TestUtils.getPropertyValue(ac.getBean("&sampleGateway"), "gatewayMap", Map.class); - Object mbf = ac.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(gateways.values().iterator().next(), - "messageConverter.messageBuilderFactory")); ac.close(); } diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java index d52468fd05e..c9dd30d6d4f 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileToStringTransformerParserTests.java @@ -45,9 +45,6 @@ public class FileToStringTransformerParserTests { @Qualifier("transformer") EventDrivenConsumer endpoint; - @Autowired - MessageBuilderFactory messageBuilderFactory; - @Test public void checkDeleteFilesValue() { DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint); @@ -58,7 +55,6 @@ public void checkDeleteFilesValue() { handlerAccessor.getPropertyValue("transformer"); DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer); assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles")); - assertNotSame(this.messageBuilderFactory, transformerAccessor.getPropertyValue("messageBuilderFactory")); } } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index f995f22cf99..cbba44c2c82 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -275,9 +275,6 @@ public class ParserUnitTests { @Autowired QueueChannel eventChannel; - @Autowired - MessageBuilderFactory messageBuilderFactory; - private static volatile int adviceCalled; @Test @@ -299,7 +296,6 @@ public void testInUdp() { assertFalse((Boolean)mapperAccessor.getPropertyValue("lookupHost")); assertFalse(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class)); assertEquals(1234, dfa.getPropertyValue("phase")); - assertNotSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); } @Test @@ -318,14 +314,12 @@ public void testInUdpMulticast() { DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper"); DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper); assertTrue((Boolean)mapperAccessor.getPropertyValue("lookupHost")); - assertNotSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory")); } @Test public void testInTcp() { DirectFieldAccessor dfa = new DirectFieldAccessor(tcpIn); assertSame(cfS1, dfa.getPropertyValue("serverConnectionFactory")); - assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1, "mapper.messageBuilderFactory")); assertEquals("testInTcp",tcpIn.getComponentName()); assertEquals("ip:tcp-inbound-channel-adapter", tcpIn.getComponentType()); assertEquals(errorChannel, dfa.getPropertyValue("errorChannel")); @@ -353,7 +347,6 @@ public void testInTcp() { public void testInTcpNioSSLDefaultConfig() { assertFalse(cfS1Nio.isLookupHost()); assertTrue((Boolean) TestUtils.getPropertyValue(cfS1Nio, "mapper.applySequence")); - assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(cfS1Nio, "mapper.messageBuilderFactory")); Object connectionSupport = TestUtils.getPropertyValue(cfS1Nio, "tcpNioConnectionSupport"); assertTrue(connectionSupport instanceof DefaultTcpNioSSLConnectionSupport); assertNotNull(TestUtils.getPropertyValue(connectionSupport, "sslContext")); @@ -381,7 +374,6 @@ public void testOutUdp() { assertEquals(23, dfa.getPropertyValue("order")); assertEquals("testOutUdp",udpOut.getComponentName()); assertEquals("ip:udp-outbound-channel-adapter", udpOut.getComponentType()); - assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); } @Test @@ -403,7 +395,6 @@ public void testOutUdpMulticast() { assertEquals(54, dfa.getPropertyValue("soTimeout")); assertEquals(55, dfa.getPropertyValue("timeToLive")); assertEquals(12, dfa.getPropertyValue("order")); - assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory")); } @Test diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java index cd581ca1e5d..c8b061ad2a0 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/config/JmsChannelParserTests.java @@ -170,8 +170,6 @@ public void topicReferenceChannel() { AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) accessor.getPropertyValue("container"); assertEquals(topic, jmsTemplate.getDefaultDestination()); assertEquals(topic, container.getDestination()); - assertNotSame(this.messageBuilderFactory, TestUtils.getPropertyValue(channel, "dispatcher" + - ".messageBuilderFactory")); assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(channel, "container.messageListener.messageBuilderFactory")); } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java index 77de95912af..3d89585108e 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisChannelParserTests.java @@ -62,7 +62,6 @@ public void testPubSubChannelConfig(){ redisChannel = context.getBean("redisChannelWithSubLimit", SubscribableChannel.class); assertEquals(1, TestUtils.getPropertyValue(redisChannel, "dispatcher.maxSubscribers", Integer.class).intValue()); Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(redisChannel, "dispatcher.messageBuilderFactory")); assertSame(mbf, TestUtils.getPropertyValue(redisChannel, "messageBuilderFactory")); context.close(); } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java index 86f644f8fbc..45312549090 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java @@ -79,8 +79,6 @@ public void validateConfiguration() { Object bean = context.getBean("withoutSerializer.adapter"); assertNotNull(bean); assertNull(TestUtils.getPropertyValue(bean, "serializer")); - Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(bean, "messageConverter.messageBuilderFactory")); } @Test diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java index 9d45f4cff6f..64769015cff 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisOutboundChannelAdapterParserTests.java @@ -77,8 +77,6 @@ public void validateConfiguration() { Object converterBean = context.getBean("testConverter"); assertEquals(converterBean, accessor.getPropertyValue("messageConverter")); assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer")); - Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME); - assertNotSame(mbf, TestUtils.getPropertyValue(handler, "messageConverter.messageBuilderFactory")); Object endpointHandler = TestUtils.getPropertyValue(adapter, "handler");