Typecasting Problem Using Netty and Google Protobuf
Akash Gangil
akashg1611 at gmail.com
Mon Jul 25 07:11:51 EDT 2011
*
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20110725/04b2023c/attachment.html
More information about the netty-users
mailing list