use of org.springframework.integration.syslog.DefaultMessageConverter 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();
}
Aggregations