Using Camel netty4 "unsupported message type" exception when sending String over UDP

1.6k Views Asked by At

Here is part of my camel route

<bean class="io.netty.handler.codec.string.StringEncoder" id="stringEncoder">
    <constructor-arg value="UTF-8"/>
</bean>

<camelContext xmlns="http://camel.apache.org/schema/spring" id="camelContext">

    <route>
        <from uri="direct:startMessageSend"/>
        <to uri="netty4:udp://localhost:5000?encoder=#stringEncoder&amp;sync=false"/>
    </route>
</camelContext>

When I send a simple string over to this endpoint.

            String udpMsgBody = "hello world!";
            template.sendBody(udpMsgBody);

I get following exception.

Caused by: java.lang.UnsupportedOperationException: unsupported message type: DefaultAddressedEnvelope (expected: DatagramPacket, AddressedEnvelope<ByteBuf, SocketAddress>, ByteBuf)
at io.netty.channel.socket.nio.NioDatagramChannel.filterOutboundMessage(NioDatagramChannel.java:324)
at io.netty.channel.AbstractChannel$AbstractUnsafe.write(AbstractChannel.java:697)
at io.netty.channel.DefaultChannelPipeline$HeadContext.write(DefaultChannelPipeline.java:1114)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:705)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:763)
at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:698)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:102)
at io.netty.channel.AbstractChannelHandlerContext.invokeWrite(AbstractChannelHandlerContext.java:705)
at io.netty.channel.AbstractChannelHandlerContext.access$1900(AbstractChannelHandlerContext.java:32)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.write(AbstractChannelHandlerContext.java:980)
at io.netty.channel.AbstractChannelHandlerContext$WriteAndFlushTask.write(AbstractChannelHandlerContext.java:1032)
at io.netty.channel.AbstractChannelHandlerContext$AbstractWriteTask.run(AbstractChannelHandlerContext.java:965)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
at java.lang.Thread.run(Thread.java:744)

However when I send the Exchange body as byteBuf I get no exception and message is sent over UDP fine.

            ByteBuf bbuffer = Unpooled.copiedBuffer(udpMsgBody.getBytes());
            template.sendBody(udpMsgBody);

My question is that even though I am using a proper StringEncoder, why can I not send a string over netty4?

Note I am using camel 2.15.2

0

There are 0 best solutions below