use of org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter in project spring-integration by spring-projects.
the class UdpSyslogReceivingChannelAdapter method onInit.
@Override
protected void onInit() {
super.onInit();
if (this.udpAdapter == null) {
this.udpAdapter = new UnicastReceivingChannelAdapter(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");
}
this.udpAdapter.setOutputChannel(new FixedSubscriberChannel(message -> convertAndSend(message)));
if (!this.udpAdapterSet) {
this.udpAdapter.afterPropertiesSet();
}
}
use of org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter in project spring-integration by spring-projects.
the class SyslogReceivingChannelAdapterTests method testAsMapFalse.
@Test
public void testAsMapFalse() throws Exception {
SyslogReceivingChannelAdapterFactoryBean factory = new SyslogReceivingChannelAdapterFactoryBean(SyslogReceivingChannelAdapterFactoryBean.Protocol.udp);
factory.setPort(0);
PollableChannel outputChannel = new QueueChannel();
factory.setOutputChannel(outputChannel);
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
factory.start();
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "adapter.udpAdapter", UnicastReceivingChannelAdapter.class);
TestingUtilities.waitListening(server, null);
UdpSyslogReceivingChannelAdapter adapter = (UdpSyslogReceivingChannelAdapter) factory.getObject();
DefaultMessageConverter defaultMessageConverter = new DefaultMessageConverter();
defaultMessageConverter.setAsMap(false);
adapter.setConverter(defaultMessageConverter);
Thread.sleep(1000);
byte[] buf = "<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE".getBytes("UTF-8");
DatagramPacket packet = new DatagramPacket(buf, buf.length, new InetSocketAddress("localhost", adapter.getPort()));
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
Message<?> message = outputChannel.receive(10000);
assertNotNull(message);
assertEquals("WEBERN", message.getHeaders().get("syslog_HOST"));
assertEquals("<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE", new String((byte[]) message.getPayload(), "UTF-8"));
adapter.stop();
}
use of org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter in project spring-integration by spring-projects.
the class SyslogReceivingChannelAdapterTests method testUdp.
@Test
public void testUdp() throws Exception {
SyslogReceivingChannelAdapterFactoryBean factory = new SyslogReceivingChannelAdapterFactoryBean(SyslogReceivingChannelAdapterFactoryBean.Protocol.udp);
PollableChannel outputChannel = new QueueChannel();
factory.setPort(0);
factory.setOutputChannel(outputChannel);
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
factory.start();
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "adapter.udpAdapter", UnicastReceivingChannelAdapter.class);
TestingUtilities.waitListening(server, null);
UdpSyslogReceivingChannelAdapter adapter = (UdpSyslogReceivingChannelAdapter) factory.getObject();
byte[] buf = "<157>JUL 26 22:08:35 WEBERN TESTING[70729]: TEST SYSLOG MESSAGE".getBytes("UTF-8");
DatagramPacket packet = new DatagramPacket(buf, buf.length, new InetSocketAddress("localhost", server.getPort()));
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
Message<?> message = outputChannel.receive(10000);
assertNotNull(message);
assertEquals("WEBERN", message.getHeaders().get("syslog_HOST"));
adapter.stop();
}
use of org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter in project spring-integration by spring-projects.
the class SyslogReceivingChannelAdapterTests method testUdpRFC5424.
@Test
public void testUdpRFC5424() throws Exception {
SyslogReceivingChannelAdapterFactoryBean factory = new SyslogReceivingChannelAdapterFactoryBean(SyslogReceivingChannelAdapterFactoryBean.Protocol.udp);
factory.setPort(0);
PollableChannel outputChannel = new QueueChannel();
factory.setOutputChannel(outputChannel);
factory.setBeanFactory(mock(BeanFactory.class));
factory.setConverter(new RFC5424MessageConverter());
factory.afterPropertiesSet();
factory.start();
UnicastReceivingChannelAdapter server = TestUtils.getPropertyValue(factory, "adapter.udpAdapter", UnicastReceivingChannelAdapter.class);
TestingUtilities.waitListening(server, null);
UdpSyslogReceivingChannelAdapter adapter = (UdpSyslogReceivingChannelAdapter) factory.getObject();
Thread.sleep(1000);
byte[] buf = ("<14>1 2014-06-20T09:14:07+00:00 loggregator d0602076-b14a-4c55-852a-981e7afeed38 DEA - " + "[exampleSDID@32473 iut=\\\"3\\\" eventSource=\\\"Application\\\" eventID=\\\"1011\\\"]" + "[exampleSDID@32473 iut=\\\"3\\\" eventSource=\\\"Application\\\" eventID=\\\"1011\\\"] Removing instance").getBytes("UTF-8");
DatagramPacket packet = new DatagramPacket(buf, buf.length, new InetSocketAddress("localhost", adapter.getPort()));
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
@SuppressWarnings("unchecked") Message<Map<String, ?>> message = (Message<Map<String, ?>>) outputChannel.receive(10000);
assertNotNull(message);
assertEquals("loggregator", message.getPayload().get("syslog_HOST"));
adapter.stop();
}
Aggregations