INT-3661: Fix the eager BF access from BPPs (P I)
JIRA: https://jira.spring.io/browse/INT-3661 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 * Move all code 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 remove `messageBuilderFactory` tests since there is no activity for target components to lazy-load them * 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 * Fix `AbstractExpressionEvaluator` * Add JavaDocs for the `IntegrationEvaluationContextAware` Fix `MongoDbMessageStoreClaimCheckIntegrationTests` Addressing PR comments
This commit is contained in:
committed by
Gary Russell
parent
134c7c870b
commit
2bde14b742
@@ -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 @@ public class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
|
||||
|
||||
@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 class DefaultMessageConverter implements MessageConverter, BeanFactoryAwa
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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 @@ import org.springframework.messaging.Message;
|
||||
* TCP implementation of a syslog inbound channel adapter.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@@ -61,9 +63,11 @@ public class TcpSyslogReceivingChannelAdapter extends SyslogReceivingChannelAdap
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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 @@ import org.springframework.messaging.MessagingException;
|
||||
* 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 class UdpSyslogReceivingChannelAdapter extends SyslogReceivingChannelAdap
|
||||
|
||||
@Override
|
||||
protected void onInit() {
|
||||
super.onInit();
|
||||
if (this.udpAdapter == null) {
|
||||
this.udpAdapter = new UnicastReceivingChannelAdapter(this.getPort());
|
||||
this.udpAdapter.setBeanFactory(getBeanFactory());
|
||||
}
|
||||
DirectChannel outputChannel = new DirectChannel();
|
||||
outputChannel.subscribe(new MessageHandler() {
|
||||
else {
|
||||
logger.info("The 'UdpSyslogReceivingChannelAdapter' overrides an 'outputChannel' " +
|
||||
"of the provided 'UnicastReceivingChannelAdapter' to support Syslog conversion " +
|
||||
"for the incoming UDP packets");
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user