Search in sources :

Example 1 with DefaultMessageConverter

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();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) InetSocketAddress(java.net.InetSocketAddress) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UnicastReceivingChannelAdapter(org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter) SyslogReceivingChannelAdapterFactoryBean(org.springframework.integration.syslog.config.SyslogReceivingChannelAdapterFactoryBean) DefaultMessageConverter(org.springframework.integration.syslog.DefaultMessageConverter) DatagramSocket(java.net.DatagramSocket) DatagramPacket(java.net.DatagramPacket) PollableChannel(org.springframework.messaging.PollableChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Aggregations

DatagramPacket (java.net.DatagramPacket)1 DatagramSocket (java.net.DatagramSocket)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 UnicastReceivingChannelAdapter (org.springframework.integration.ip.udp.UnicastReceivingChannelAdapter)1 DefaultMessageConverter (org.springframework.integration.syslog.DefaultMessageConverter)1 SyslogReceivingChannelAdapterFactoryBean (org.springframework.integration.syslog.config.SyslogReceivingChannelAdapterFactoryBean)1 PollableChannel (org.springframework.messaging.PollableChannel)1