For further reference, I got what I wanted with the following code using
netty (this evening I'll check how to do it with mina):

public static void main(String[] args) throws Exception {
    SimpleRegistry reg = new SimpleRegistry();
    ChannelHandlerFactory decoder =
        ChannelHandlerFactories.newStringDecoder(Charset.defaultCharset());
    reg.put("mydecoder", decoder);

    CamelContext context = new DefaultCamelContext(reg);
    context.addRoutes(new RouteBuilder() {
      public void configure() {
        
from("netty:tcp://0.0.0.0:5001/?decoder=#mydecoder&sync=false").process(new
Processor() {
          public void process(Exchange exchange) throws Exception {
            String text = exchange.getIn().getBody(String.class);
            System.out.println("Got the following bytes: {" + text + "}");
            exchange.getOut().setBody(text);  // not sure what this line
does and if it is required
          }
        });
        // .to("log:dump?showAll=true");
      }
    });

    context.start();
    System.out.println("Press ENTER to exit");
    System.in.read();
    System.out.println("exit");
    context.stop();
  }



2013/11/28 Cristiano Costantini <cristiano.costant...@gmail.com>

> Thank you Claus,
> then I'll check about mina2 on the book when I'll be back home this
> evening ;-)
>
> In the meanwhile I've also seen that there are some examples down in the
> section "Using Multiple Codecs" for the Camel Netty component (I skipped
> that section at first as I read only the "Usage Sample" section that say
> nothing about encoder/decoders)
>
> Cristiano
>
>
>
> 2013/11/28 Claus Ibsen <claus.ib...@gmail.com>
>
>> Camel in Action chapter 7, section 7.5.2 talks about how to write
>> custom codecs with mina and have example to go along.
>>
>> Also you can check the unit tests of these components as we may have a
>> custom codec unit test also.
>>
>> And then there is the documentation of these projects also you can
>> take a look at how to write custom codecs.
>>
>> And for Netty then the Netty in Action book have a full chapter on
>> writing custom codecs.
>> http://manning.com/maurer/
>>
>>
>>
>> On Thu, Nov 28, 2013 at 8:27 AM, Cristiano Costantini
>> <cristiano.costant...@gmail.com> wrote:
>> > Hi All,
>> > I'm trying to make a camel-mina2 TCP endpoint which should only dump
>> that
>> > bytes are received by the socket.
>> >
>> > With UDP this is easy as "For UDP if no codec is specified the default
>> uses
>> > a basic ByteBuffer based codec."
>> >
>> > On TCP I have some limitations, textline don't works as my consumer
>> don't
>> > sends endlines.
>> > Could you suggest me how to make or use a simple codec that allow me to
>> do
>> > this in TCP?
>> > It is enough for me to sysout the number of bytes of each TCP receive...
>> >
>> > I've seen that the custom codec need to be registered in SimpleRegistry,
>> > but I've found no examples with real codecs and I don't know what to
>> use.
>> > Do mina2 component already provides some codec I can use, or should I
>> write
>> > a codec by myself? Or should I use camel-netty?
>> >
>> > Thank you!
>> > Cristiano
>> >
>> > P.S. Sorry I'm a newbie of camel-mina2, it is the second time I use this
>> > component but with UDP was much easier, I just need some hints for
>> taking
>> > the right direction an then I'll figure out what to do by myself
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: cib...@redhat.com
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>

Reply via email to