Typecasting Problem Using Netty and Google Protobuf
"이희승 (Trustin Lee)"
trustin at gmail.com
Mon Jul 25 07:41:44 EDT 2011
Hi Akash,
Could you show us the bootstrap code (e.g. main()) of the receiving
part? I suspect that your pipeline does not have proper decoders.
HTH
Akash Gangil wrote:
> *
> Hi,
>
> Explaining the problem in nutshell when I typecast the message (received
> by the client) to the message type (of protocol buffer class) in the
> server I get this error WARNING: Unexpected exception from downstream.
> java.lang.ClassCastException:
> org.jboss.netty.buffer.BigEndianHeapChannelBuffer cannot be cast to
> org.jboss.netty.example.echo.MessageProtos$Packet
> **
> *
> Packet p = (Packet) e.getMessage() ,
> *
> **
> where Packet is the Message class generated via google Proc Buffers
> **
>
> *
> *
> *
> *SGClienthandler.java : *
> *
> *
>
> public void send(String message_type, String message_to_send, int
> message_id){
> Packet p = Packet.newBuilder()
> .setPacketId(message_id)
> .setPacketType(message_type)
> .setPacketContent(message_to_send).build();
> try {
> channel.write(p);
> System.out.print("Message was sent to this channel : "
> + channel);
> }
> catch (Exception e) {
> System.out.println(" In send() ");
> e.printStackTrace();
> }
> }
>
> *EchoServerhandler.java :*
>
> @Override
> public void messageReceived(
> ChannelHandlerContext ctx, MessageEvent e) {
> System.out.print("Message Received : " + e.getMessage());
> Packet req = (Packet) e.getMessage();
> System.out.print("Packet Id received : " + req.getPacketId());
> System.out.print("Packet Type received : " + req.getPacketType());
> System.out.print("Packet Content received : " +
> req.getPacketContent());
> }
>
>
>
> The Pipeline factory of both the client and server namely :
> *SGPipelineFactory and EchoServerPipelineFactory *have same
> encoding and decoding handlers apart from the specific handlers related
> to their logic.
>
> // Decoders
> pipeline.addLast("frameDecoder", new
> ProtobufVarint32FrameDecoder());
> pipeline.addLast("protobufDecoder", new
> ProtobufDecoder(Packet.getDefaultInstance()));
>
> // Encoder
> pipeline.addLast("frameEncoder", new
> ProtobufVarint32LengthFieldPrepender());
> pipeline.addLast("protobufEncoder", new ProtobufEncoder());
>
>
>
>
> *Error :*
>
> WARNING: Unexpected exception from downstream.
> java.lang.ClassCastException:
> org.jboss.netty.buffer.BigEndianHeapChannelBuffer cannot be cast to
> org.jboss.netty.example.echo.MessageProtos$Packet
> at
> org.jboss.netty.example.echo.EchoServerHandler.messageReceived(EchoServerHandler.java:63)
>
> The line 63 is in red.
>
>
> Would be great if I can get some pointers.
>
> --
> Akash
>
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/netty-users
--
Trustin Lee, http://gleamynode.net/
More information about the netty-users
mailing list