I am using Netty 3.9. I have a simple client server setup which I got from http://en.wikipedia.org/wiki/Netty_%28software%29#Netty_TCP_Example. I have expanded the example to send a Java search plan object from the client to the server
The search plan object is a 3rd party object which has methods for serializing and deserializing. Serialization writes the object into a byte[] array. My client pipeline factory looks like this:
this.bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(
new StringDecoder(CharsetUtil.UTF_8),
new StringEncoder(CharsetUtil.UTF_8),
new DelimiterBasedFrameDecoder(
ALLOWED_CHARACTER_BUFFER_SIZE, Delimiters
.lineDelimiter()),
/* We also add our Clients own ChannelHandler. */
new ClientChannelHandler());
}
});
I think StringDecoder and StringEncoder are incorrect. I think I need some sort of ByteEncoder/Decoder which I do not see. Do I need to write these? I tried this code to convert to a String on the Client
byte[] byteVersion = searchPlanRepo.serialize(missionNum); // serialize the search plan
searchPlanStr = new String(byteVersion, StandardCharsets.UTF_8);
but on the server no matter what I do to "deserialize" the object I fail. I continuously get the error message:
"java.lang.ClassCastException: java.lang.String cannot be cast to payload.mission.SearchPlanType"
My questions:
- Do I need a custom byte encoder/decoder? Are there any examples?
- Serialization seems simple: byte array to String but deserialization from a String to a byte array does not work. I am sure I am missing something. Can anyone point me in the correct direction?
Thanks for taking the time to read this. :)
Phil