Skip to content

Commit c0937d2

Browse files
committed
Fix Syslog module for changes in IP module
* Remove `SyslogdTests.java` which are not tests.
1 parent 1184c4b commit c0937d2

File tree

8 files changed

+44
-160
lines changed

8 files changed

+44
-160
lines changed

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SyslogdTests-context.xml

Lines changed: 0 additions & 39 deletions
This file was deleted.

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/SyslogdTests.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/SyslogdTests-context.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.

spring-integration-ip/src/test/java/org/springframework/integration/ip/udp/SyslogdTests.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

spring-integration-syslog/src/main/java/org/springframework/integration/syslog/config/SyslogReceivingChannelAdapterFactoryBean.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.jspecify.annotations.Nullable;
2020

21+
import org.springframework.beans.factory.BeanFactory;
2122
import org.springframework.beans.factory.BeanNameAware;
2223
import org.springframework.beans.factory.config.AbstractFactoryBean;
2324
import org.springframework.context.ApplicationEventPublisher;
@@ -184,28 +185,38 @@ public Class<?> getObjectType() {
184185
@Override
185186
protected SyslogReceivingChannelAdapterSupport createInstance() {
186187
SyslogReceivingChannelAdapterSupport adapter;
188+
UnicastReceivingChannelAdapter udpAdapterToUse = this.udpAdapter;
189+
BeanFactory beanFactory = getBeanFactory();
190+
ApplicationEventPublisher applicationEventPublisherToUse = this.applicationEventPublisher;
187191
if (this.protocol == Protocol.tcp) {
188192
adapter = new TcpSyslogReceivingChannelAdapter();
189193
if (this.connectionFactory != null) {
190194
Assert.isNull(this.port, "Cannot specify both 'port' and 'connectionFactory'");
191195
((TcpSyslogReceivingChannelAdapter) adapter).setConnectionFactory(this.connectionFactory);
192196
}
193-
else if (this.applicationEventPublisher != null) {
197+
else if (applicationEventPublisherToUse != null) {
194198
((TcpSyslogReceivingChannelAdapter) adapter)
195-
.setApplicationEventPublisher(this.applicationEventPublisher);
199+
.setApplicationEventPublisher(applicationEventPublisherToUse);
196200
}
197-
Assert.isNull(this.udpAdapter, "Cannot specify 'udp-attributes' when the protocol is 'tcp'");
201+
Assert.isNull(udpAdapterToUse, "Cannot specify 'udp-attributes' when the protocol is 'tcp'");
198202
}
199203
else if (this.protocol == Protocol.udp) {
200204
adapter = new UdpSyslogReceivingChannelAdapter();
201-
if (this.udpAdapter != null) {
205+
if (udpAdapterToUse != null) {
202206
Assert.isNull(this.port, "Cannot specify both 'port' and 'udpAdapter'");
203-
((UdpSyslogReceivingChannelAdapter) adapter).setUdpAdapter(this.udpAdapter);
207+
if (beanFactory != null) {
208+
udpAdapterToUse.setBeanFactory(beanFactory);
209+
}
210+
if (applicationEventPublisherToUse != null) {
211+
udpAdapterToUse.setApplicationEventPublisher(applicationEventPublisherToUse);
212+
}
213+
udpAdapterToUse.afterPropertiesSet();
214+
((UdpSyslogReceivingChannelAdapter) adapter).setUdpAdapter(udpAdapterToUse);
204215
}
205216
Assert.isNull(this.connectionFactory, "Cannot specify 'connection-factory' unless the protocol is 'tcp'");
206217
}
207218
else {
208-
throw new IllegalStateException("Unsupported protocol: " + this.protocol.toString());
219+
throw new IllegalStateException("Unsupported protocol: " + this.protocol);
209220
}
210221

211222
adapter.setAutoStartup(this.autoStartup);
@@ -218,7 +229,8 @@ else if (this.protocol == Protocol.udp) {
218229
.acceptIfNotNull(this.sendTimeout, adapter::setSendTimeout)
219230
.acceptIfNotNull(this.converter, adapter::setConverter)
220231
.acceptIfNotNull(this.beanName, adapter::setBeanName)
221-
.acceptIfNotNull(getBeanFactory(), adapter::setBeanFactory);
232+
.acceptIfNotNull(beanFactory, adapter::setBeanFactory)
233+
.acceptIfNotNull(applicationEventPublisherToUse, adapter::setApplicationEventPublisher);
222234

223235
adapter.afterPropertiesSet();
224236
this.syslogAdapter = adapter;

spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterSupport.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.syslog.inbound;
1818

19+
import org.springframework.context.ApplicationEventPublisher;
20+
import org.springframework.context.ApplicationEventPublisherAware;
1921
import org.springframework.integration.endpoint.MessageProducerSupport;
2022
import org.springframework.integration.syslog.DefaultMessageConverter;
2123
import org.springframework.integration.syslog.MessageConverter;
@@ -28,19 +30,34 @@
2830
*
2931
* @author Gary Russell
3032
* @author Ngoc Nhan
33+
* @author Artem Bilan
34+
*
3135
* @since 3.0
3236
*
3337
*/
34-
public abstract class SyslogReceivingChannelAdapterSupport extends MessageProducerSupport {
38+
public abstract class SyslogReceivingChannelAdapterSupport extends MessageProducerSupport
39+
implements ApplicationEventPublisherAware {
3540

3641
protected static final int DEFAULT_PORT = 514;
3742

43+
@SuppressWarnings("NullAway.Init")
44+
private ApplicationEventPublisher applicationEventPublisher;
45+
3846
private volatile int port = DEFAULT_PORT;
3947

4048
private MessageConverter converter = new DefaultMessageConverter();
4149

4250
private boolean converterSet;
4351

52+
@Override
53+
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
54+
this.applicationEventPublisher = applicationEventPublisher;
55+
}
56+
57+
protected ApplicationEventPublisher getApplicationEventPublisher() {
58+
return this.applicationEventPublisher;
59+
}
60+
4461
/**
4562
* @return The port on which this adapter listens.
4663
*/

spring-integration-syslog/src/main/java/org/springframework/integration/syslog/inbound/UdpSyslogReceivingChannelAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ protected void onInit() {
6161
if (this.udpAdapter == null) {
6262
this.udpAdapter = new UnicastReceivingChannelAdapter(getPort());
6363
this.udpAdapter.setBeanFactory(getBeanFactory());
64+
this.udpAdapter.setApplicationEventPublisher(getApplicationEventPublisher());
6465
}
6566
else {
6667
logger.info("The 'UdpSyslogReceivingChannelAdapter' overrides an 'outputChannel' " +

spring-integration-syslog/src/test/java/org/springframework/integration/syslog/inbound/SyslogReceivingChannelAdapterTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void testUdp() throws Exception {
7777
factory.setPort(0);
7878
factory.setOutputChannel(outputChannel);
7979
factory.setBeanFactory(mock());
80+
factory.setApplicationEventPublisher(mock());
8081
factory.afterPropertiesSet();
8182
factory.start();
8283
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "syslogAdapter.udpAdapter",
@@ -150,6 +151,7 @@ public void testAsMapFalse() throws Exception {
150151
PollableChannel outputChannel = new QueueChannel();
151152
factory.setOutputChannel(outputChannel);
152153
factory.setBeanFactory(mock());
154+
factory.setApplicationEventPublisher(mock());
153155
factory.afterPropertiesSet();
154156
factory.start();
155157
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "syslogAdapter.udpAdapter",
@@ -191,10 +193,12 @@ public void testTcpRFC5424() throws Exception {
191193
return null;
192194
}).when(publisher).publishEvent(any(ApplicationEvent.class));
193195
factory.setBeanFactory(getBeanFactory());
196+
factory.setApplicationEventPublisher(publisher);
194197
AbstractServerConnectionFactory connectionFactory = new TcpNioServerConnectionFactory(0);
195198
connectionFactory.setBeanFactory(getBeanFactory());
196199
connectionFactory.setDeserializer(new RFC6587SyslogDeserializer());
197200
connectionFactory.setApplicationEventPublisher(publisher);
201+
connectionFactory.afterPropertiesSet();
198202
factory.setConnectionFactory(connectionFactory);
199203
factory.setConverter(new RFC5424MessageConverter());
200204
factory.afterPropertiesSet();
@@ -239,11 +243,12 @@ public void testUdpRFC5424() throws Exception {
239243
PollableChannel outputChannel = new QueueChannel();
240244
factory.setOutputChannel(outputChannel);
241245
factory.setConverter(new RFC5424MessageConverter());
246+
factory.setBeanFactory(mock());
247+
factory.setApplicationEventPublisher(mock());
242248
factory.afterPropertiesSet();
243249
factory.start();
244250
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "syslogAdapter.udpAdapter",
245251
UnicastReceivingChannelAdapter.class);
246-
server.setBeanFactory(mock());
247252
TestingUtilities.waitListening(server, null);
248253
UdpSyslogReceivingChannelAdapter adapter = (UdpSyslogReceivingChannelAdapter) factory.getObject();
249254
byte[] buf = ("<14>1 2014-06-20T09:14:07+00:00 loggregator d0602076-b14a-4c55-852a-981e7afeed38 DEA - " +

0 commit comments

Comments
 (0)