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.
|
||||
@@ -44,7 +44,9 @@ import org.springframework.messaging.MessageHandlingException;
|
||||
* 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 class TcpMessageMapper implements
|
||||
|
||||
@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 class TcpMessageMapper implements
|
||||
Message<Object> message = null;
|
||||
Object payload = connection.getPayload();
|
||||
if (payload != null) {
|
||||
AbstractIntegrationMessageBuilder<Object> messageBuilder = this.messageBuilderFactory.withPayload(payload);
|
||||
AbstractIntegrationMessageBuilder<Object> messageBuilder = getMessageBuilderFactory().withPayload(payload);
|
||||
this.addStandardHeaders(connection, messageBuilder);
|
||||
this.addCustomHeaders(connection, messageBuilder);
|
||||
message = messageBuilder.build();
|
||||
|
||||
@@ -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 @@ import org.springframework.util.Assert;
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
* @since 2.0
|
||||
*/
|
||||
public class DatagramPacketMessageMapper implements InboundMessageMapper<DatagramPacket>, OutboundMessageMapper<DatagramPacket>,
|
||||
@@ -76,12 +77,16 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
|
||||
|
||||
private volatile MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
|
||||
|
||||
private volatile boolean messageBuilderFactorySet;
|
||||
|
||||
private static Pattern udpHeadersPattern =
|
||||
Pattern.compile(RegexUtils.escapeRegexSpecials(IpHeaders.ACK_ADDRESS) +
|
||||
"=" + "([^;]*);" +
|
||||
RegexUtils.escapeRegexSpecials(MessageHeaders.ID) +
|
||||
"=" + "([^;]*);");
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
public void setCharset(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
@@ -107,7 +112,17 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -213,7 +228,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
|
||||
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 class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
|
||||
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)
|
||||
|
||||
@@ -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.
|
||||
@@ -275,9 +275,6 @@ public class ParserUnitTests {
|
||||
@Autowired
|
||||
QueueChannel eventChannel;
|
||||
|
||||
@Autowired
|
||||
MessageBuilderFactory messageBuilderFactory;
|
||||
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
@Test
|
||||
@@ -299,7 +296,6 @@ public class ParserUnitTests {
|
||||
assertFalse((Boolean)mapperAccessor.getPropertyValue("lookupHost"));
|
||||
assertFalse(TestUtils.getPropertyValue(udpIn, "autoStartup", Boolean.class));
|
||||
assertEquals(1234, dfa.getPropertyValue("phase"));
|
||||
assertSame(this.messageBuilderFactory, mapperAccessor.getPropertyValue("messageBuilderFactory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -318,14 +314,12 @@ public class ParserUnitTests {
|
||||
DatagramPacketMessageMapper mapper = (DatagramPacketMessageMapper) dfa.getPropertyValue("mapper");
|
||||
DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(mapper);
|
||||
assertTrue((Boolean)mapperAccessor.getPropertyValue("lookupHost"));
|
||||
assertSame(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"));
|
||||
assertEquals("testInTcp",tcpIn.getComponentName());
|
||||
assertEquals("ip:tcp-inbound-channel-adapter", tcpIn.getComponentType());
|
||||
assertEquals(errorChannel, dfa.getPropertyValue("errorChannel"));
|
||||
@@ -353,7 +347,6 @@ public class ParserUnitTests {
|
||||
public void testInTcpNioSSLDefaultConfig() {
|
||||
assertFalse(cfS1Nio.isLookupHost());
|
||||
assertTrue((Boolean) TestUtils.getPropertyValue(cfS1Nio, "mapper.applySequence"));
|
||||
assertSame(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 class ParserUnitTests {
|
||||
assertEquals(23, dfa.getPropertyValue("order"));
|
||||
assertEquals("testOutUdp",udpOut.getComponentName());
|
||||
assertEquals("ip:udp-outbound-channel-adapter", udpOut.getComponentType());
|
||||
assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -403,7 +395,6 @@ public class ParserUnitTests {
|
||||
assertEquals(54, dfa.getPropertyValue("soTimeout"));
|
||||
assertEquals(55, dfa.getPropertyValue("timeToLive"));
|
||||
assertEquals(12, dfa.getPropertyValue("order"));
|
||||
assertSame(this.messageBuilderFactory, TestUtils.getPropertyValue(mapper, "messageBuilderFactory"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -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 class TcpNioConnectionReadTests {
|
||||
done.countDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.integration.ip.tcp.NioSocketReader}.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testReadCrLf() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user