Here I provide a sample test case to reproduce the surprising behavior.

public class Mina2UdpTest extends CamelTestSupport {
    private static volatile int port;
    private static volatile String longMessage = "A very long UTF-8
string with length more than 2048 bytes";

    @BeforeClass
    public static void chooseFreePort() throws Exception {
        port = AvailablePortFinder.getNextAvailable();
    }

    protected int getPort() {
        return port;
    }


    protected RouteBuilder createRouteBuilder() {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {

from(String.format("mina2:udp://localhost:%1$s?sync=false&textline=false&allowDefaultCodec=false",getPort()))
                    .to("mock:result");
            }
        };
    }

    @Test
    public void testDefaultMina2UdpBehavior() throws Exception{
        
template().sendBody(String.format("mina2:udp://localhost:%1$s?sync=false&textline=false&allowDefaultCodec=false",
getPort()), longMessage);
        MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
        mockEndpoint.setExpectedMessageCount(1);
        mockEndpoint.assertIsSatisfied();

        //Equality test
        Exchange e = mockEndpoint.getReceivedExchanges().get(0);
        Object o = e.getIn().getBody();
        String result = context().getTypeConverter().convertTo(String.class,o);
        assertEquals(longMessage,result);
    }
}

Debug message snippet from the log:
...
2012-11-23 10:18:54,874 [main           ] DEBUG Mina2Producer
        - Writing body: A very long UTF-8 string with length more than
2048 bytes
...
2012-11-23 10:18:54,906 [agramAcceptor-1] DEBUG Mina2Consumer
        - Received body: A very long UTF-8 string with.. (truncated to
2048 bytes)

As another note, even though allowDefaultCodec property is set to
false, it is noticeable that the default codec
Mina2UdpProtocolCodecFactory is still called.

I'll be glad hearing comments and feedback from others regarding this finding.

Regards,
Mike

Reply via email to