I am getting messages over TCP in standard xml format, which I am listening to over my netty client. How should my pipeline be written so that I can parse strings starting and ending with <abc>....</abc> ?
I am guessing there should be a String decoder and another custom handler (netty defined or otherwise) that deals with the parsing of XML from the TCP stream.
Something like the following?
public Bootstrap createBootstrap(final Bootstrap b, EventLoopGroup eventLoop) {
b.group(workerGroup);
b.channel(NioSocketChannel.class);
ReconnectionClient reconnectionClient = new ReconnectionClient(this);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(reconnectionClient);
pipeline.addLast(new StringDecoder(CharsetUtil.UTF_8));
pipeline.addLast(new ClientHandler()); // deals with String parsing
}
});
// Use command line arguments to pass the socket
b.connect(serverIP, serverPort).addListener(new ConnectionListener(this));
return b;
}
The second part of my question is how do I parse individual XML strings that are transmitted over TCP? As in, what code should be written in ClientHandler() that implements this functionality?